@windrun-huaiin/backend-core 30.0.0 → 31.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -0
- package/dist/app/api/user/anonymous/init/fingerprint-only-route.d.ts +8 -0
- package/dist/app/api/user/anonymous/init/fingerprint-only-route.d.ts.map +1 -0
- package/dist/app/api/user/anonymous/init/fingerprint-only-route.js +20 -0
- package/dist/app/api/user/anonymous/init/fingerprint-only-route.mjs +18 -0
- package/dist/app/api/user/anonymous/init/route-shared.d.ts +10 -0
- package/dist/app/api/user/anonymous/init/route-shared.d.ts.map +1 -0
- package/dist/app/api/user/anonymous/init/route-shared.js +557 -0
- package/dist/app/api/user/anonymous/init/route-shared.mjs +555 -0
- package/dist/app/api/user/anonymous/init/route.d.ts +3 -3
- package/dist/app/api/user/anonymous/init/route.d.ts.map +1 -1
- package/dist/app/api/user/anonymous/init/route.js +6 -554
- package/dist/app/api/user/anonymous/init/route.mjs +7 -555
- 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 +18 -6
- package/src/app/api/user/anonymous/init/fingerprint-only-route.ts +14 -0
- package/src/app/api/user/anonymous/init/route-shared.ts +710 -0
- package/src/app/api/user/anonymous/init/route.ts +7 -712
- 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
|
@@ -18,10 +18,10 @@ function POST(request) {
|
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
var _a, _b, _c;
|
|
20
20
|
try {
|
|
21
|
-
//
|
|
21
|
+
// Read the raw request body.
|
|
22
22
|
const rawBody = yield request.text();
|
|
23
23
|
let event;
|
|
24
|
-
//
|
|
24
|
+
// Skip signature verification in development.
|
|
25
25
|
if (process.env.NODE_ENV === 'development') {
|
|
26
26
|
console.log('Development mode: skipping webhook signature verification');
|
|
27
27
|
try {
|
|
@@ -33,22 +33,22 @@ function POST(request) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
//
|
|
36
|
+
// Verify the signature in production.
|
|
37
37
|
const headerPayload = yield headers();
|
|
38
38
|
const svix_id = headerPayload.get('svix-id');
|
|
39
39
|
const svix_timestamp = headerPayload.get('svix-timestamp');
|
|
40
40
|
const svix_signature = headerPayload.get('svix-signature');
|
|
41
|
-
//
|
|
41
|
+
// Reject requests missing required headers.
|
|
42
42
|
if (!svix_id || !svix_timestamp || !svix_signature) {
|
|
43
43
|
return NextResponse.json({ error: 'Missing webhook headers' }, { status: 400 });
|
|
44
44
|
}
|
|
45
|
-
//
|
|
45
|
+
// Load the webhook signing secret.
|
|
46
46
|
const webhookSecret = process.env.CLERK_WEBHOOK_SECRET;
|
|
47
47
|
if (!webhookSecret) {
|
|
48
48
|
console.error('CLERK_WEBHOOK_SECRET is not configured');
|
|
49
49
|
return NextResponse.json({ error: 'Webhook configuration error' }, { status: 500 });
|
|
50
50
|
}
|
|
51
|
-
//
|
|
51
|
+
// Verify the webhook signature.
|
|
52
52
|
try {
|
|
53
53
|
const wh = new Webhook(webhookSecret);
|
|
54
54
|
event = wh.verify(rawBody, {
|
|
@@ -70,7 +70,7 @@ function POST(request) {
|
|
|
70
70
|
}, event);
|
|
71
71
|
let processingResult = { success: true, message: 'Event processed successfully' };
|
|
72
72
|
try {
|
|
73
|
-
//
|
|
73
|
+
// Dispatch by event type.
|
|
74
74
|
const { type } = event;
|
|
75
75
|
switch (type) {
|
|
76
76
|
case 'user.created':
|
|
@@ -106,7 +106,7 @@ function POST(request) {
|
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
|
-
*
|
|
109
|
+
* Handle the user.created event.
|
|
110
110
|
*/
|
|
111
111
|
function handleUserCreated(event) {
|
|
112
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -125,7 +125,7 @@ function handleUserCreated(event) {
|
|
|
125
125
|
fingerprintId,
|
|
126
126
|
userName
|
|
127
127
|
});
|
|
128
|
-
//
|
|
128
|
+
// Validate required fields.
|
|
129
129
|
if (!fingerprintId) {
|
|
130
130
|
console.error('Missing fingerprintId in webhook data, process flow error');
|
|
131
131
|
return;
|
|
@@ -135,16 +135,16 @@ function handleUserCreated(event) {
|
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
137
137
|
try {
|
|
138
|
-
//
|
|
138
|
+
// Find all non-deleted users for this device fingerprint.
|
|
139
139
|
const existingUsers = yield userService.findListByFingerprintId(fingerprintId);
|
|
140
140
|
if (!existingUsers || existingUsers.length === 0) {
|
|
141
141
|
console.error('Invalid fingerprintId in webhook data, process flow error');
|
|
142
142
|
return;
|
|
143
143
|
}
|
|
144
|
-
//
|
|
144
|
+
// Find an existing user with the same email.
|
|
145
145
|
const sameEmailUser = existingUsers.find(user => user.email === email);
|
|
146
146
|
if (sameEmailUser) {
|
|
147
|
-
//
|
|
147
|
+
// Same account; update clerkUserId if needed.
|
|
148
148
|
if (sameEmailUser.clerkUserId !== clerkUserId) {
|
|
149
149
|
yield userService.updateUser(sameEmailUser.userId, { clerkUserId, userName: userName, status: UserStatus.REGISTERED });
|
|
150
150
|
console.log(`Updated clerkUserId for user ${sameEmailUser.userId}`);
|
|
@@ -154,15 +154,15 @@ function handleUserCreated(event) {
|
|
|
154
154
|
}
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
|
-
//
|
|
157
|
+
// Find an anonymous user with no email or clerkUserId.
|
|
158
158
|
const anonymousUser = existingUsers.find(user => !user.email && !user.clerkUserId && user.status === UserStatus.ANONYMOUS);
|
|
159
159
|
if (anonymousUser) {
|
|
160
|
-
//
|
|
160
|
+
// Upgrade the anonymous user.
|
|
161
161
|
yield userAggregateService.upgradeToRegistered(anonymousUser.userId, email, clerkUserId, userName);
|
|
162
162
|
console.log(`Successfully upgraded anonymous user ${anonymousUser.userId} to registered user`);
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
165
|
-
//
|
|
165
|
+
// New account on the same device; create a new user.
|
|
166
166
|
yield userAggregateService.createNewRegisteredUser(clerkUserId, email, fingerprintId, userName);
|
|
167
167
|
console.log(`Created new user for device ${fingerprintId} with email ${email}`);
|
|
168
168
|
}
|
|
@@ -173,7 +173,7 @@ function handleUserCreated(event) {
|
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
175
|
/**
|
|
176
|
-
*
|
|
176
|
+
* Handle the user.deleted event.
|
|
177
177
|
*/
|
|
178
178
|
function handleUserDeleted(event) {
|
|
179
179
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
2
|
import { User } from '../services/database/prisma-model-type';
|
|
3
3
|
import { type AuthProvider, type ProviderIdentity } from './auth-shared';
|
|
4
|
-
/**
|
|
5
|
-
* 认证结果类型
|
|
6
|
-
*/
|
|
7
4
|
export interface AuthResult {
|
|
8
5
|
userId: string;
|
|
9
6
|
user: User;
|
|
@@ -11,48 +8,36 @@ export interface AuthResult {
|
|
|
11
8
|
providerUserId: string;
|
|
12
9
|
}
|
|
13
10
|
/**
|
|
14
|
-
*
|
|
11
|
+
* Fetch User's info from header field by Middleware
|
|
15
12
|
*/
|
|
16
13
|
export declare function getAuthenticatedUser(req: NextRequest): Promise<AuthResult>;
|
|
17
14
|
/**
|
|
18
|
-
*
|
|
15
|
+
* Require Auth, success back user's id
|
|
19
16
|
*/
|
|
20
17
|
export declare function requireAuth(req: NextRequest): Promise<string>;
|
|
21
18
|
/**
|
|
22
|
-
*
|
|
19
|
+
* Require Auth, success back user's info
|
|
23
20
|
*/
|
|
24
21
|
export declare function requireAuthWithUser(req: NextRequest): Promise<AuthResult>;
|
|
25
22
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
23
|
+
* Only use in server side
|
|
24
|
+
* Server Component / Server Action, just need user's login status
|
|
28
25
|
*/
|
|
29
26
|
export declare function getOptionalServerAuthIdentity(): Promise<ProviderIdentity | null>;
|
|
30
27
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
28
|
+
* Only use in server side
|
|
29
|
+
* Server Component / Server Action, need user's login status and user's data, will check db
|
|
33
30
|
*/
|
|
34
31
|
export declare function getOptionalServerAuthUser(): Promise<AuthResult | null>;
|
|
35
32
|
/**
|
|
36
|
-
* API Route
|
|
33
|
+
* API Route Auth Util
|
|
37
34
|
*/
|
|
38
35
|
export declare class ApiAuthUtils {
|
|
39
36
|
private req;
|
|
40
37
|
constructor(req: NextRequest);
|
|
41
|
-
/**
|
|
42
|
-
* 要求用户必须已认证,返回用户ID
|
|
43
|
-
*/
|
|
44
38
|
requireAuth(): Promise<string>;
|
|
45
|
-
/**
|
|
46
|
-
* 要求用户必须已认证,返回完整用户信息
|
|
47
|
-
*/
|
|
48
39
|
requireAuthWithUser(): Promise<AuthResult>;
|
|
49
|
-
/**
|
|
50
|
-
* 获取用户ID(如果已认证)
|
|
51
|
-
*/
|
|
52
40
|
getUserId(): Promise<string | null>;
|
|
53
|
-
/**
|
|
54
|
-
* 获取完整用户信息(如果已认证)
|
|
55
|
-
*/
|
|
56
41
|
getUser(): Promise<AuthResult | null>;
|
|
57
42
|
}
|
|
58
43
|
//# sourceMappingURL=auth-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-utils.d.ts","sourceRoot":"","sources":["../../src/auth/auth-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,IAAI,EAAE,MAAM,wCAAwC,CAAC;AAC9D,OAAO,EAA6B,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEpG
|
|
1
|
+
{"version":3,"file":"auth-utils.d.ts","sourceRoot":"","sources":["../../src/auth/auth-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,IAAI,EAAE,MAAM,wCAAwC,CAAC;AAC9D,OAAO,EAA6B,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEpG,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAuBhF;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAGnE;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAE/E;AAED;;;GAGG;AACH,wBAAsB,6BAA6B,IAAI,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAetF;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAsB5E;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,GAAG,CAAc;gBAEb,GAAG,EAAE,WAAW;IAItB,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9B,mBAAmB,IAAI,OAAO,CAAC,UAAU,CAAC;IAI1C,SAAS,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IASnC,OAAO,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;CAO5C"}
|
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);
|