@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.
- package/README.md +95 -0
- package/dist/app/api/user/anonymous/init/route.d.ts +1 -1
- package/dist/app/api/user/anonymous/init/route.d.ts.map +1 -1
- package/dist/app/api/user/anonymous/init/route.js +18 -19
- package/dist/app/api/user/anonymous/init/route.mjs +18 -19
- package/dist/app/api/webhook/clerk/user/route.js +16 -16
- package/dist/app/api/webhook/clerk/user/route.mjs +16 -16
- package/dist/auth/auth-utils.d.ts +8 -23
- package/dist/auth/auth-utils.d.ts.map +1 -1
- package/dist/auth/auth-utils.js +8 -20
- package/dist/auth/auth-utils.mjs +8 -20
- package/dist/lib/money-price-config.d.ts +28 -28
- package/dist/lib/money-price-config.js +31 -31
- package/dist/lib/money-price-config.mjs +31 -31
- package/dist/lib/stripe-config.js +3 -3
- package/dist/lib/stripe-config.mjs +3 -3
- package/dist/prisma/prisma-transaction-util.js +1 -1
- package/dist/prisma/prisma-transaction-util.mjs +1 -1
- package/dist/prisma/prisma.d.ts.map +1 -1
- package/dist/prisma/prisma.js +18 -19
- package/dist/prisma/prisma.mjs +18 -19
- package/dist/services/aggregate/billing.aggregate.service.js +6 -6
- package/dist/services/aggregate/billing.aggregate.service.mjs +6 -6
- package/dist/services/aggregate/user.aggregate.service.d.ts +9 -9
- package/dist/services/aggregate/user.aggregate.service.js +16 -16
- package/dist/services/aggregate/user.aggregate.service.mjs +16 -16
- package/dist/services/database/constants.js +34 -34
- package/dist/services/database/constants.mjs +34 -34
- package/dist/services/database/credit.service.js +2 -2
- package/dist/services/database/credit.service.mjs +2 -2
- package/dist/services/database/transaction.service.js +1 -1
- package/dist/services/database/transaction.service.mjs +1 -1
- package/dist/services/database/user.service.js +2 -2
- package/dist/services/database/user.service.mjs +2 -2
- package/dist/services/stripe/webhook-handler.js +5 -5
- package/dist/services/stripe/webhook-handler.mjs +5 -5
- package/package.json +13 -6
- package/src/app/api/user/anonymous/init/route.ts +21 -22
- package/src/app/api/webhook/clerk/user/route.ts +17 -17
- package/src/auth/auth-utils.ts +8 -23
- package/src/lib/money-price-config.ts +31 -32
- package/src/lib/stripe-config.ts +3 -3
- package/src/prisma/prisma-transaction-util.ts +1 -1
- package/src/prisma/prisma.ts +18 -19
- package/src/services/aggregate/billing.aggregate.service.ts +7 -7
- package/src/services/aggregate/user.aggregate.service.ts +16 -16
- package/src/services/database/constants.ts +34 -34
- package/src/services/database/credit.service.ts +2 -2
- package/src/services/database/transaction.service.ts +1 -1
- package/src/services/database/user.service.ts +2 -2
- package/src/services/stripe/webhook-handler.ts +5 -5
package/dist/auth/auth-utils.js
CHANGED
|
@@ -8,7 +8,7 @@ require('../services/database/credit.service.js');
|
|
|
8
8
|
var authShared = require('./auth-shared.js');
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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 {
|
package/dist/auth/auth-utils.mjs
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
* -
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
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
|
-
*
|
|
15
|
+
* Get the credit amount for a price ID.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
* -
|
|
19
|
-
* -
|
|
20
|
-
* -
|
|
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 -
|
|
23
|
-
* @param _provider -
|
|
24
|
-
* @returns
|
|
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.
|
|
32
|
-
* 2.
|
|
33
|
-
* 3.
|
|
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
|
-
* -
|
|
37
|
-
* -
|
|
38
|
-
* -
|
|
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 -
|
|
41
|
-
* @param plan -
|
|
42
|
-
* @param billingType -
|
|
43
|
-
* @param _provider -
|
|
44
|
-
* @returns
|
|
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
|
-
// ============
|
|
101
|
+
// ============ Application-level wrappers that hide moneyPriceConfig details ============
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
103
|
+
* Get the currently active payment provider configuration.
|
|
104
104
|
*
|
|
105
|
-
*
|
|
106
|
-
* -
|
|
107
|
-
* -
|
|
108
|
-
* -
|
|
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
|
-
*
|
|
116
|
+
* Get the credit amount for a price ID.
|
|
117
117
|
*
|
|
118
|
-
*
|
|
119
|
-
* -
|
|
120
|
-
* -
|
|
121
|
-
* -
|
|
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 -
|
|
124
|
-
* @param _provider -
|
|
125
|
-
* @returns
|
|
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.
|
|
135
|
-
* 2.
|
|
136
|
-
* 3.
|
|
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
|
-
* -
|
|
140
|
-
* -
|
|
141
|
-
* -
|
|
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 -
|
|
144
|
-
* @param plan -
|
|
145
|
-
* @param billingType -
|
|
146
|
-
* @param _provider -
|
|
147
|
-
* @returns
|
|
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
|
-
// ============
|
|
99
|
+
// ============ Application-level wrappers that hide moneyPriceConfig details ============
|
|
100
100
|
/**
|
|
101
|
-
*
|
|
101
|
+
* Get the currently active payment provider configuration.
|
|
102
102
|
*
|
|
103
|
-
*
|
|
104
|
-
* -
|
|
105
|
-
* -
|
|
106
|
-
* -
|
|
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
|
-
*
|
|
114
|
+
* Get the credit amount for a price ID.
|
|
115
115
|
*
|
|
116
|
-
*
|
|
117
|
-
* -
|
|
118
|
-
* -
|
|
119
|
-
* -
|
|
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 -
|
|
122
|
-
* @param _provider -
|
|
123
|
-
* @returns
|
|
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.
|
|
133
|
-
* 2.
|
|
134
|
-
* 3.
|
|
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
|
-
* -
|
|
138
|
-
* -
|
|
139
|
-
* -
|
|
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 -
|
|
142
|
-
* @param plan -
|
|
143
|
-
* @param billingType -
|
|
144
|
-
* @param _provider -
|
|
145
|
-
* @returns
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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;
|
|
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"}
|
package/dist/prisma/prisma.js
CHANGED
|
@@ -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
|
-
// ---
|
|
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
|
-
//
|
|
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
|
-
//
|
|
84
|
+
// Ensure parameters is an array.
|
|
86
85
|
if (!Array.isArray(parameters)) {
|
|
87
|
-
console.warn('Prisma params
|
|
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
|
-
//
|
|
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.
|
|
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(
|
|
122
|
+
console.log(`Duration: ${ms}ms, ${slow}`);
|
|
124
123
|
};
|
|
125
|
-
//
|
|
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
|
}
|