@windrun-huaiin/backend-core 14.5.0 → 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/prisma/index.d.ts +0 -1
- package/dist/prisma/index.d.ts.map +1 -1
- package/package.json +5 -10
- package/src/prisma/index.ts +0 -1
- package/dist/lib/auth-utils.d.ts +0 -46
- package/dist/lib/auth-utils.d.ts.map +0 -1
- package/dist/lib/auth-utils.js +0 -107
- package/dist/lib/auth-utils.mjs +0 -102
- package/dist/prisma/client.d.ts +0 -2
- package/dist/prisma/client.d.ts.map +0 -1
- package/dist/prisma/client.js +0 -12
- package/dist/prisma/client.mjs +0 -1
- package/src/prisma/client.ts +0 -2
package/dist/prisma/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prisma/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prisma/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@windrun-huaiin/backend-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "15.0.0",
|
|
4
4
|
"description": "Shared backend primitives: Prisma schema/client, database services, routing helpers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,11 +17,6 @@
|
|
|
17
17
|
"import": "./dist/prisma/index.mjs",
|
|
18
18
|
"require": "./dist/prisma/index.js"
|
|
19
19
|
},
|
|
20
|
-
"./prisma/client": {
|
|
21
|
-
"types": "./dist/prisma/client.d.ts",
|
|
22
|
-
"import": "./dist/prisma/client.mjs",
|
|
23
|
-
"require": "./dist/prisma/client.js"
|
|
24
|
-
},
|
|
25
20
|
"./database": {
|
|
26
21
|
"types": "./dist/services/database/index.d.ts",
|
|
27
22
|
"import": "./dist/services/database/index.mjs",
|
|
@@ -109,8 +104,8 @@
|
|
|
109
104
|
"stripe": "20.0.0",
|
|
110
105
|
"svix": "^1.86.0",
|
|
111
106
|
"zod": "^4.3.6",
|
|
112
|
-
"@windrun-huaiin/
|
|
113
|
-
"@windrun-huaiin/
|
|
107
|
+
"@windrun-huaiin/lib": "^15.0.0",
|
|
108
|
+
"@windrun-huaiin/third-ui": "^15.0.0"
|
|
114
109
|
},
|
|
115
110
|
"devDependencies": {
|
|
116
111
|
"@rollup/plugin-alias": "^5.1.1",
|
|
@@ -133,8 +128,8 @@
|
|
|
133
128
|
"access": "public"
|
|
134
129
|
},
|
|
135
130
|
"scripts": {
|
|
136
|
-
"build": "rollup -c rollup.config.mjs",
|
|
137
|
-
"build:prod": "rollup -c rollup.config.mjs",
|
|
131
|
+
"build": "rm -rf dist && rollup -c rollup.config.mjs",
|
|
132
|
+
"build:prod": "rm -rf dist && rollup -c rollup.config.mjs",
|
|
138
133
|
"dev": "rollup -c rollup.config.mjs --watch",
|
|
139
134
|
"clean": "rm -rf dist",
|
|
140
135
|
"type-check": "tsc --noEmit"
|
package/src/prisma/index.ts
CHANGED
package/dist/lib/auth-utils.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { NextRequest } from 'next/server';
|
|
2
|
-
import { User } from '../services/database/prisma-model-type';
|
|
3
|
-
/**
|
|
4
|
-
* 认证结果类型
|
|
5
|
-
*/
|
|
6
|
-
export interface AuthResult {
|
|
7
|
-
userId: string;
|
|
8
|
-
user: User;
|
|
9
|
-
clerkUserId: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* 从中间件设置的 Clerk ID 获取完整用户信息
|
|
13
|
-
*/
|
|
14
|
-
export declare function getAuthenticatedUser(req: NextRequest): Promise<AuthResult>;
|
|
15
|
-
/**
|
|
16
|
-
* 要求用户必须已认证,返回用户ID
|
|
17
|
-
*/
|
|
18
|
-
export declare function requireAuth(req: NextRequest): Promise<string>;
|
|
19
|
-
/**
|
|
20
|
-
* 要求用户必须已认证,返回完整用户信息
|
|
21
|
-
*/
|
|
22
|
-
export declare function requireAuthWithUser(req: NextRequest): Promise<AuthResult>;
|
|
23
|
-
/**
|
|
24
|
-
* API Route版本的认证工具函数
|
|
25
|
-
*/
|
|
26
|
-
export declare class ApiAuthUtils {
|
|
27
|
-
private req;
|
|
28
|
-
constructor(req: NextRequest);
|
|
29
|
-
/**
|
|
30
|
-
* 要求用户必须已认证,返回用户ID
|
|
31
|
-
*/
|
|
32
|
-
requireAuth(): Promise<string>;
|
|
33
|
-
/**
|
|
34
|
-
* 要求用户必须已认证,返回完整用户信息
|
|
35
|
-
*/
|
|
36
|
-
requireAuthWithUser(): Promise<AuthResult>;
|
|
37
|
-
/**
|
|
38
|
-
* 获取用户ID(如果已认证)
|
|
39
|
-
*/
|
|
40
|
-
getUserId(): Promise<string | null>;
|
|
41
|
-
/**
|
|
42
|
-
* 获取完整用户信息(如果已认证)
|
|
43
|
-
*/
|
|
44
|
-
getUser(): Promise<AuthResult | null>;
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=auth-utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-utils.d.ts","sourceRoot":"","sources":["../../src/lib/auth-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAE,MAAM,wCAAwC,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,IAAI,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAqBhF;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;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,GAAG,CAAc;gBAEb,GAAG,EAAE,WAAW;IAI5B;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAIpC;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,UAAU,CAAC;IAIhD;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IASzC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;CAO5C"}
|
package/dist/lib/auth-utils.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var tslib_es6 = require('../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.js');
|
|
4
|
-
var user_service = require('../services/database/user.service.js');
|
|
5
|
-
require('../prisma/prisma.js');
|
|
6
|
-
require('../services/database/credit.service.js');
|
|
7
|
-
require('@prisma/client');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 从中间件设置的 Clerk ID 获取完整用户信息
|
|
11
|
-
*/
|
|
12
|
-
function getAuthenticatedUser(req) {
|
|
13
|
-
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
try {
|
|
15
|
-
const clerkUserId = req.headers.get('x-clerk-user-id');
|
|
16
|
-
if (!clerkUserId) {
|
|
17
|
-
throw new Error('Authentication required');
|
|
18
|
-
}
|
|
19
|
-
const user = yield user_service.userService.findByClerkUserId(clerkUserId);
|
|
20
|
-
if (!user) {
|
|
21
|
-
throw new Error('User not found in database');
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
userId: user.userId,
|
|
25
|
-
user,
|
|
26
|
-
clerkUserId
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
console.error('Error getting authenticated user:', error);
|
|
31
|
-
throw error;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* 要求用户必须已认证,返回用户ID
|
|
37
|
-
*/
|
|
38
|
-
function requireAuth(req) {
|
|
39
|
-
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
const auth = yield getAuthenticatedUser(req);
|
|
41
|
-
return auth.userId;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* 要求用户必须已认证,返回完整用户信息
|
|
46
|
-
*/
|
|
47
|
-
function requireAuthWithUser(req) {
|
|
48
|
-
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
return yield getAuthenticatedUser(req);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* API Route版本的认证工具函数
|
|
54
|
-
*/
|
|
55
|
-
class ApiAuthUtils {
|
|
56
|
-
constructor(req) {
|
|
57
|
-
this.req = req;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* 要求用户必须已认证,返回用户ID
|
|
61
|
-
*/
|
|
62
|
-
requireAuth() {
|
|
63
|
-
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
return yield requireAuth(this.req);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* 要求用户必须已认证,返回完整用户信息
|
|
69
|
-
*/
|
|
70
|
-
requireAuthWithUser() {
|
|
71
|
-
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
return yield requireAuthWithUser(this.req);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* 获取用户ID(如果已认证)
|
|
77
|
-
*/
|
|
78
|
-
getUserId() {
|
|
79
|
-
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
try {
|
|
81
|
-
const auth = yield getAuthenticatedUser(this.req);
|
|
82
|
-
return auth.userId;
|
|
83
|
-
}
|
|
84
|
-
catch (_a) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* 获取完整用户信息(如果已认证)
|
|
91
|
-
*/
|
|
92
|
-
getUser() {
|
|
93
|
-
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
try {
|
|
95
|
-
return yield getAuthenticatedUser(this.req);
|
|
96
|
-
}
|
|
97
|
-
catch (_a) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
exports.ApiAuthUtils = ApiAuthUtils;
|
|
105
|
-
exports.getAuthenticatedUser = getAuthenticatedUser;
|
|
106
|
-
exports.requireAuth = requireAuth;
|
|
107
|
-
exports.requireAuthWithUser = requireAuthWithUser;
|
package/dist/lib/auth-utils.mjs
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from '../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs';
|
|
2
|
-
import { userService } from '../services/database/user.service.mjs';
|
|
3
|
-
import '../prisma/prisma.mjs';
|
|
4
|
-
import '../services/database/credit.service.mjs';
|
|
5
|
-
import '@prisma/client';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 从中间件设置的 Clerk ID 获取完整用户信息
|
|
9
|
-
*/
|
|
10
|
-
function getAuthenticatedUser(req) {
|
|
11
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
-
try {
|
|
13
|
-
const clerkUserId = req.headers.get('x-clerk-user-id');
|
|
14
|
-
if (!clerkUserId) {
|
|
15
|
-
throw new Error('Authentication required');
|
|
16
|
-
}
|
|
17
|
-
const user = yield userService.findByClerkUserId(clerkUserId);
|
|
18
|
-
if (!user) {
|
|
19
|
-
throw new Error('User not found in database');
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
userId: user.userId,
|
|
23
|
-
user,
|
|
24
|
-
clerkUserId
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
console.error('Error getting authenticated user:', error);
|
|
29
|
-
throw error;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* 要求用户必须已认证,返回用户ID
|
|
35
|
-
*/
|
|
36
|
-
function requireAuth(req) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const auth = yield getAuthenticatedUser(req);
|
|
39
|
-
return auth.userId;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* 要求用户必须已认证,返回完整用户信息
|
|
44
|
-
*/
|
|
45
|
-
function requireAuthWithUser(req) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
return yield getAuthenticatedUser(req);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* API Route版本的认证工具函数
|
|
52
|
-
*/
|
|
53
|
-
class ApiAuthUtils {
|
|
54
|
-
constructor(req) {
|
|
55
|
-
this.req = req;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* 要求用户必须已认证,返回用户ID
|
|
59
|
-
*/
|
|
60
|
-
requireAuth() {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
return yield requireAuth(this.req);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* 要求用户必须已认证,返回完整用户信息
|
|
67
|
-
*/
|
|
68
|
-
requireAuthWithUser() {
|
|
69
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
return yield requireAuthWithUser(this.req);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* 获取用户ID(如果已认证)
|
|
75
|
-
*/
|
|
76
|
-
getUserId() {
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
try {
|
|
79
|
-
const auth = yield getAuthenticatedUser(this.req);
|
|
80
|
-
return auth.userId;
|
|
81
|
-
}
|
|
82
|
-
catch (_a) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* 获取完整用户信息(如果已认证)
|
|
89
|
-
*/
|
|
90
|
-
getUser() {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
try {
|
|
93
|
-
return yield getAuthenticatedUser(this.req);
|
|
94
|
-
}
|
|
95
|
-
catch (_a) {
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export { ApiAuthUtils, getAuthenticatedUser, requireAuth, requireAuthWithUser };
|
package/dist/prisma/client.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/prisma/client.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC"}
|
package/dist/prisma/client.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var client = require('@prisma/client');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.keys(client).forEach(function (k) {
|
|
8
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () { return client[k]; }
|
|
11
|
-
});
|
|
12
|
-
});
|
package/dist/prisma/client.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@prisma/client';
|
package/src/prisma/client.ts
DELETED