@longzai-intelligence-auth/express 0.0.2
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/core/error-mapper.d.ts +2 -0
- package/dist/core/error-mapper.js +27 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +12 -0
- package/dist/middlewares/audit.middleware.d.ts +4 -0
- package/dist/middlewares/audit.middleware.js +12 -0
- package/dist/middlewares/error-handler.middleware.d.ts +4 -0
- package/dist/middlewares/error-handler.middleware.js +23 -0
- package/dist/middlewares/jwt-verify.middleware.d.ts +4 -0
- package/dist/middlewares/jwt-verify.middleware.js +36 -0
- package/dist/middlewares/logger.middleware.d.ts +4 -0
- package/dist/middlewares/logger.middleware.js +17 -0
- package/dist/middlewares/rate-limit.middleware.d.ts +4 -0
- package/dist/middlewares/rate-limit.middleware.js +42 -0
- package/dist/middlewares/rbac.middleware.d.ts +4 -0
- package/dist/middlewares/rbac.middleware.js +49 -0
- package/dist/middlewares/tenant.middleware.d.ts +4 -0
- package/dist/middlewares/tenant.middleware.js +22 -0
- package/dist/presets/basic-preset.d.ts +4 -0
- package/dist/presets/basic-preset.js +11 -0
- package/dist/presets/standard-preset.d.ts +4 -0
- package/dist/presets/standard-preset.js +27 -0
- package/dist/types/express-auth.types.d.ts +47 -0
- package/dist/types/express-auth.types.js +1 -0
- package/dist/utils/extract-client-ip.d.ts +2 -0
- package/dist/utils/extract-client-ip.js +6 -0
- package/dist/utils/extract-user-agent.d.ts +2 -0
- package/dist/utils/extract-user-agent.js +3 -0
- package/package.json +65 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AuthenticationError, DuplicateEntityError, isValidationError, isEntityNotFoundError, isPermissionDeniedError, isBusinessRuleError, isConcurrencyError, } from "@longzai-intelligence/error";
|
|
2
|
+
import { TokenExpiredError, TokenInvalidError, TokenMissingError, MfaRequiredError, InvalidCredentialsError, AccountDisabledError, RateLimitExceededError, } from "@longzai-intelligence-auth/core";
|
|
3
|
+
export function mapDomainErrorToStatus(error) {
|
|
4
|
+
if (isValidationError(error))
|
|
5
|
+
return 400;
|
|
6
|
+
if (error instanceof TokenExpiredError ||
|
|
7
|
+
error instanceof TokenInvalidError ||
|
|
8
|
+
error instanceof TokenMissingError ||
|
|
9
|
+
error instanceof MfaRequiredError ||
|
|
10
|
+
error instanceof InvalidCredentialsError ||
|
|
11
|
+
error instanceof AccountDisabledError ||
|
|
12
|
+
error instanceof AuthenticationError)
|
|
13
|
+
return 401;
|
|
14
|
+
if (isPermissionDeniedError(error))
|
|
15
|
+
return 403;
|
|
16
|
+
if (isEntityNotFoundError(error))
|
|
17
|
+
return 404;
|
|
18
|
+
if (error instanceof DuplicateEntityError)
|
|
19
|
+
return 409;
|
|
20
|
+
if (error instanceof RateLimitExceededError)
|
|
21
|
+
return 429;
|
|
22
|
+
if (isConcurrencyError(error))
|
|
23
|
+
return 409;
|
|
24
|
+
if (isBusinessRuleError(error))
|
|
25
|
+
return 422;
|
|
26
|
+
return 500;
|
|
27
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { mapDomainErrorToStatus } from "./core/error-mapper";
|
|
2
|
+
export { createJwtVerifyMiddleware } from "./middlewares/jwt-verify.middleware";
|
|
3
|
+
export type { JwtVerifyMiddlewareOptions } from "./middlewares/jwt-verify.middleware";
|
|
4
|
+
export { createRbacMiddleware } from "./middlewares/rbac.middleware";
|
|
5
|
+
export type { RbacMiddlewareOptions } from "./middlewares/rbac.middleware";
|
|
6
|
+
export { createTenantMiddleware } from "./middlewares/tenant.middleware";
|
|
7
|
+
export type { TenantMiddlewareOptions } from "./middlewares/tenant.middleware";
|
|
8
|
+
export { createRateLimitMiddleware } from "./middlewares/rate-limit.middleware";
|
|
9
|
+
export type { RateLimitMiddlewareOptions } from "./middlewares/rate-limit.middleware";
|
|
10
|
+
export { createAuditMiddleware } from "./middlewares/audit.middleware";
|
|
11
|
+
export type { AuditMiddlewareOptions } from "./middlewares/audit.middleware";
|
|
12
|
+
export { createLoggerMiddleware } from "./middlewares/logger.middleware";
|
|
13
|
+
export type { LoggerMiddlewareOptions } from "./middlewares/logger.middleware";
|
|
14
|
+
export { createErrorHandlerMiddleware } from "./middlewares/error-handler.middleware";
|
|
15
|
+
export type { ErrorHandlerMiddlewareOptions } from "./middlewares/error-handler.middleware";
|
|
16
|
+
export { createBasicPreset } from "./presets/basic-preset";
|
|
17
|
+
export type { BasicPresetOptions } from "./presets/basic-preset";
|
|
18
|
+
export { createStandardPreset } from "./presets/standard-preset";
|
|
19
|
+
export type { StandardPresetOptions } from "./presets/standard-preset";
|
|
20
|
+
export { extractClientIp } from "./utils/extract-client-ip";
|
|
21
|
+
export { extractUserAgent } from "./utils/extract-user-agent";
|
|
22
|
+
export type { AuthRequest } from "./types/express-auth.types";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { mapDomainErrorToStatus } from "./core/error-mapper";
|
|
2
|
+
export { createJwtVerifyMiddleware } from "./middlewares/jwt-verify.middleware";
|
|
3
|
+
export { createRbacMiddleware } from "./middlewares/rbac.middleware";
|
|
4
|
+
export { createTenantMiddleware } from "./middlewares/tenant.middleware";
|
|
5
|
+
export { createRateLimitMiddleware } from "./middlewares/rate-limit.middleware";
|
|
6
|
+
export { createAuditMiddleware } from "./middlewares/audit.middleware";
|
|
7
|
+
export { createLoggerMiddleware } from "./middlewares/logger.middleware";
|
|
8
|
+
export { createErrorHandlerMiddleware } from "./middlewares/error-handler.middleware";
|
|
9
|
+
export { createBasicPreset } from "./presets/basic-preset";
|
|
10
|
+
export { createStandardPreset } from "./presets/standard-preset";
|
|
11
|
+
export { extractClientIp } from "./utils/extract-client-ip";
|
|
12
|
+
export { extractUserAgent } from "./utils/extract-user-agent";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Request, Response, NextFunction } from "express";
|
|
2
|
+
import type { AuditMiddlewareOptions } from "../types/express-auth.types";
|
|
3
|
+
export type { AuditMiddlewareOptions };
|
|
4
|
+
export declare function createAuditMiddleware(options: AuditMiddlewareOptions): (_req: Request, _res: Response, next: NextFunction) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function createAuditMiddleware(options) {
|
|
2
|
+
const { adapter } = options;
|
|
3
|
+
return (_req, _res, next) => {
|
|
4
|
+
const authReq = _req;
|
|
5
|
+
authReq.recordAudit = (entry) => {
|
|
6
|
+
adapter.audit.save(entry).catch((error) => {
|
|
7
|
+
console.error("审计日志写入失败:", error);
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
next();
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Request, Response, NextFunction } from "express";
|
|
2
|
+
import type { ErrorHandlerMiddlewareOptions } from "../types/express-auth.types";
|
|
3
|
+
export type { ErrorHandlerMiddlewareOptions };
|
|
4
|
+
export declare function createErrorHandlerMiddleware(options?: ErrorHandlerMiddlewareOptions): (error: Error, req: Request, res: Response, _next: NextFunction) => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DomainError } from "@longzai-intelligence/error";
|
|
2
|
+
import { mapDomainErrorToStatus } from "../core/error-mapper";
|
|
3
|
+
export function createErrorHandlerMiddleware(options = {}) {
|
|
4
|
+
const { logger } = options;
|
|
5
|
+
return (error, req, res, _next) => {
|
|
6
|
+
if (error instanceof DomainError) {
|
|
7
|
+
const status = mapDomainErrorToStatus(error);
|
|
8
|
+
res.status(status).json({
|
|
9
|
+
code: error.code,
|
|
10
|
+
message: error.message,
|
|
11
|
+
...(error.context && Object.keys(error.context).length > 0
|
|
12
|
+
? { details: error.context }
|
|
13
|
+
: {}),
|
|
14
|
+
});
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
logger?.error("未预期的错误", {
|
|
18
|
+
error: error instanceof Error ? error.message : String(error),
|
|
19
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
20
|
+
});
|
|
21
|
+
res.status(500).json({ code: "INTERNAL_ERROR", message: "服务器内部错误" });
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Request, Response, NextFunction } from "express";
|
|
2
|
+
import type { JwtVerifyMiddlewareOptions } from "../types/express-auth.types";
|
|
3
|
+
export type { JwtVerifyMiddlewareOptions };
|
|
4
|
+
export declare function createJwtVerifyMiddleware(options: JwtVerifyMiddlewareOptions): (req: Request, _res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createJwtVerifier } from "@longzai-intelligence-auth/jwt";
|
|
2
|
+
import { TokenMissingError, TokenInvalidError } from "@longzai-intelligence-auth/core";
|
|
3
|
+
export function createJwtVerifyMiddleware(options) {
|
|
4
|
+
const { jwt: jwtConfig, defaultTenantId = "default" } = options;
|
|
5
|
+
let verifierPromise = null;
|
|
6
|
+
const getVerifier = () => {
|
|
7
|
+
if (!verifierPromise) {
|
|
8
|
+
verifierPromise = createJwtVerifier(jwtConfig);
|
|
9
|
+
}
|
|
10
|
+
return verifierPromise;
|
|
11
|
+
};
|
|
12
|
+
return async (req, _res, next) => {
|
|
13
|
+
try {
|
|
14
|
+
const authReq = req;
|
|
15
|
+
const authHeader = req.headers["authorization"];
|
|
16
|
+
const bearer = typeof authHeader === "string" && authHeader.startsWith("Bearer ")
|
|
17
|
+
? authHeader.slice(7)
|
|
18
|
+
: null;
|
|
19
|
+
if (!bearer) {
|
|
20
|
+
throw new TokenMissingError();
|
|
21
|
+
}
|
|
22
|
+
const verifier = await getVerifier();
|
|
23
|
+
const result = await verifier.verifyAccessToken(bearer);
|
|
24
|
+
if (!result.success || !result.payload) {
|
|
25
|
+
throw new TokenInvalidError(result.error);
|
|
26
|
+
}
|
|
27
|
+
const payload = result.payload;
|
|
28
|
+
authReq.auth = payload;
|
|
29
|
+
authReq.tenantId = payload.tenantId ?? defaultTenantId;
|
|
30
|
+
next();
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
next(error);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Request, Response, NextFunction } from "express";
|
|
2
|
+
import type { LoggerMiddlewareOptions } from "../types/express-auth.types";
|
|
3
|
+
export type { LoggerMiddlewareOptions };
|
|
4
|
+
export declare function createLoggerMiddleware(options: LoggerMiddlewareOptions): (req: Request, res: Response, next: NextFunction) => void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function createLoggerMiddleware(options) {
|
|
2
|
+
const { logger } = options;
|
|
3
|
+
return (req, res, next) => {
|
|
4
|
+
const startTime = Date.now();
|
|
5
|
+
logger.info(`${req.method} ${req.originalUrl}`);
|
|
6
|
+
res.on("finish", () => {
|
|
7
|
+
const duration = Date.now() - startTime;
|
|
8
|
+
logger.info(`${req.method} ${req.originalUrl} ${res.statusCode} ${duration}ms`);
|
|
9
|
+
});
|
|
10
|
+
res.on("error", (error) => {
|
|
11
|
+
logger.error(`${req.method} ${req.originalUrl} 请求错误`, {
|
|
12
|
+
error: error instanceof Error ? error.message : String(error),
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
next();
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Request, Response, NextFunction } from "express";
|
|
2
|
+
import type { RateLimitMiddlewareOptions } from "../types/express-auth.types";
|
|
3
|
+
export type { RateLimitMiddlewareOptions };
|
|
4
|
+
export declare function createRateLimitMiddleware(options?: RateLimitMiddlewareOptions): (req: Request, _res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createMemoryRateLimiter } from "@longzai-intelligence-auth/rate-limit";
|
|
2
|
+
import { RateLimitExceededError } from "@longzai-intelligence-auth/core";
|
|
3
|
+
function defaultKeyGenerator(req) {
|
|
4
|
+
return req.headers["x-forwarded-for"]?.split(",")[0]?.trim()
|
|
5
|
+
?? req.headers["x-real-ip"]
|
|
6
|
+
?? req.ip
|
|
7
|
+
?? "unknown";
|
|
8
|
+
}
|
|
9
|
+
export function createRateLimitMiddleware(options = { windowSeconds: 60, maxRequests: 100 }) {
|
|
10
|
+
const { logger } = options;
|
|
11
|
+
const keyGen = options.keyGenerator ?? defaultKeyGenerator;
|
|
12
|
+
const limiter = createMemoryRateLimiter({
|
|
13
|
+
windowSeconds: options.windowSeconds,
|
|
14
|
+
maxRequests: options.maxRequests,
|
|
15
|
+
});
|
|
16
|
+
const timer = setInterval(() => {
|
|
17
|
+
limiter.cleanup();
|
|
18
|
+
}, 60_000);
|
|
19
|
+
if (typeof process !== "undefined" && typeof process.on === "function") {
|
|
20
|
+
process.on("exit", () => clearInterval(timer));
|
|
21
|
+
}
|
|
22
|
+
return async (req, _res, next) => {
|
|
23
|
+
try {
|
|
24
|
+
const authReq = req;
|
|
25
|
+
const clientIp = keyGen(req);
|
|
26
|
+
authReq.clientIp = clientIp;
|
|
27
|
+
const path = req.path;
|
|
28
|
+
const key = `${clientIp}:${path}`;
|
|
29
|
+
const allowed = await limiter.check(key);
|
|
30
|
+
if (!allowed) {
|
|
31
|
+
logger?.warn("限流触发", { clientIp, path });
|
|
32
|
+
throw new RateLimitExceededError();
|
|
33
|
+
}
|
|
34
|
+
const remaining = options.maxRequests - limiter.getCount(key);
|
|
35
|
+
authReq.rateLimitRemaining = remaining;
|
|
36
|
+
next();
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
next(error);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Request, Response, NextFunction } from "express";
|
|
2
|
+
import type { RbacMiddlewareOptions } from "../types/express-auth.types";
|
|
3
|
+
export type { RbacMiddlewareOptions };
|
|
4
|
+
export declare function createRbacMiddleware(options: RbacMiddlewareOptions): (permission: string) => (req: Request, _res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createRoleChecker } from "@longzai-intelligence-auth/rbac";
|
|
2
|
+
import { createJwtVerifier } from "@longzai-intelligence-auth/jwt";
|
|
3
|
+
import { TokenMissingError, TokenInvalidError } from "@longzai-intelligence-auth/core";
|
|
4
|
+
export function createRbacMiddleware(options) {
|
|
5
|
+
const { jwt: jwtConfig, defaultTenantId = "default" } = options;
|
|
6
|
+
const roleChecker = createRoleChecker();
|
|
7
|
+
let verifierPromise = null;
|
|
8
|
+
const getVerifier = () => {
|
|
9
|
+
if (!verifierPromise) {
|
|
10
|
+
verifierPromise = createJwtVerifier(jwtConfig);
|
|
11
|
+
}
|
|
12
|
+
return verifierPromise;
|
|
13
|
+
};
|
|
14
|
+
return (permission) => {
|
|
15
|
+
return async (req, _res, next) => {
|
|
16
|
+
try {
|
|
17
|
+
const authReq = req;
|
|
18
|
+
const authHeader = req.headers["authorization"];
|
|
19
|
+
const bearer = typeof authHeader === "string" && authHeader.startsWith("Bearer ")
|
|
20
|
+
? authHeader.slice(7)
|
|
21
|
+
: null;
|
|
22
|
+
if (!bearer) {
|
|
23
|
+
throw new TokenMissingError();
|
|
24
|
+
}
|
|
25
|
+
const verifier = await getVerifier();
|
|
26
|
+
const result = await verifier.verifyAccessToken(bearer);
|
|
27
|
+
if (!result.success || !result.payload) {
|
|
28
|
+
throw new TokenInvalidError(result.error);
|
|
29
|
+
}
|
|
30
|
+
const payload = result.payload;
|
|
31
|
+
authReq.auth = payload;
|
|
32
|
+
authReq.tenantId = payload.tenantId ?? defaultTenantId;
|
|
33
|
+
const [resource, action] = permission.split(":");
|
|
34
|
+
if (!resource || !action) {
|
|
35
|
+
throw new Error(`无效的权限格式: ${permission},应为 resource:action`);
|
|
36
|
+
}
|
|
37
|
+
const hasPermission = roleChecker.hasPermission(payload, resource, action);
|
|
38
|
+
if (!hasPermission) {
|
|
39
|
+
const { PermissionDeniedError } = await import("@longzai-intelligence/error");
|
|
40
|
+
throw new PermissionDeniedError(resource, action);
|
|
41
|
+
}
|
|
42
|
+
next();
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
next(error);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Request, Response, NextFunction } from "express";
|
|
2
|
+
import type { TenantMiddlewareOptions } from "../types/express-auth.types";
|
|
3
|
+
export type { TenantMiddlewareOptions };
|
|
4
|
+
export declare function createTenantMiddleware(options?: TenantMiddlewareOptions): (req: Request, _res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function createTenantMiddleware(options = {}) {
|
|
2
|
+
const { defaultTenantId = "default", adapter } = options;
|
|
3
|
+
return async (req, _res, next) => {
|
|
4
|
+
try {
|
|
5
|
+
const authReq = req;
|
|
6
|
+
const headerTenantId = req.headers["x-tenant-id"];
|
|
7
|
+
const tenantId = headerTenantId ?? defaultTenantId;
|
|
8
|
+
authReq.tenantId = tenantId;
|
|
9
|
+
if (adapter && tenantId !== defaultTenantId) {
|
|
10
|
+
const result = await adapter.tenant.validateStatus(tenantId);
|
|
11
|
+
if (!result.valid) {
|
|
12
|
+
const { PermissionDeniedError } = await import("@longzai-intelligence/error");
|
|
13
|
+
throw new PermissionDeniedError("tenant", "access");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
next();
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
next(error);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createJwtVerifyMiddleware } from "../middlewares/jwt-verify.middleware";
|
|
2
|
+
import { createErrorHandlerMiddleware } from "../middlewares/error-handler.middleware";
|
|
3
|
+
export function createBasicPreset(options) {
|
|
4
|
+
return [
|
|
5
|
+
createJwtVerifyMiddleware({
|
|
6
|
+
jwt: options.jwt,
|
|
7
|
+
defaultTenantId: options.defaultTenantId,
|
|
8
|
+
}),
|
|
9
|
+
createErrorHandlerMiddleware({ logger: options.logger }),
|
|
10
|
+
];
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createJwtVerifyMiddleware } from "../middlewares/jwt-verify.middleware";
|
|
2
|
+
import { createRbacMiddleware } from "../middlewares/rbac.middleware";
|
|
3
|
+
import { createTenantMiddleware } from "../middlewares/tenant.middleware";
|
|
4
|
+
import { createRateLimitMiddleware } from "../middlewares/rate-limit.middleware";
|
|
5
|
+
import { createErrorHandlerMiddleware } from "../middlewares/error-handler.middleware";
|
|
6
|
+
export function createStandardPreset(options) {
|
|
7
|
+
const rbacMiddleware = createRbacMiddleware({
|
|
8
|
+
jwt: options.jwt,
|
|
9
|
+
defaultTenantId: options.defaultTenantId,
|
|
10
|
+
});
|
|
11
|
+
return [
|
|
12
|
+
createJwtVerifyMiddleware({
|
|
13
|
+
jwt: options.jwt,
|
|
14
|
+
defaultTenantId: options.defaultTenantId,
|
|
15
|
+
}),
|
|
16
|
+
rbacMiddleware("*:*"),
|
|
17
|
+
createTenantMiddleware({
|
|
18
|
+
defaultTenantId: options.defaultTenantId,
|
|
19
|
+
adapter: options.adapter,
|
|
20
|
+
}),
|
|
21
|
+
createRateLimitMiddleware({
|
|
22
|
+
windowSeconds: 60,
|
|
23
|
+
maxRequests: 100,
|
|
24
|
+
}),
|
|
25
|
+
createErrorHandlerMiddleware({ logger: options.logger }),
|
|
26
|
+
];
|
|
27
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Request } from "express";
|
|
2
|
+
import type { JwtSignerConfig } from "@longzai-intelligence-auth/jwt";
|
|
3
|
+
import type { IdentityAuthBackend, RateLimitConfig, LoggerService, AuditLogEntry } from "@longzai-intelligence-auth/core";
|
|
4
|
+
import type { AccessTokenPayload } from "@longzai-intelligence-auth/core";
|
|
5
|
+
export interface AuthRequest extends Request {
|
|
6
|
+
auth: AccessTokenPayload;
|
|
7
|
+
tenantId: string;
|
|
8
|
+
clientIp?: string;
|
|
9
|
+
rateLimitRemaining?: number;
|
|
10
|
+
recordAudit?: (entry: Omit<AuditLogEntry, never>) => void;
|
|
11
|
+
}
|
|
12
|
+
export type JwtVerifyMiddlewareOptions = {
|
|
13
|
+
jwt: JwtSignerConfig;
|
|
14
|
+
defaultTenantId?: string;
|
|
15
|
+
};
|
|
16
|
+
export type RbacMiddlewareOptions = {
|
|
17
|
+
jwt: JwtSignerConfig;
|
|
18
|
+
defaultTenantId?: string;
|
|
19
|
+
};
|
|
20
|
+
export type TenantMiddlewareOptions = {
|
|
21
|
+
defaultTenantId?: string;
|
|
22
|
+
adapter?: IdentityAuthBackend;
|
|
23
|
+
};
|
|
24
|
+
export type RateLimitMiddlewareOptions = RateLimitConfig & {
|
|
25
|
+
logger?: LoggerService;
|
|
26
|
+
keyGenerator?: (req: Request) => string;
|
|
27
|
+
};
|
|
28
|
+
export type AuditMiddlewareOptions = {
|
|
29
|
+
adapter: IdentityAuthBackend;
|
|
30
|
+
};
|
|
31
|
+
export type LoggerMiddlewareOptions = {
|
|
32
|
+
logger: LoggerService;
|
|
33
|
+
};
|
|
34
|
+
export type ErrorHandlerMiddlewareOptions = {
|
|
35
|
+
logger?: LoggerService;
|
|
36
|
+
};
|
|
37
|
+
export type BasicPresetOptions = {
|
|
38
|
+
jwt: JwtSignerConfig;
|
|
39
|
+
defaultTenantId?: string;
|
|
40
|
+
logger?: LoggerService;
|
|
41
|
+
};
|
|
42
|
+
export type StandardPresetOptions = {
|
|
43
|
+
jwt: JwtSignerConfig;
|
|
44
|
+
defaultTenantId?: string;
|
|
45
|
+
adapter: IdentityAuthBackend;
|
|
46
|
+
logger?: LoggerService;
|
|
47
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longzai-intelligence-auth/express",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"license": "UNLICENSED",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/index.d.cts",
|
|
18
|
+
"default": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/longzai/longzai-intelligence-auth",
|
|
31
|
+
"directory": "packages/express"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@longzai-intelligence-auth/core": "0.0.2",
|
|
35
|
+
"@longzai-intelligence-auth/jwt": "0.0.2",
|
|
36
|
+
"@longzai-intelligence-auth/rate-limit": "0.0.2",
|
|
37
|
+
"@longzai-intelligence-auth/rbac": "0.0.2",
|
|
38
|
+
"@longzai-intelligence-auth/session": "0.0.2",
|
|
39
|
+
"@longzai-intelligence-auth/hashing": "0.0.2",
|
|
40
|
+
"@longzai-intelligence/error": "^0.0.5"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"express": "^4.18 || ^5"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"express": "^4.21",
|
|
47
|
+
"@types/express": "^5"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "bun build src/index.ts --outdir dist --target bun",
|
|
51
|
+
"build:declaration": "tsgo --declaration --emitDeclarationOnly --outDir dist -p tsconfig/app.json",
|
|
52
|
+
"build:prod": "NODE_ENV=production tsdown",
|
|
53
|
+
"prepublishOnly": "bun run build:prod",
|
|
54
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
55
|
+
"typecheck:app": "tsgo --noEmit -p tsconfig/app.json",
|
|
56
|
+
"typecheck:node": "tsgo --noEmit -p tsconfig/node.json",
|
|
57
|
+
"typecheck:test": "tsgo --noEmit -p tsconfig/test.json",
|
|
58
|
+
"lint": "oxlint && oxfmt --check",
|
|
59
|
+
"lint:fix": "oxlint --fix && oxfmt",
|
|
60
|
+
"test": "bun test",
|
|
61
|
+
"test:watch": "bun test --watch",
|
|
62
|
+
"test:coverage": "bun test --coverage",
|
|
63
|
+
"clean": "rm -rf dist out .cache"
|
|
64
|
+
}
|
|
65
|
+
}
|