@windrun-huaiin/backend-core 28.0.1 → 29.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 (132) hide show
  1. package/dist/app/api/stripe/checkout/route.js +0 -1
  2. package/dist/app/api/stripe/checkout/route.mjs +0 -1
  3. package/dist/app/api/stripe/customer-portal/route.js +0 -1
  4. package/dist/app/api/stripe/customer-portal/route.mjs +0 -1
  5. package/dist/app/api/webhook/clerk/user/route.js +0 -1
  6. package/dist/app/api/webhook/clerk/user/route.mjs +0 -1
  7. package/dist/auth/auth-utils.js +0 -1
  8. package/dist/auth/auth-utils.mjs +0 -1
  9. package/dist/index.js +0 -3
  10. package/dist/index.mjs +0 -3
  11. package/dist/lib/credit-overview.js +0 -1
  12. package/dist/lib/credit-overview.mjs +0 -1
  13. package/dist/lib/stripe-config.js +0 -1
  14. package/dist/lib/stripe-config.mjs +0 -1
  15. package/dist/prisma/index.d.ts +2 -2
  16. package/dist/prisma/index.d.ts.map +1 -1
  17. package/dist/prisma/index.js +0 -3
  18. package/dist/prisma/index.mjs +0 -3
  19. package/dist/prisma/prisma-transaction-util.d.ts +1 -1
  20. package/dist/prisma/prisma-transaction-util.d.ts.map +1 -1
  21. package/dist/prisma/prisma.d.ts +6 -6
  22. package/dist/prisma/prisma.d.ts.map +1 -1
  23. package/dist/prisma/prisma.js +4 -37
  24. package/dist/prisma/prisma.mjs +4 -37
  25. package/dist/services/aggregate/anonymous.aggregate.service.d.ts +2 -3
  26. package/dist/services/aggregate/anonymous.aggregate.service.d.ts.map +1 -1
  27. package/dist/services/aggregate/anonymous.aggregate.service.js +2 -8
  28. package/dist/services/aggregate/anonymous.aggregate.service.mjs +2 -8
  29. package/dist/services/aggregate/billing.aggregate.service.js +0 -1
  30. package/dist/services/aggregate/billing.aggregate.service.mjs +0 -1
  31. package/dist/services/aggregate/user.aggregate.service.d.ts +3 -3
  32. package/dist/services/aggregate/user.aggregate.service.d.ts.map +1 -1
  33. package/dist/services/aggregate/user.aggregate.service.js +0 -1
  34. package/dist/services/aggregate/user.aggregate.service.mjs +0 -1
  35. package/dist/services/context/user-context-service.js +0 -1
  36. package/dist/services/context/user-context-service.mjs +0 -1
  37. package/dist/services/database/apilog.service.js +0 -1
  38. package/dist/services/database/apilog.service.mjs +0 -1
  39. package/dist/services/database/core-entities.d.ts +123 -0
  40. package/dist/services/database/core-entities.d.ts.map +1 -0
  41. package/dist/services/database/credit.service.d.ts +1 -1
  42. package/dist/services/database/credit.service.d.ts.map +1 -1
  43. package/dist/services/database/credit.service.js +3 -8
  44. package/dist/services/database/credit.service.mjs +3 -8
  45. package/dist/services/database/creditAuditLog.service.d.ts +1 -1
  46. package/dist/services/database/creditAuditLog.service.d.ts.map +1 -1
  47. package/dist/services/database/creditAuditLog.service.js +6 -6
  48. package/dist/services/database/creditAuditLog.service.mjs +6 -6
  49. package/dist/services/database/prisma-model-type.d.ts +28 -2
  50. package/dist/services/database/prisma-model-type.d.ts.map +1 -1
  51. package/dist/services/database/subscription.service.js +1 -2
  52. package/dist/services/database/subscription.service.mjs +1 -2
  53. package/dist/services/database/transaction.service.d.ts +1 -1
  54. package/dist/services/database/transaction.service.d.ts.map +1 -1
  55. package/dist/services/database/transaction.service.js +14 -19
  56. package/dist/services/database/transaction.service.mjs +14 -19
  57. package/dist/services/database/user.service.d.ts +13 -4
  58. package/dist/services/database/user.service.d.ts.map +1 -1
  59. package/dist/services/database/user.service.js +5 -3
  60. package/dist/services/database/user.service.mjs +5 -3
  61. package/dist/services/database/userBackup.service.js +0 -1
  62. package/dist/services/database/userBackup.service.mjs +0 -1
  63. package/dist/services/stripe/webhook-handler.js +0 -1
  64. package/dist/services/stripe/webhook-handler.mjs +0 -1
  65. package/package.json +9 -16
  66. package/src/app/api/user/anonymous/init/route.ts +2 -2
  67. package/src/prisma/index.ts +6 -2
  68. package/src/prisma/prisma-transaction-util.ts +1 -1
  69. package/src/prisma/prisma.ts +14 -47
  70. package/src/services/aggregate/anonymous.aggregate.service.ts +7 -9
  71. package/src/services/aggregate/user.aggregate.service.ts +3 -3
  72. package/src/services/database/core-entities.ts +128 -0
  73. package/src/services/database/credit.service.ts +7 -8
  74. package/src/services/database/creditAuditLog.service.ts +11 -9
  75. package/src/services/database/prisma-model-type.ts +33 -4
  76. package/src/services/database/subscription.service.ts +2 -2
  77. package/src/services/database/transaction.service.ts +22 -23
  78. package/src/services/database/user.service.ts +23 -6
  79. package/dist/core-prisma/browser.d.ts +0 -40
  80. package/dist/core-prisma/browser.d.ts.map +0 -1
  81. package/dist/core-prisma/client.d.ts +0 -57
  82. package/dist/core-prisma/client.d.ts.map +0 -1
  83. package/dist/core-prisma/client.js +0 -55
  84. package/dist/core-prisma/client.mjs +0 -33
  85. package/dist/core-prisma/commonInputTypes.d.ts +0 -495
  86. package/dist/core-prisma/commonInputTypes.d.ts.map +0 -1
  87. package/dist/core-prisma/enums.d.ts +0 -2
  88. package/dist/core-prisma/enums.d.ts.map +0 -1
  89. package/dist/core-prisma/internal/class.d.ts +0 -193
  90. package/dist/core-prisma/internal/class.d.ts.map +0 -1
  91. package/dist/core-prisma/internal/class.js +0 -108
  92. package/dist/core-prisma/internal/class.mjs +0 -87
  93. package/dist/core-prisma/internal/prismaNamespace.d.ts +0 -1180
  94. package/dist/core-prisma/internal/prismaNamespace.d.ts.map +0 -1
  95. package/dist/core-prisma/internal/prismaNamespace.js +0 -278
  96. package/dist/core-prisma/internal/prismaNamespace.mjs +0 -226
  97. package/dist/core-prisma/internal/prismaNamespaceBrowser.d.ts +0 -233
  98. package/dist/core-prisma/internal/prismaNamespaceBrowser.d.ts.map +0 -1
  99. package/dist/core-prisma/models/Apilog.d.ts +0 -1088
  100. package/dist/core-prisma/models/Apilog.d.ts.map +0 -1
  101. package/dist/core-prisma/models/Credit.d.ts +0 -1554
  102. package/dist/core-prisma/models/Credit.d.ts.map +0 -1
  103. package/dist/core-prisma/models/CreditAuditLog.d.ts +0 -1362
  104. package/dist/core-prisma/models/CreditAuditLog.d.ts.map +0 -1
  105. package/dist/core-prisma/models/Subscription.d.ts +0 -1441
  106. package/dist/core-prisma/models/Subscription.d.ts.map +0 -1
  107. package/dist/core-prisma/models/Transaction.d.ts +0 -2222
  108. package/dist/core-prisma/models/Transaction.d.ts.map +0 -1
  109. package/dist/core-prisma/models/User.d.ts +0 -1775
  110. package/dist/core-prisma/models/User.d.ts.map +0 -1
  111. package/dist/core-prisma/models/UserBackup.d.ts +0 -1228
  112. package/dist/core-prisma/models/UserBackup.d.ts.map +0 -1
  113. package/dist/core-prisma/models.d.ts +0 -9
  114. package/dist/core-prisma/models.d.ts.map +0 -1
  115. package/migrations/create.sql +0 -176
  116. package/migrations/init-schema.sql +0 -20
  117. package/prisma/schema.prisma +0 -193
  118. package/src/core-prisma/browser.ts +0 -54
  119. package/src/core-prisma/client.ts +0 -78
  120. package/src/core-prisma/commonInputTypes.ts +0 -565
  121. package/src/core-prisma/enums.ts +0 -15
  122. package/src/core-prisma/internal/class.ts +0 -293
  123. package/src/core-prisma/internal/prismaNamespace.ts +0 -1419
  124. package/src/core-prisma/internal/prismaNamespaceBrowser.ts +0 -259
  125. package/src/core-prisma/models/Apilog.ts +0 -1244
  126. package/src/core-prisma/models/Credit.ts +0 -1722
  127. package/src/core-prisma/models/CreditAuditLog.ts +0 -1536
  128. package/src/core-prisma/models/Subscription.ts +0 -1610
  129. package/src/core-prisma/models/Transaction.ts +0 -2398
  130. package/src/core-prisma/models/User.ts +0 -1982
  131. package/src/core-prisma/models/UserBackup.ts +0 -1384
  132. package/src/core-prisma/models.ts +0 -18
@@ -1,9 +1,11 @@
1
1
  import { __awaiter } from 'tslib';
2
2
  import { UserStatus } from './constants.mjs';
3
3
  import { checkAndFallbackWithNonTCClient } from '../../prisma/prisma.mjs';
4
- import '../../core-prisma/client.mjs';
5
4
 
6
5
  /* eslint-disable @typescript-eslint/no-explicit-any */
6
+ function toPrismaJsonValue(value) {
7
+ return value === undefined ? undefined : value;
8
+ }
7
9
  class UserService {
8
10
  // Create user
9
11
  createUser(data, tx) {
@@ -12,7 +14,7 @@ class UserService {
12
14
  return yield client.user.create({
13
15
  data: {
14
16
  fingerprintId: data.fingerprintId,
15
- sourceRef: data.sourceRef,
17
+ sourceRef: toPrismaJsonValue(data.sourceRef),
16
18
  clerkUserId: data.clerkUserId,
17
19
  stripeCusId: data.stripeCusId,
18
20
  email: data.email,
@@ -76,7 +78,7 @@ class UserService {
76
78
  const client = checkAndFallbackWithNonTCClient(tx);
77
79
  return yield client.user.update({
78
80
  where: { userId },
79
- data,
81
+ data: Object.assign(Object.assign({}, data), { sourceRef: toPrismaJsonValue(data.sourceRef) }),
80
82
  });
81
83
  });
82
84
  }
@@ -2,7 +2,6 @@
2
2
 
3
3
  var tslib = require('tslib');
4
4
  var prisma = require('../../prisma/prisma.js');
5
- require('../../core-prisma/client.js');
6
5
 
7
6
  /* eslint-disable @typescript-eslint/no-explicit-any */
8
7
  class UserBackupService {
@@ -1,6 +1,5 @@
1
1
  import { __awaiter } from 'tslib';
2
2
  import { checkAndFallbackWithNonTCClient } from '../../prisma/prisma.mjs';
3
- import '../../core-prisma/client.mjs';
4
3
 
5
4
  /* eslint-disable @typescript-eslint/no-explicit-any */
6
5
  class UserBackupService {
@@ -4,7 +4,6 @@ var tslib = require('tslib');
4
4
  var billing_aggregate_service = require('../aggregate/billing.aggregate.service.js');
5
5
  var constants = require('../database/constants.js');
6
6
  require('../../prisma/prisma.js');
7
- require('../../core-prisma/client.js');
8
7
  var subscription_service = require('../database/subscription.service.js');
9
8
  require('../database/credit.service.js');
10
9
  var transaction_service = require('../database/transaction.service.js');
@@ -2,7 +2,6 @@ import { __awaiter } from 'tslib';
2
2
  import { billingAggregateService } from '../aggregate/billing.aggregate.service.mjs';
3
3
  import { OrderStatus, TransactionType, PaymentStatus, BillingReason } from '../database/constants.mjs';
4
4
  import '../../prisma/prisma.mjs';
5
- import '../../core-prisma/client.mjs';
6
5
  import { subscriptionService } from '../database/subscription.service.mjs';
7
6
  import '../database/credit.service.mjs';
8
7
  import { transactionService } from '../database/transaction.service.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windrun-huaiin/backend-core",
3
- "version": "28.0.1",
3
+ "version": "29.0.1",
4
4
  "description": "Shared backend primitives: Prisma schema/client, database services, routing helpers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -134,28 +134,23 @@
134
134
  "!dist/node_modules",
135
135
  "!dist/node_modules/**",
136
136
  "src",
137
- "prisma",
138
- "migrations",
139
137
  "package.json",
140
138
  "README.md",
141
139
  "LICENSE"
142
140
  ],
143
141
  "dependencies": {
144
142
  "@clerk/nextjs": "^7.0.5",
145
- "@prisma/adapter-pg": "^6.19.0",
146
- "@prisma/client": "^6.19.0",
147
143
  "@upstash/redis": "^1.34.0",
148
144
  "@upstash/qstash": "^2.7.0",
149
145
  "@upstash/lock": "^0.2.1",
150
146
  "next": "16.1.6",
151
- "prisma": "^6.19.0",
152
147
  "stripe": "22.0.2",
153
148
  "svix": "^1.86.0",
154
149
  "tslib": "^2.8.1",
155
150
  "zod": "^4.3.6",
156
- "@windrun-huaiin/contracts": "^28.0.0",
157
- "@windrun-huaiin/third-ui": "^28.0.0",
158
- "@windrun-huaiin/lib": "^28.0.0"
151
+ "@windrun-huaiin/contracts": "^29.0.0",
152
+ "@windrun-huaiin/lib": "^29.0.0",
153
+ "@windrun-huaiin/third-ui": "^29.0.2"
159
154
  },
160
155
  "devDependencies": {
161
156
  "@rollup/plugin-alias": "^5.1.1",
@@ -169,9 +164,8 @@
169
164
  "peerDependencies": {
170
165
  "@windrun-huaiin/contracts": ">=22.0.0",
171
166
  "@clerk/nextjs": "^7.0.5",
172
- "@prisma/client": "^6.19.0",
167
+ "@prisma/client": "^7.8.0",
173
168
  "next": "16.1.6",
174
- "prisma": "^6.19.0",
175
169
  "stripe": "22.0.2",
176
170
  "svix": "^1.86.0"
177
171
  },
@@ -179,11 +173,10 @@
179
173
  "access": "public"
180
174
  },
181
175
  "scripts": {
182
- "prisma:generate": "rm -rf src/core-prisma && prisma generate --schema prisma/schema.prisma",
183
- "build": "pnpm prisma:generate && rm -rf dist && rollup -c rollup.config.mjs",
184
- "build:prod": "pnpm prisma:generate && rm -rf dist && rollup -c rollup.config.mjs",
185
- "dev": "pnpm prisma:generate && rollup -c rollup.config.mjs --watch",
176
+ "build": "rm -rf dist && rollup -c rollup.config.mjs",
177
+ "build:prod": "rm -rf dist && rollup -c rollup.config.mjs",
178
+ "dev": "rollup -c rollup.config.mjs --watch",
186
179
  "clean": "rm -rf dist",
187
- "type-check": "pnpm prisma:generate && tsc --noEmit"
180
+ "type-check": "tsc --noEmit"
188
181
  }
189
182
  }
@@ -20,7 +20,7 @@ import {
20
20
  } from '@core/context/user-context-service';
21
21
  import { finalizeUserContext } from '@core/context/user-context-finalizer';
22
22
 
23
- import type { Prisma } from '@core/db/prisma-model-type';
23
+ import type { CoreJsonObject } from '@core/db/prisma-model-type';
24
24
 
25
25
 
26
26
  // ==================== 类型定义 ====================
@@ -70,7 +70,7 @@ function createErrorResponse(message: string, status = 400): NextResponse {
70
70
  return NextResponse.json(errorResponse, { status });
71
71
  }
72
72
 
73
- type SourceRefData = Prisma.InputJsonObject & {
73
+ type SourceRefData = CoreJsonObject & {
74
74
  capturedAt?: string;
75
75
  landingUrl?: string;
76
76
  landingPath?: string;
@@ -15,5 +15,9 @@ export type {
15
15
  Transaction,
16
16
  Apilog,
17
17
  UserBackup,
18
- } from '../core-prisma/client';
19
- export { Prisma } from '../core-prisma/client';
18
+ CoreJsonArray,
19
+ CoreJsonObject,
20
+ CoreJsonPrimitive,
21
+ CoreJsonValue,
22
+ } from '../services/database/core-entities';
23
+ export type { Prisma } from '../services/database/prisma-model-type';
@@ -1,5 +1,5 @@
1
1
  import { getBackendCorePrisma } from './prisma';
2
- import { Prisma } from '../core-prisma/client';
2
+ import type { Prisma } from '@core/db/prisma-model-type';
3
3
 
4
4
  // 事务工具类,回滚时打印回滚日志
5
5
  export async function runInTransaction<T>(
@@ -1,8 +1,6 @@
1
- import { PrismaPg } from '@prisma/adapter-pg';
2
- import { PrismaClient, Prisma } from '../core-prisma/client';
1
+ import type { Prisma } from '@core/db/prisma-model-type';
3
2
 
4
- type AppPrismaClient = PrismaClient<'query' | 'info' | 'warn' | 'error'>;
5
- export type BackendCorePrismaClient = AppPrismaClient;
3
+ export type BackendCorePrismaClient = BackendCoreHostPrismaClient;
6
4
  export type BackendCoreHostPrismaClient = {
7
5
  // Deliberately loose: host applications generate their own Prisma Client,
8
6
  // so transaction overloads are structurally compatible at runtime but not
@@ -14,8 +12,12 @@ export type BackendCoreHostPrismaClient = {
14
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
13
  $executeRaw: any;
16
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ $executeRawUnsafe?: any;
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
17
  $queryRaw: any;
18
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ $queryRawUnsafe?: any;
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
21
  user: any;
20
22
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
23
  subscription: any;
@@ -72,47 +74,10 @@ function createPrismaInstanceId(prefix = 'core-prisma') {
72
74
  return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`;
73
75
  }
74
76
 
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,
112
- log: logConfig,
113
- });
114
-
115
- return configureBackendCorePrisma(client, instanceId) as AppPrismaClient;
77
+ export function createPrismaClient(): never {
78
+ throw new Error(
79
+ 'backend-core no longer creates its own PrismaClient. The host application must create and register its Prisma client via configureBackendCorePrisma().',
80
+ );
116
81
  }
117
82
 
118
83
  export function configureBackendCorePrisma(
@@ -127,10 +92,12 @@ export function configureBackendCorePrisma(
127
92
 
128
93
  export function getBackendCorePrisma(): BackendCorePrismaClient {
129
94
  if (!globalForPrisma.prisma) {
130
- configureBackendCorePrisma(createPrismaClient());
95
+ throw new Error(
96
+ 'backend-core Prisma client is not configured. Register the host Prisma client via configureBackendCorePrisma() before using backend-core database services.',
97
+ );
131
98
  }
132
99
 
133
- return globalForPrisma.prisma as unknown as BackendCorePrismaClient;
100
+ return globalForPrisma.prisma as BackendCorePrismaClient;
134
101
  }
135
102
 
136
103
  // Backward-compatible lazy export. Accessing a property creates the client,
@@ -1,6 +1,6 @@
1
1
  import { creditService, subscriptionService, userService } from '@core/db';
2
2
  import { UserStatus } from '@core/db/constants';
3
- import type { Credit, Subscription, User } from '@core/db/prisma-model-type';
3
+ import type { CoreJsonValue, Credit, Subscription, User } from '@core/db/prisma-model-type';
4
4
  import { freeAmount } from '@core/lib/credit-init';
5
5
  import { runInTransaction } from '@core/prisma/prisma-transaction-util';
6
6
  import { CreditType, OperationType } from '@core/db/constants';
@@ -22,12 +22,10 @@ class AnonymousAggregateService {
22
22
  tx: Prisma.TransactionClient,
23
23
  fingerprintId: string,
24
24
  ): Promise<void> {
25
- await tx.$executeRaw`
26
- SELECT pg_advisory_xact_lock(
27
- ${Prisma.raw(String(ANONYMOUS_INIT_LOCK_NAMESPACE))},
28
- hashtext(${fingerprintId})
29
- )
30
- `;
25
+ await tx.$executeRawUnsafe?.(
26
+ `SELECT pg_advisory_xact_lock(${ANONYMOUS_INIT_LOCK_NAMESPACE}, hashtext($1))`,
27
+ fingerprintId,
28
+ );
31
29
  }
32
30
 
33
31
  private async findLatestUserContextByFingerprintId(
@@ -58,7 +56,7 @@ class AnonymousAggregateService {
58
56
  private async createAnonymousUser(
59
57
  fingerprintId: string,
60
58
  tx: Prisma.TransactionClient,
61
- options?: { sourceRef?: Prisma.InputJsonValue; },
59
+ options?: { sourceRef?: CoreJsonValue; },
62
60
  ): Promise<AnonymousInitContext> {
63
61
  const newUser = await userService.createUser(
64
62
  {
@@ -95,7 +93,7 @@ class AnonymousAggregateService {
95
93
 
96
94
  async getOrCreateByFingerprintId(
97
95
  fingerprintId: string,
98
- options?: { sourceRef?: Prisma.InputJsonValue; },
96
+ options?: { sourceRef?: CoreJsonValue; },
99
97
  ): Promise<AnonymousInitContext> {
100
98
  return runInTransaction(async (tx) => {
101
99
  await this.lockFingerprintInit(tx, fingerprintId);
@@ -1,6 +1,6 @@
1
1
  import { CreditType, OperationType, UserStatus } from '@core/db/constants';
2
2
  import { creditService, subscriptionService, userService } from '@core/db/index';
3
- import type { Credit, Prisma, User } from '@core/db/prisma-model-type';
3
+ import type { CoreJsonValue, Credit, Prisma, User } from '@core/db/prisma-model-type';
4
4
  import { freeAmount, freeRegisterAmount } from '@core/lib/credit-init';
5
5
  import { runInTransaction } from '@core/prisma/prisma-transaction-util';
6
6
 
@@ -9,7 +9,7 @@ export class UserAggregateService {
9
9
 
10
10
  async initAnonymousUser(
11
11
  fingerprintId: string,
12
- options?: { sourceRef?: Prisma.InputJsonValue; }
12
+ options?: { sourceRef?: CoreJsonValue; }
13
13
  ): Promise<{ newUser: User; credit: Credit; }> {
14
14
  return runInTransaction(async (tx) => {
15
15
  const newUser = await userService.createUser(
@@ -57,7 +57,7 @@ export class UserAggregateService {
57
57
  email?: string,
58
58
  fingerprintId?: string,
59
59
  userName?: string,
60
- sourceRef?: Prisma.InputJsonValue,
60
+ sourceRef?: CoreJsonValue,
61
61
  ): Promise<{ newUser: User; credit: Credit; }> {
62
62
  return runInTransaction(async (tx) => {
63
63
  const newUser = await userService.createUser(
@@ -0,0 +1,128 @@
1
+ export type CoreJsonPrimitive = string | number | boolean | null;
2
+ export type CoreJsonValue = CoreJsonPrimitive | CoreJsonObject | CoreJsonArray;
3
+ export interface CoreJsonObject {
4
+ [key: string]: CoreJsonValue | undefined;
5
+ }
6
+ export interface CoreJsonArray extends Array<CoreJsonValue> {}
7
+
8
+ export interface User {
9
+ id: bigint;
10
+ userId: string;
11
+ status: string;
12
+ fingerprintId: string | null;
13
+ clerkUserId: string | null;
14
+ stripeCusId: string | null;
15
+ email: string | null;
16
+ userName: string | null;
17
+ createdAt: Date | null;
18
+ updatedAt: Date | null;
19
+ sourceRef: CoreJsonValue | null;
20
+ }
21
+
22
+ export interface Subscription {
23
+ id: bigint;
24
+ userId: string;
25
+ status: string;
26
+ paySubscriptionId: string | null;
27
+ orderId: string | null;
28
+ priceId: string | null;
29
+ priceName: string | null;
30
+ creditsAllocated: number;
31
+ subPeriodStart: Date | null;
32
+ subPeriodEnd: Date | null;
33
+ createdAt: Date | null;
34
+ updatedAt: Date | null;
35
+ deleted: number;
36
+ }
37
+
38
+ export interface Credit {
39
+ id: bigint;
40
+ userId: string;
41
+ balanceFree: number;
42
+ totalFreeLimit: number;
43
+ freeStart: Date | null;
44
+ freeEnd: Date | null;
45
+ balancePaid: number;
46
+ totalPaidLimit: number;
47
+ paidStart: Date | null;
48
+ paidEnd: Date | null;
49
+ balanceOneTimePaid: number;
50
+ totalOneTimePaidLimit: number;
51
+ oneTimePaidStart: Date | null;
52
+ oneTimePaidEnd: Date | null;
53
+ createdAt: Date | null;
54
+ updatedAt: Date | null;
55
+ }
56
+
57
+ export interface Transaction {
58
+ id: bigint;
59
+ userId: string;
60
+ orderId: string;
61
+ orderStatus: string;
62
+ orderCreatedAt: Date | null;
63
+ orderExpiredAt: Date | null;
64
+ orderUpdatedAt: Date | null;
65
+ type: string | null;
66
+ paySupplier: string | null;
67
+ paySessionId: string | null;
68
+ payTransactionId: string | null;
69
+ paySubscriptionId: string | null;
70
+ subPeriodStart: Date | null;
71
+ subPeriodEnd: Date | null;
72
+ subLastTryCancelAt: Date | null;
73
+ subPeriodCanceledAt: Date | null;
74
+ subCancellationDetail: string | null;
75
+ priceId: string | null;
76
+ priceName: string | null;
77
+ amount: unknown;
78
+ currency: string | null;
79
+ creditsGranted: number | null;
80
+ payInvoiceId: string | null;
81
+ paymentStatus: string;
82
+ billingReason: string | null;
83
+ hostedInvoiceUrl: string | null;
84
+ invoicePdf: string | null;
85
+ orderDetail: string | null;
86
+ paidEmail: string | null;
87
+ paidAt: Date | null;
88
+ paidDetail: string | null;
89
+ payUpdatedAt: Date | null;
90
+ deleted: number;
91
+ }
92
+
93
+ export interface CreditAuditLog {
94
+ id: bigint;
95
+ userId: string;
96
+ creditsChange: number;
97
+ feature: string | null;
98
+ creditType: string;
99
+ operationType: string;
100
+ operationReferId: string | null;
101
+ createdAt: Date | null;
102
+ deleted: number;
103
+ }
104
+
105
+ export interface UserBackup {
106
+ id: bigint;
107
+ originalUserId: string;
108
+ status: string | null;
109
+ fingerprintId: string | null;
110
+ clerkUserId: string | null;
111
+ stripeCusId: string | null;
112
+ email: string | null;
113
+ userName: string | null;
114
+ backupData: CoreJsonValue | null;
115
+ deletedAt: Date | null;
116
+ createdAt: Date | null;
117
+ deleted: number;
118
+ }
119
+
120
+ export interface Apilog {
121
+ id: bigint;
122
+ apiType: string;
123
+ methodName: string;
124
+ summary: string | null;
125
+ request: string | null;
126
+ response: string | null;
127
+ createdAt: Date | null;
128
+ }
@@ -1,4 +1,4 @@
1
- import { Prisma } from '@core/db/prisma-model-type';
1
+ import type { Prisma } from '@core/db/prisma-model-type';
2
2
  import type { Credit, CreditAuditLog } from '@core/db/prisma-model-type';
3
3
  import { CreditType, OperationType } from '@core/db/constants';
4
4
  import { freeExpiredDays } from '@core/lib/credit-init';
@@ -679,13 +679,12 @@ export class CreditService {
679
679
  async getLowBalanceUsers(threshold: number = 10, tx?: Prisma.TransactionClient): Promise<Credit[]> {
680
680
  const client = checkAndFallbackWithNonTCClient(tx);
681
681
 
682
- const query = Prisma.sql`
683
- SELECT * FROM credits
684
- WHERE (balance_free + balance_paid + balance_onetime_paid) < ${threshold}
685
- ORDER BY (balance_free + balance_paid + balance_onetime_paid) ASC
686
- `;
687
-
688
- return await client.$queryRaw<Credit[]>(query);
682
+ return await client.$queryRawUnsafe(
683
+ `SELECT * FROM credits
684
+ WHERE (balance_free + balance_paid + balance_onetime_paid) < $1
685
+ ORDER BY (balance_free + balance_paid + balance_onetime_paid) ASC`,
686
+ threshold,
687
+ );
689
688
  }
690
689
 
691
690
  // Get Credit Statistics
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
 
3
- import { Prisma } from '@core/db/prisma-model-type';
3
+ import type { Prisma } from '@core/db/prisma-model-type';
4
4
  import type { CreditAuditLog } from '@core/db/prisma-model-type';
5
5
  import { CreditType, OperationType } from '@core/db/constants';
6
6
  import { checkAndFallbackWithNonTCClient } from '@core/prisma/index';
@@ -162,7 +162,7 @@ export class CreditAuditLogService {
162
162
  // Calculate creditAudit statistics by feature
163
163
  const featureMap = new Map<string, number>();
164
164
 
165
- allUsage.forEach((creditAudit) => {
165
+ allUsage.forEach((creditAudit: any) => {
166
166
  if (creditAudit.operationType === OperationType.CONSUME) {
167
167
  stats.totalConsumed += creditAudit.creditsChange;
168
168
  if (creditAudit.creditType === CreditType.FREE) {
@@ -230,7 +230,7 @@ export class CreditAuditLogService {
230
230
  take: limit,
231
231
  });
232
232
 
233
- return result.map((item) => ({
233
+ return result.map((item: any) => ({
234
234
  feature: item.feature,
235
235
  totalCredits: item._sum.creditsChange || 0,
236
236
  usageCount: item._count,
@@ -254,9 +254,7 @@ export class CreditAuditLogService {
254
254
  startDate.setDate(startDate.getDate() - days);
255
255
 
256
256
  const client = checkAndFallbackWithNonTCClient(tx);
257
- const userFilter = userId ? Prisma.sql`AND user_id = ${userId}` : Prisma.sql``;
258
-
259
- const result = await client.$queryRaw`
257
+ const query = `
260
258
  SELECT
261
259
  DATE(created_at) as date,
262
260
  SUM(CASE WHEN operation_type = 'consume' THEN credits_used ELSE 0 END) as consumed,
@@ -267,13 +265,17 @@ export class CreditAuditLogService {
267
265
  THEN credits_used ELSE 0 END) as paid_consumed,
268
266
  COUNT(DISTINCT user_id) as unique_users
269
267
  FROM credit_usage
270
- WHERE created_at >= ${startDate}
268
+ WHERE created_at >= $1
271
269
  AND deleted = 0
272
- ${userFilter}
270
+ ${userId ? 'AND user_id = $2' : ''}
273
271
  GROUP BY DATE(created_at)
274
272
  ORDER BY date DESC
275
273
  `;
276
274
 
275
+ const result = userId
276
+ ? await client.$queryRawUnsafe(query, startDate, userId)
277
+ : await client.$queryRawUnsafe(query, startDate);
278
+
277
279
  return result as {
278
280
  date: Date;
279
281
  consumed: number;
@@ -340,7 +342,7 @@ export class CreditAuditLogService {
340
342
  client.creditAuditLog.groupBy({
341
343
  by: ['userId'],
342
344
  where: { deleted: 0 },
343
- }).then((result) => result.length),
345
+ }).then((result: any[]) => result.length),
344
346
  client.creditAuditLog.count({ where: { deleted: 0 } }),
345
347
  client.creditAuditLog.aggregate({
346
348
  where: { operationType: OperationType.CONSUME, deleted: 0 },
@@ -1,4 +1,3 @@
1
- // Export Prisma Model Types
2
1
  export type {
3
2
  User,
4
3
  Subscription,
@@ -7,7 +6,37 @@ export type {
7
6
  Transaction,
8
7
  Apilog,
9
8
  UserBackup,
10
- } from '../../core-prisma/client';
9
+ CoreJsonArray,
10
+ CoreJsonObject,
11
+ CoreJsonPrimitive,
12
+ CoreJsonValue,
13
+ } from './core-entities';
11
14
 
12
- // Prisma既是类型也是值
13
- export { Prisma } from '../../core-prisma/client';
15
+ import type { BackendCoreHostPrismaClient } from '../../prisma/prisma';
16
+ import type { CoreJsonObject, CoreJsonValue } from './core-entities';
17
+
18
+ export namespace Prisma {
19
+ export type TransactionClient = BackendCoreHostPrismaClient;
20
+ export type QueryEvent = {
21
+ query: string;
22
+ params: string;
23
+ duration: number;
24
+ };
25
+ export type InputJsonValue = CoreJsonValue;
26
+ export type InputJsonObject = CoreJsonObject;
27
+ export type NullableJsonNullValueInput = null;
28
+ export type UserUpdateInput = Record<string, unknown>;
29
+ export type CreditUpdateInput = Record<string, unknown>;
30
+ export type SubscriptionUpdateInput = Record<string, unknown>;
31
+ export type TransactionUpdateInput = Record<string, unknown>;
32
+ export type CreditAuditLogUncheckedCreateInput = Record<string, unknown>;
33
+ export type CreditAuditLogCreateManyInput = Record<string, unknown>;
34
+ export type CreditAuditLogOrderByWithRelationInput = Record<string, unknown>;
35
+ export type CreditAuditLogWhereInput = Record<string, any>;
36
+ export type TransactionOrderByWithRelationInput = Record<string, unknown>;
37
+ export type TransactionWhereInput = Record<string, any>;
38
+ export type TransactionCreateManyInput = Record<string, unknown>;
39
+ export type UserWhereInput = Record<string, any>;
40
+ export type UserBackupOrderByWithRelationInput = Record<string, unknown>;
41
+ export type UserBackupWhereInput = Record<string, any>;
42
+ }
@@ -299,7 +299,7 @@ export class SubscriptionService {
299
299
  where: {
300
300
  paySubscriptionId: {
301
301
  in: activeSubscriptions
302
- .map(s => s.paySubscriptionId)
302
+ .map((s: any) => s.paySubscriptionId)
303
303
  .filter(Boolean) as string[],
304
304
  },
305
305
  orderStatus: 'success',
@@ -307,7 +307,7 @@ export class SubscriptionService {
307
307
  select: { amount: true },
308
308
  });
309
309
 
310
- revenue = transactions.reduce((sum, t) =>
310
+ revenue = transactions.reduce((sum: number, t: any) =>
311
311
  sum + (t.amount ? parseFloat(t.amount.toString()) : 0), 0
312
312
  );
313
313
  }