@windrun-huaiin/backend-core 30.0.0 → 31.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.
Files changed (51) hide show
  1. package/README.md +95 -0
  2. package/dist/app/api/user/anonymous/init/route.d.ts +1 -1
  3. package/dist/app/api/user/anonymous/init/route.d.ts.map +1 -1
  4. package/dist/app/api/user/anonymous/init/route.js +18 -19
  5. package/dist/app/api/user/anonymous/init/route.mjs +18 -19
  6. package/dist/app/api/webhook/clerk/user/route.js +16 -16
  7. package/dist/app/api/webhook/clerk/user/route.mjs +16 -16
  8. package/dist/auth/auth-utils.d.ts +8 -23
  9. package/dist/auth/auth-utils.d.ts.map +1 -1
  10. package/dist/auth/auth-utils.js +8 -20
  11. package/dist/auth/auth-utils.mjs +8 -20
  12. package/dist/lib/money-price-config.d.ts +28 -28
  13. package/dist/lib/money-price-config.js +31 -31
  14. package/dist/lib/money-price-config.mjs +31 -31
  15. package/dist/lib/stripe-config.js +3 -3
  16. package/dist/lib/stripe-config.mjs +3 -3
  17. package/dist/prisma/prisma-transaction-util.js +1 -1
  18. package/dist/prisma/prisma-transaction-util.mjs +1 -1
  19. package/dist/prisma/prisma.d.ts.map +1 -1
  20. package/dist/prisma/prisma.js +18 -19
  21. package/dist/prisma/prisma.mjs +18 -19
  22. package/dist/services/aggregate/billing.aggregate.service.js +6 -6
  23. package/dist/services/aggregate/billing.aggregate.service.mjs +6 -6
  24. package/dist/services/aggregate/user.aggregate.service.d.ts +9 -9
  25. package/dist/services/aggregate/user.aggregate.service.js +16 -16
  26. package/dist/services/aggregate/user.aggregate.service.mjs +16 -16
  27. package/dist/services/database/constants.js +34 -34
  28. package/dist/services/database/constants.mjs +34 -34
  29. package/dist/services/database/credit.service.js +2 -2
  30. package/dist/services/database/credit.service.mjs +2 -2
  31. package/dist/services/database/transaction.service.js +1 -1
  32. package/dist/services/database/transaction.service.mjs +1 -1
  33. package/dist/services/database/user.service.js +2 -2
  34. package/dist/services/database/user.service.mjs +2 -2
  35. package/dist/services/stripe/webhook-handler.js +5 -5
  36. package/dist/services/stripe/webhook-handler.mjs +5 -5
  37. package/package.json +13 -6
  38. package/src/app/api/user/anonymous/init/route.ts +21 -22
  39. package/src/app/api/webhook/clerk/user/route.ts +17 -17
  40. package/src/auth/auth-utils.ts +8 -23
  41. package/src/lib/money-price-config.ts +31 -32
  42. package/src/lib/stripe-config.ts +3 -3
  43. package/src/prisma/prisma-transaction-util.ts +1 -1
  44. package/src/prisma/prisma.ts +18 -19
  45. package/src/services/aggregate/billing.aggregate.service.ts +7 -7
  46. package/src/services/aggregate/user.aggregate.service.ts +16 -16
  47. package/src/services/database/constants.ts +34 -34
  48. package/src/services/database/credit.service.ts +2 -2
  49. package/src/services/database/transaction.service.ts +1 -1
  50. package/src/services/database/user.service.ts +2 -2
  51. package/src/services/stripe/webhook-handler.ts +5 -5
@@ -8,7 +8,7 @@ require('../services/database/credit.service.js');
8
8
  var authShared = require('./auth-shared.js');
9
9
 
10
10
  /**
11
- * 从中间件设置的 Clerk ID 获取完整用户信息
11
+ * Fetch User's info from header field by Middleware
12
12
  */
13
13
  function getAuthenticatedUser(req) {
14
14
  return tslib.__awaiter(this, void 0, void 0, function* () {
@@ -36,7 +36,7 @@ function getAuthenticatedUser(req) {
36
36
  });
37
37
  }
38
38
  /**
39
- * 要求用户必须已认证,返回用户ID
39
+ * Require Auth, success back user's id
40
40
  */
41
41
  function requireAuth(req) {
42
42
  return tslib.__awaiter(this, void 0, void 0, function* () {
@@ -45,7 +45,7 @@ function requireAuth(req) {
45
45
  });
46
46
  }
47
47
  /**
48
- * 要求用户必须已认证,返回完整用户信息
48
+ * Require Auth, success back user's info
49
49
  */
50
50
  function requireAuthWithUser(req) {
51
51
  return tslib.__awaiter(this, void 0, void 0, function* () {
@@ -53,8 +53,8 @@ function requireAuthWithUser(req) {
53
53
  });
54
54
  }
55
55
  /**
56
- * 服务端场景下获取当前已认证身份(如果存在)
57
- * 适用于只依赖登录态、不需要查询业务用户的逻辑
56
+ * Only use in server side
57
+ * Server Component / Server Action, just need user's login status
58
58
  */
59
59
  function getOptionalServerAuthIdentity() {
60
60
  return tslib.__awaiter(this, void 0, void 0, function* () {
@@ -75,8 +75,8 @@ function getOptionalServerAuthIdentity() {
75
75
  });
76
76
  }
77
77
  /**
78
- * 服务端场景下获取当前已认证用户(如果存在)
79
- * 适用于 Server Component / Server Action 中基于登录态控制展示的逻辑
78
+ * Only use in server side
79
+ * Server Component / Server Action, need user's login status and user's data, will check db
80
80
  */
81
81
  function getOptionalServerAuthUser() {
82
82
  return tslib.__awaiter(this, void 0, void 0, function* () {
@@ -103,31 +103,22 @@ function getOptionalServerAuthUser() {
103
103
  });
104
104
  }
105
105
  /**
106
- * API Route版本的认证工具函数
106
+ * API Route Auth Util
107
107
  */
108
108
  class ApiAuthUtils {
109
109
  constructor(req) {
110
110
  this.req = req;
111
111
  }
112
- /**
113
- * 要求用户必须已认证,返回用户ID
114
- */
115
112
  requireAuth() {
116
113
  return tslib.__awaiter(this, void 0, void 0, function* () {
117
114
  return yield requireAuth(this.req);
118
115
  });
119
116
  }
120
- /**
121
- * 要求用户必须已认证,返回完整用户信息
122
- */
123
117
  requireAuthWithUser() {
124
118
  return tslib.__awaiter(this, void 0, void 0, function* () {
125
119
  return yield requireAuthWithUser(this.req);
126
120
  });
127
121
  }
128
- /**
129
- * 获取用户ID(如果已认证)
130
- */
131
122
  getUserId() {
132
123
  return tslib.__awaiter(this, void 0, void 0, function* () {
133
124
  try {
@@ -139,9 +130,6 @@ class ApiAuthUtils {
139
130
  }
140
131
  });
141
132
  }
142
- /**
143
- * 获取完整用户信息(如果已认证)
144
- */
145
133
  getUser() {
146
134
  return tslib.__awaiter(this, void 0, void 0, function* () {
147
135
  try {
@@ -6,7 +6,7 @@ import '../services/database/credit.service.mjs';
6
6
  import { AUTH_HEADERS, AUTH_ERRORS } from './auth-shared.mjs';
7
7
 
8
8
  /**
9
- * 从中间件设置的 Clerk ID 获取完整用户信息
9
+ * Fetch User's info from header field by Middleware
10
10
  */
11
11
  function getAuthenticatedUser(req) {
12
12
  return __awaiter(this, void 0, void 0, function* () {
@@ -34,7 +34,7 @@ function getAuthenticatedUser(req) {
34
34
  });
35
35
  }
36
36
  /**
37
- * 要求用户必须已认证,返回用户ID
37
+ * Require Auth, success back user's id
38
38
  */
39
39
  function requireAuth(req) {
40
40
  return __awaiter(this, void 0, void 0, function* () {
@@ -43,7 +43,7 @@ function requireAuth(req) {
43
43
  });
44
44
  }
45
45
  /**
46
- * 要求用户必须已认证,返回完整用户信息
46
+ * Require Auth, success back user's info
47
47
  */
48
48
  function requireAuthWithUser(req) {
49
49
  return __awaiter(this, void 0, void 0, function* () {
@@ -51,8 +51,8 @@ function requireAuthWithUser(req) {
51
51
  });
52
52
  }
53
53
  /**
54
- * 服务端场景下获取当前已认证身份(如果存在)
55
- * 适用于只依赖登录态、不需要查询业务用户的逻辑
54
+ * Only use in server side
55
+ * Server Component / Server Action, just need user's login status
56
56
  */
57
57
  function getOptionalServerAuthIdentity() {
58
58
  return __awaiter(this, void 0, void 0, function* () {
@@ -73,8 +73,8 @@ function getOptionalServerAuthIdentity() {
73
73
  });
74
74
  }
75
75
  /**
76
- * 服务端场景下获取当前已认证用户(如果存在)
77
- * 适用于 Server Component / Server Action 中基于登录态控制展示的逻辑
76
+ * Only use in server side
77
+ * Server Component / Server Action, need user's login status and user's data, will check db
78
78
  */
79
79
  function getOptionalServerAuthUser() {
80
80
  return __awaiter(this, void 0, void 0, function* () {
@@ -101,31 +101,22 @@ function getOptionalServerAuthUser() {
101
101
  });
102
102
  }
103
103
  /**
104
- * API Route版本的认证工具函数
104
+ * API Route Auth Util
105
105
  */
106
106
  class ApiAuthUtils {
107
107
  constructor(req) {
108
108
  this.req = req;
109
109
  }
110
- /**
111
- * 要求用户必须已认证,返回用户ID
112
- */
113
110
  requireAuth() {
114
111
  return __awaiter(this, void 0, void 0, function* () {
115
112
  return yield requireAuth(this.req);
116
113
  });
117
114
  }
118
- /**
119
- * 要求用户必须已认证,返回完整用户信息
120
- */
121
115
  requireAuthWithUser() {
122
116
  return __awaiter(this, void 0, void 0, function* () {
123
117
  return yield requireAuthWithUser(this.req);
124
118
  });
125
119
  }
126
- /**
127
- * 获取用户ID(如果已认证)
128
- */
129
120
  getUserId() {
130
121
  return __awaiter(this, void 0, void 0, function* () {
131
122
  try {
@@ -137,9 +128,6 @@ class ApiAuthUtils {
137
128
  }
138
129
  });
139
130
  }
140
- /**
141
- * 获取完整用户信息(如果已认证)
142
- */
143
131
  getUser() {
144
132
  return __awaiter(this, void 0, void 0, function* () {
145
133
  try {
@@ -1,47 +1,47 @@
1
1
  import { MoneyPriceConfig, PaymentProviderConfig, EnhancePricePlan } from '@windrun-huaiin/third-ui/main/server';
2
2
  export declare const moneyPriceConfig: MoneyPriceConfig;
3
3
  /**
4
- * 获取当前激活的支付供应商配置
4
+ * Get the currently active payment provider configuration.
5
5
  *
6
- * 🔒 安全设计:
7
- * - wrapper函数隐藏moneyPriceConfig
8
- * - util层负责从config中提取激活的provider配置
9
- * - 外部只能通过这个wrapper访问,看不到config对象
6
+ * Security design:
7
+ * - Wrapper functions keep moneyPriceConfig private.
8
+ * - Utility functions extract the active provider configuration from the config.
9
+ * - External callers can access only this wrapper, not the full config object.
10
10
  *
11
- * @returns 当前激活的支付供应商配置
11
+ * @returns The currently active payment provider configuration.
12
12
  */
13
13
  export declare function getActiveProviderConfig(): PaymentProviderConfig;
14
14
  /**
15
- * 根据 priceId 获取对应的积分数量
15
+ * Get the credit amount for a price ID.
16
16
  *
17
- * 🔒 安全设计:
18
- * - wrapper函数隐藏moneyPriceConfig
19
- * - util层负责解析config并提取结果
20
- * - 外部只能通过这个wrapper访问,看不到config对象
17
+ * Security design:
18
+ * - Wrapper functions keep moneyPriceConfig private.
19
+ * - Utility functions parse the config and extract the result.
20
+ * - External callers can access only this wrapper, not the full config object.
21
21
  *
22
- * @param priceId - 查询的价格ID
23
- * @param _provider - 保留参数(向后兼容),暂未使用
24
- * @returns 对应的积分数量,或null
22
+ * @param priceId - Price ID to query.
23
+ * @param _provider - Reserved for backward compatibility; currently unused.
24
+ * @returns The matching credit amount, or null.
25
25
  */
26
26
  export declare function getCreditsFromPriceId(priceId?: string, _provider?: string): number | null;
27
27
  /**
28
- * 根据查询参数获取价格配置
28
+ * Get price configuration by query parameters.
29
29
  *
30
- * 支持三种查询方式:
31
- * 1. priceId 查询:getPriceConfig(priceId='price_xxx')
32
- * 2. plan billingType 查询:getPriceConfig(undefined, 'P2', 'monthly')
33
- * 3. plan 查询:getPriceConfig(undefined, 'P2')
30
+ * Supported query modes:
31
+ * 1. By priceId: getPriceConfig(priceId='price_xxx')
32
+ * 2. By plan and billingType: getPriceConfig(undefined, 'P2', 'monthly')
33
+ * 3. By plan: getPriceConfig(undefined, 'P2')
34
34
  *
35
- * 🔒 安全设计:
36
- * - wrapper函数隐藏moneyPriceConfig
37
- * - util层负责解析config并提取匹配的结果
38
- * - 外部只能通过这个wrapper访问,看不到config对象
35
+ * Security design:
36
+ * - Wrapper functions keep moneyPriceConfig private.
37
+ * - Utility functions parse the config and extract the matching result.
38
+ * - External callers can access only this wrapper, not the full config object.
39
39
  *
40
- * @param priceId - 查询的价格ID(可选)
41
- * @param plan - 查询的套餐名称如'P2''U3'(可选)
42
- * @param billingType - 查询的计费类型如'monthly''yearly'(可选)
43
- * @param _provider - 保留参数(向后兼容),暂未使用
44
- * @returns 匹配的价格配置,包含计算好的元数据(priceNamedescriptioninterval
40
+ * @param priceId - Optional price ID to query.
41
+ * @param plan - Optional plan name, such as 'P2' or 'U3'.
42
+ * @param billingType - Optional billing type, such as 'monthly' or 'yearly'.
43
+ * @param _provider - Reserved for backward compatibility; currently unused.
44
+ * @returns The matching price config with derived metadata: priceName, description, and interval.
45
45
  */
46
46
  export declare function getPriceConfig(priceId?: string, plan?: string, billingType?: string, _provider?: string): (EnhancePricePlan & {
47
47
  priceName: string;
@@ -7,7 +7,7 @@ const moneyPriceConfig = {
7
7
  stripe: {
8
8
  provider: 'stripe',
9
9
  enabled: true,
10
- // 订阅模式产品
10
+ // Subscription products
11
11
  subscriptionProducts: {
12
12
  F1: {
13
13
  key: 'F1',
@@ -65,7 +65,7 @@ const moneyPriceConfig = {
65
65
  }
66
66
  }
67
67
  },
68
- // 积分包产品
68
+ // Credit pack products
69
69
  creditPackProducts: {
70
70
  F1: {
71
71
  key: 'F1',
@@ -98,53 +98,53 @@ const moneyPriceConfig = {
98
98
  minFeaturesCount: 4
99
99
  }
100
100
  };
101
- // ============ 应用层wrapper - 隐藏moneyPriceConfig细节 ============
101
+ // ============ Application-level wrappers that hide moneyPriceConfig details ============
102
102
  /**
103
- * 获取当前激活的支付供应商配置
103
+ * Get the currently active payment provider configuration.
104
104
  *
105
- * 🔒 安全设计:
106
- * - wrapper函数隐藏moneyPriceConfig
107
- * - util层负责从config中提取激活的provider配置
108
- * - 外部只能通过这个wrapper访问,看不到config对象
105
+ * Security design:
106
+ * - Wrapper functions keep moneyPriceConfig private.
107
+ * - Utility functions extract the active provider configuration from the config.
108
+ * - External callers can access only this wrapper, not the full config object.
109
109
  *
110
- * @returns 当前激活的支付供应商配置
110
+ * @returns The currently active payment provider configuration.
111
111
  */
112
112
  function getActiveProviderConfig() {
113
113
  return server.getActiveProviderConfigUtil(moneyPriceConfig);
114
114
  }
115
115
  /**
116
- * 根据 priceId 获取对应的积分数量
116
+ * Get the credit amount for a price ID.
117
117
  *
118
- * 🔒 安全设计:
119
- * - wrapper函数隐藏moneyPriceConfig
120
- * - util层负责解析config并提取结果
121
- * - 外部只能通过这个wrapper访问,看不到config对象
118
+ * Security design:
119
+ * - Wrapper functions keep moneyPriceConfig private.
120
+ * - Utility functions parse the config and extract the result.
121
+ * - External callers can access only this wrapper, not the full config object.
122
122
  *
123
- * @param priceId - 查询的价格ID
124
- * @param _provider - 保留参数(向后兼容),暂未使用
125
- * @returns 对应的积分数量,或null
123
+ * @param priceId - Price ID to query.
124
+ * @param _provider - Reserved for backward compatibility; currently unused.
125
+ * @returns The matching credit amount, or null.
126
126
  */
127
127
  function getCreditsFromPriceId(priceId, _provider) {
128
128
  return server.getCreditsFromPriceIdUtil(priceId, moneyPriceConfig);
129
129
  }
130
130
  /**
131
- * 根据查询参数获取价格配置
131
+ * Get price configuration by query parameters.
132
132
  *
133
- * 支持三种查询方式:
134
- * 1. priceId 查询:getPriceConfig(priceId='price_xxx')
135
- * 2. plan billingType 查询:getPriceConfig(undefined, 'P2', 'monthly')
136
- * 3. plan 查询:getPriceConfig(undefined, 'P2')
133
+ * Supported query modes:
134
+ * 1. By priceId: getPriceConfig(priceId='price_xxx')
135
+ * 2. By plan and billingType: getPriceConfig(undefined, 'P2', 'monthly')
136
+ * 3. By plan: getPriceConfig(undefined, 'P2')
137
137
  *
138
- * 🔒 安全设计:
139
- * - wrapper函数隐藏moneyPriceConfig
140
- * - util层负责解析config并提取匹配的结果
141
- * - 外部只能通过这个wrapper访问,看不到config对象
138
+ * Security design:
139
+ * - Wrapper functions keep moneyPriceConfig private.
140
+ * - Utility functions parse the config and extract the matching result.
141
+ * - External callers can access only this wrapper, not the full config object.
142
142
  *
143
- * @param priceId - 查询的价格ID(可选)
144
- * @param plan - 查询的套餐名称如'P2''U3'(可选)
145
- * @param billingType - 查询的计费类型如'monthly''yearly'(可选)
146
- * @param _provider - 保留参数(向后兼容),暂未使用
147
- * @returns 匹配的价格配置,包含计算好的元数据(priceNamedescriptioninterval
143
+ * @param priceId - Optional price ID to query.
144
+ * @param plan - Optional plan name, such as 'P2' or 'U3'.
145
+ * @param billingType - Optional billing type, such as 'monthly' or 'yearly'.
146
+ * @param _provider - Reserved for backward compatibility; currently unused.
147
+ * @returns The matching price config with derived metadata: priceName, description, and interval.
148
148
  */
149
149
  function getPriceConfig(priceId, plan, billingType, _provider) {
150
150
  return server.getPriceConfigUtil(priceId, plan, billingType, moneyPriceConfig);
@@ -5,7 +5,7 @@ const moneyPriceConfig = {
5
5
  stripe: {
6
6
  provider: 'stripe',
7
7
  enabled: true,
8
- // 订阅模式产品
8
+ // Subscription products
9
9
  subscriptionProducts: {
10
10
  F1: {
11
11
  key: 'F1',
@@ -63,7 +63,7 @@ const moneyPriceConfig = {
63
63
  }
64
64
  }
65
65
  },
66
- // 积分包产品
66
+ // Credit pack products
67
67
  creditPackProducts: {
68
68
  F1: {
69
69
  key: 'F1',
@@ -96,53 +96,53 @@ const moneyPriceConfig = {
96
96
  minFeaturesCount: 4
97
97
  }
98
98
  };
99
- // ============ 应用层wrapper - 隐藏moneyPriceConfig细节 ============
99
+ // ============ Application-level wrappers that hide moneyPriceConfig details ============
100
100
  /**
101
- * 获取当前激活的支付供应商配置
101
+ * Get the currently active payment provider configuration.
102
102
  *
103
- * 🔒 安全设计:
104
- * - wrapper函数隐藏moneyPriceConfig
105
- * - util层负责从config中提取激活的provider配置
106
- * - 外部只能通过这个wrapper访问,看不到config对象
103
+ * Security design:
104
+ * - Wrapper functions keep moneyPriceConfig private.
105
+ * - Utility functions extract the active provider configuration from the config.
106
+ * - External callers can access only this wrapper, not the full config object.
107
107
  *
108
- * @returns 当前激活的支付供应商配置
108
+ * @returns The currently active payment provider configuration.
109
109
  */
110
110
  function getActiveProviderConfig() {
111
111
  return getActiveProviderConfigUtil(moneyPriceConfig);
112
112
  }
113
113
  /**
114
- * 根据 priceId 获取对应的积分数量
114
+ * Get the credit amount for a price ID.
115
115
  *
116
- * 🔒 安全设计:
117
- * - wrapper函数隐藏moneyPriceConfig
118
- * - util层负责解析config并提取结果
119
- * - 外部只能通过这个wrapper访问,看不到config对象
116
+ * Security design:
117
+ * - Wrapper functions keep moneyPriceConfig private.
118
+ * - Utility functions parse the config and extract the result.
119
+ * - External callers can access only this wrapper, not the full config object.
120
120
  *
121
- * @param priceId - 查询的价格ID
122
- * @param _provider - 保留参数(向后兼容),暂未使用
123
- * @returns 对应的积分数量,或null
121
+ * @param priceId - Price ID to query.
122
+ * @param _provider - Reserved for backward compatibility; currently unused.
123
+ * @returns The matching credit amount, or null.
124
124
  */
125
125
  function getCreditsFromPriceId(priceId, _provider) {
126
126
  return getCreditsFromPriceIdUtil(priceId, moneyPriceConfig);
127
127
  }
128
128
  /**
129
- * 根据查询参数获取价格配置
129
+ * Get price configuration by query parameters.
130
130
  *
131
- * 支持三种查询方式:
132
- * 1. priceId 查询:getPriceConfig(priceId='price_xxx')
133
- * 2. plan billingType 查询:getPriceConfig(undefined, 'P2', 'monthly')
134
- * 3. plan 查询:getPriceConfig(undefined, 'P2')
131
+ * Supported query modes:
132
+ * 1. By priceId: getPriceConfig(priceId='price_xxx')
133
+ * 2. By plan and billingType: getPriceConfig(undefined, 'P2', 'monthly')
134
+ * 3. By plan: getPriceConfig(undefined, 'P2')
135
135
  *
136
- * 🔒 安全设计:
137
- * - wrapper函数隐藏moneyPriceConfig
138
- * - util层负责解析config并提取匹配的结果
139
- * - 外部只能通过这个wrapper访问,看不到config对象
136
+ * Security design:
137
+ * - Wrapper functions keep moneyPriceConfig private.
138
+ * - Utility functions parse the config and extract the matching result.
139
+ * - External callers can access only this wrapper, not the full config object.
140
140
  *
141
- * @param priceId - 查询的价格ID(可选)
142
- * @param plan - 查询的套餐名称如'P2''U3'(可选)
143
- * @param billingType - 查询的计费类型如'monthly''yearly'(可选)
144
- * @param _provider - 保留参数(向后兼容),暂未使用
145
- * @returns 匹配的价格配置,包含计算好的元数据(priceNamedescriptioninterval
141
+ * @param priceId - Optional price ID to query.
142
+ * @param plan - Optional plan name, such as 'P2' or 'U3'.
143
+ * @param billingType - Optional billing type, such as 'monthly' or 'yearly'.
144
+ * @param _provider - Reserved for backward compatibility; currently unused.
145
+ * @returns The matching price config with derived metadata: priceName, description, and interval.
146
146
  */
147
147
  function getPriceConfig(priceId, plan, billingType, _provider) {
148
148
  return getPriceConfigUtil(priceId, plan, billingType, moneyPriceConfig);
@@ -60,7 +60,7 @@ const createCheckoutSession = (params, subscriptionData) => tslib.__awaiter(void
60
60
  }
61
61
  // One-time payment specific configuration
62
62
  if (isSubscriptionMode) {
63
- // 在这里注入订单元数据,以保证后续事件处理能根据订单去匹配处理,只能在订阅模式里设置数据,否则Stripe报错
63
+ // Attach order metadata for later event matching. Stripe only allows this in subscription mode.
64
64
  sessionParams.subscription_data = subscriptionData;
65
65
  }
66
66
  else {
@@ -89,7 +89,7 @@ const createCheckoutSession = (params, subscriptionData) => tslib.__awaiter(void
89
89
  throw error;
90
90
  }
91
91
  });
92
- // 根据发票ID去查支付ID
92
+ // Resolve the payment ID from an invoice ID.
93
93
  const fetchPaymentId = (invoiceId) => tslib.__awaiter(void 0, void 0, void 0, function* () {
94
94
  var _a, _b;
95
95
  const fullInvoice = yield getStripe().invoices.retrieve(invoiceId, {
@@ -147,7 +147,7 @@ const createOrGetCustomer = (params) => tslib.__awaiter(void 0, void 0, void 0,
147
147
  return stripeCustomer.id;
148
148
  }
149
149
  }
150
- // 创建新客户
150
+ // Create a new customer.
151
151
  const customerParams = {
152
152
  metadata: {
153
153
  user_id: userId,
@@ -58,7 +58,7 @@ const createCheckoutSession = (params, subscriptionData) => __awaiter(void 0, vo
58
58
  }
59
59
  // One-time payment specific configuration
60
60
  if (isSubscriptionMode) {
61
- // 在这里注入订单元数据,以保证后续事件处理能根据订单去匹配处理,只能在订阅模式里设置数据,否则Stripe报错
61
+ // Attach order metadata for later event matching. Stripe only allows this in subscription mode.
62
62
  sessionParams.subscription_data = subscriptionData;
63
63
  }
64
64
  else {
@@ -87,7 +87,7 @@ const createCheckoutSession = (params, subscriptionData) => __awaiter(void 0, vo
87
87
  throw error;
88
88
  }
89
89
  });
90
- // 根据发票ID去查支付ID
90
+ // Resolve the payment ID from an invoice ID.
91
91
  const fetchPaymentId = (invoiceId) => __awaiter(void 0, void 0, void 0, function* () {
92
92
  var _a, _b;
93
93
  const fullInvoice = yield getStripe().invoices.retrieve(invoiceId, {
@@ -145,7 +145,7 @@ const createOrGetCustomer = (params) => __awaiter(void 0, void 0, void 0, functi
145
145
  return stripeCustomer.id;
146
146
  }
147
147
  }
148
- // 创建新客户
148
+ // Create a new customer.
149
149
  const customerParams = {
150
150
  metadata: {
151
151
  user_id: userId,
@@ -3,7 +3,7 @@
3
3
  var tslib = require('tslib');
4
4
  var prisma = require('./prisma.js');
5
5
 
6
- // 事务工具类,回滚时打印回滚日志
6
+ // Transaction helper that logs rollback details on failure.
7
7
  function runInTransaction(fn, operationName) {
8
8
  return tslib.__awaiter(this, void 0, void 0, function* () {
9
9
  const start = Date.now();
@@ -1,7 +1,7 @@
1
1
  import { __awaiter } from 'tslib';
2
2
  import { getBackendCorePrisma } from './prisma.mjs';
3
3
 
4
- // 事务工具类,回滚时打印回滚日志
4
+ // Transaction helper that logs rollback details on failure.
5
5
  function runInTransaction(fn, operationName) {
6
6
  return __awaiter(this, void 0, void 0, function* () {
7
7
  const start = Date.now();
@@ -1 +1 @@
1
- {"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../../src/prisma/prisma.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEzD,MAAM,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAClE,MAAM,MAAM,2BAA2B,GAAG;IAKxC,YAAY,EAAE,GAAG,CAAC;IAElB,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,WAAW,EAAE,GAAG,CAAC;IAEjB,iBAAiB,CAAC,EAAE,GAAG,CAAC;IAExB,SAAS,EAAE,GAAG,CAAC;IAEf,eAAe,CAAC,EAAE,GAAG,CAAC;IAEtB,IAAI,EAAE,GAAG,CAAC;IAEV,YAAY,EAAE,GAAG,CAAC;IAElB,MAAM,EAAE,GAAG,CAAC;IAEZ,WAAW,EAAE,GAAG,CAAC;IAEjB,cAAc,EAAE,GAAG,CAAC;IAEpB,UAAU,EAAE,GAAG,CAAC;IAEhB,MAAM,EAAE,GAAG,CAAC;CACb,CAAC;AA2CF,wBAAgB,kBAAkB,IAAI,KAAK,CAI1C;AAED,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,2BAA2B,EACzC,UAAU,SAAmE,GAC5E,2BAA2B,CAK7B;AAED,wBAAgB,oBAAoB,IAAI,uBAAuB,CAQ9D;AAID,eAAO,MAAM,MAAM,6BAIjB,CAAC;AAuFH,wBAAgB,+BAA+B,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,GAAG,uBAAuB,CAEjI"}
1
+ {"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../../src/prisma/prisma.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEzD,MAAM,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAClE,MAAM,MAAM,2BAA2B,GAAG;IAKxC,YAAY,EAAE,GAAG,CAAC;IAElB,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,WAAW,EAAE,GAAG,CAAC;IAEjB,iBAAiB,CAAC,EAAE,GAAG,CAAC;IAExB,SAAS,EAAE,GAAG,CAAC;IAEf,eAAe,CAAC,EAAE,GAAG,CAAC;IAEtB,IAAI,EAAE,GAAG,CAAC;IAEV,YAAY,EAAE,GAAG,CAAC;IAElB,MAAM,EAAE,GAAG,CAAC;IAEZ,WAAW,EAAE,GAAG,CAAC;IAEjB,cAAc,EAAE,GAAG,CAAC;IAEpB,UAAU,EAAE,GAAG,CAAC;IAEhB,MAAM,EAAE,GAAG,CAAC;CACb,CAAC;AA2CF,wBAAgB,kBAAkB,IAAI,KAAK,CAI1C;AAED,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,2BAA2B,EACzC,UAAU,SAAmE,GAC5E,2BAA2B,CAK7B;AAED,wBAAgB,oBAAoB,IAAI,uBAAuB,CAQ9D;AAID,eAAO,MAAM,MAAM,6BAIjB,CAAC;AAsFH,wBAAgB,+BAA+B,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,GAAG,uBAAuB,CAEjI"}
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const globalForPrisma = globalThis;
4
- // ==================== 日志配置 ====================
4
+ // ==================== Logging Configuration ====================
5
5
  const getLogConfig = () => {
6
6
  if (process.env.PRISMA_DEBUG === 'true') {
7
7
  return [
@@ -67,41 +67,40 @@ function registerDevelopmentQueryLogger(prismaClient, instanceId) {
67
67
  const listenerId = `listener_${Date.now()}_${Math.random().toString(36).substr(2, 5)}`;
68
68
  globalForPrisma[ID_KEY] = listenerId;
69
69
  console.log(`Prisma Query Logger Registered | Listener ID: ${listenerId} | Instance ID: ${instanceId}`);
70
- // --- 自定义SQL拼接 ---
70
+ // --- Custom SQL interpolation ---
71
71
  const interpolate = (query, params) => {
72
- // 1. 【核心修改】:安全检查和参数解析
72
+ // 1. Validate and parse parameters safely.
73
73
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
74
  let parameters = [];
75
75
  try {
76
- // 尝试解析 params 字符串
77
- // 如果 params 是空字符串 "",或者不是有效的 JSON,这里会捕获错误
76
+ // Parse the params string. Empty strings or invalid JSON are handled by the catch block.
78
77
  parameters = params && params.length > 0 ? JSON.parse(params) : [];
79
78
  // eslint-disable-next-line unused-imports/no-unused-vars
80
79
  }
81
80
  catch (e) {
82
- // 如果无法解析,则直接返回原始查询,跳过替换
81
+ // If parsing fails, return the original query without interpolation.
83
82
  return query;
84
83
  }
85
- // 确保 parameters 是一个数组
84
+ // Ensure parameters is an array.
86
85
  if (!Array.isArray(parameters)) {
87
- console.warn('Prisma params解析结果不是数组,跳过参数替换。Result:', parameters);
86
+ console.warn('Prisma params did not parse to an array; skipping parameter interpolation. Result:', parameters);
88
87
  return query;
89
88
  }
90
- // 如果没有参数,直接返回查询
89
+ // If there are no parameters, return the query as-is.
91
90
  if (parameters.length === 0) {
92
91
  return query;
93
92
  }
94
- // 2. 将参数列表的值进行安全的字符串化处理
93
+ // 2. Safely stringify parameter values.
95
94
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
95
  const safeValues = parameters.map((p) => {
97
96
  if (p === null)
98
97
  return 'NULL';
99
- // 对字符串类型的值加上单引号并转义(这是SQL安全的关键)
98
+ // Quote and escape string values for readable SQL logging.
100
99
  if (typeof p === 'string')
101
100
  return `'${p.replace(/'/g, "''")}'`;
102
- return p; // 数字、布尔值等直接返回
101
+ return p; // Numbers, booleans, and similar values can be returned directly.
103
102
  });
104
- // 3. 循环替换 $1, $2, ...
103
+ // 3. Replace $1, $2, ... placeholders.
105
104
  let sql = query;
106
105
  for (let i = 0; i < safeValues.length; i++) {
107
106
  const placeholder = new RegExp('\\$' + (i + 1) + '(?!\\d)', 'g');
@@ -114,20 +113,20 @@ function registerDevelopmentQueryLogger(prismaClient, instanceId) {
114
113
  const slow = ms >= 200 ? '🐌 SLOW SQL ' : '🚀 SQL';
115
114
  const interpolatedSql = interpolate(event.query, event.params);
116
115
  const clean = interpolatedSql
117
- .replace(/"[^"]+"\./g, '') // "".
118
- .replace(/= '([^']+)'/g, `= '$1'`) // 已经替换成单引号,此处可以优化
119
- .replace(/"/g, ''); // 彻底灭双引号
116
+ .replace(/"[^"]+"\./g, '') // Remove "table". prefixes.
117
+ .replace(/= '([^']+)'/g, `= '$1'`) // Keep normalized quoted values.
118
+ .replace(/"/g, ''); // Remove remaining double quotes.
120
119
  console.log('─'.repeat(60));
121
120
  console.log(`Prisma Instance ID: ${instanceId} | Listener ID: ${listenerId}`);
122
121
  console.log(`${clean};`);
123
- console.log(`⏰ 耗时: ${ms}ms, ${slow}`);
122
+ console.log(`Duration: ${ms}ms, ${slow}`);
124
123
  };
125
- // 注册包装后的 handler
124
+ // Register the wrapped handler.
126
125
  (_a = prismaClient.$on) === null || _a === void 0 ? void 0 : _a.call(prismaClient, 'query', wrappedHandler);
127
126
  globalForPrisma[REGISTERED_KEY] = true;
128
127
  }
129
128
  }
130
- // ==================== 便捷方法, 入参事务客户端不存在或者不传, 就返回全局非事务客户端 ====================
129
+ // ==================== Client Helper: fall back to the global non-transaction client when no transaction client is provided ====================
131
130
  function checkAndFallbackWithNonTCClient(tx) {
132
131
  return tx !== null && tx !== void 0 ? tx : getBackendCorePrisma();
133
132
  }