@longzai-intelligence-auth/core 0.0.5 → 0.0.7

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/index.js ADDED
@@ -0,0 +1 @@
1
+ import{z as e}from"zod";import{DomainError as t}from"@longzai-intelligence/error";const n=e.object({secret:e.string().min(1,`JWT 密钥不能为空`),accessExpiresIn:e.string().default(`15m`),refreshExpiresIn:e.string().default(`7d`)}),r=e.object({minLength:e.number().int().positive().default(8),requireUppercase:e.boolean().default(!0),requireLowercase:e.boolean().default(!0),requireNumber:e.boolean().default(!0),requireSpecial:e.boolean().default(!1),historyCount:e.number().int().nonnegative().default(5),expireDays:e.number().int().nonnegative().default(0)}),i=e.object({windowSeconds:e.number().int().positive().default(60),maxRequests:e.number().int().positive().default(100)}),a=e.object({jwt:n,passwordPolicy:r,defaultTenantId:e.string().min(1).default(`default`)}),o=e.object({sub:e.string(),type:e.literal(`access`),tenantId:e.string().optional(),iss:e.string().optional(),aud:e.string().optional(),jti:e.string().optional(),roles:e.array(e.string()).optional(),permissions:e.array(e.string()).optional()}),s=e.object({sub:e.string(),sessionId:e.string(),type:e.literal(`refresh`)}),c=e.object({sub:e.string(),type:e.literal(`password_reset`)}),l=e.object({sub:e.string(),type:e.literal(`mfa_pending`)}),u=e.string().regex(/^[a-zA-Z0-9_-]+:[a-zA-Z0-9_-]+$/,`权限格式应为 resource:action`),d=e.object({resource:e.string().min(1),action:e.string().min(1)}),f=e.object({email:e.string().email(`邮箱格式无效`),username:e.string().min(3,`用户名至少 3 个字符`).max(50,`用户名最多 50 个字符`),password:e.string().min(8,`密码至少 8 个字符`).max(128,`密码最多 128 个字符`),displayName:e.string().optional()}),p=e.object({displayName:e.string().optional(),avatarUrl:e.string().url(`头像 URL 格式无效`).optional()}),m=e.object({currentPassword:e.string(`请输入当前密码`),newPassword:e.string().min(8,`新密码至少 8 个字符`).max(128,`新密码最多 128 个字符`)}),h=e.object({email:e.string().email(`邮箱格式无效`),password:e.string(`请输入密码`)}),g=e.object({refreshToken:e.string(`请输入刷新令牌`)}),_=`dev-secret-key`;function v(){let e=process.env.JWT_SECRET??_;return e===_&&console.warn(`[Auth] JWT_SECRET 环境变量未设置,正在使用开发密钥。请勿在生产环境中使用!`),process.env.JWT_ALGORITHM,{secret:e,accessExpiresIn:process.env.JWT_ACCESS_EXPIRES_IN??`15m`,refreshExpiresIn:process.env.JWT_REFRESH_EXPIRES_IN??`7d`}}function y(){return{windowSeconds:60,maxRequests:100}}function b(){return{minLength:8,requireUppercase:!0,requireLowercase:!0,requireNumber:!0,requireSpecial:!1,historyCount:0,expireDays:0}}var x=class extends t{constructor(e=`认证令牌已过期`){super(e,`TOKEN_EXPIRED`)}},S=class extends t{constructor(e=`无效的认证令牌`){super(e,`TOKEN_INVALID`)}},C=class extends t{constructor(e=`未认证,请先登录`){super(e,`TOKEN_MISSING`)}},w=class extends t{constructor(e=`需要多因素认证验证`){super(e,`MFA_REQUIRED`)}},T=class extends t{constructor(e=`用户名或密码错误`){super(e,`INVALID_CREDENTIALS`)}},E=class extends t{constructor(e=`账户已被禁用`){super(e,`ACCOUNT_DISABLED`)}},D=class extends t{constructor(e=`用户不存在`){super(e,`USER_NOT_FOUND`)}},O=class extends t{constructor(e=`用户已存在`){super(e,`USER_ALREADY_EXISTS`)}},k=class extends t{constructor(e=`密码不符合策略要求`){super(e,`PASSWORD_POLICY_VIOLATION`)}},A=class extends t{constructor(e=`会话不存在`){super(e,`SESSION_NOT_FOUND`)}},j=class extends t{constructor(e=`会话已过期`){super(e,`SESSION_EXPIRED`)}},M=class extends t{constructor(e=`请求过于频繁,请稍后再试`){super(e,`RATE_LIMIT_EXCEEDED`)}};export{E as AccountDisabledError,T as InvalidCredentialsError,w as MfaRequiredError,k as PasswordPolicyViolationError,M as RateLimitExceededError,j as SessionExpiredError,A as SessionNotFoundError,x as TokenExpiredError,S as TokenInvalidError,C as TokenMissingError,O as UserAlreadyExistsError,D as UserNotFoundError,o as accessTokenPayloadSchema,a as authConfigSchema,m as changePasswordSchema,v as createDefaultJwtConfig,b as createDefaultPasswordPolicy,y as createDefaultRateLimitConfig,f as createUserSchema,n as jwtConfigSchema,h as loginSchema,l as mfaPendingTokenPayloadSchema,r as passwordPolicyConfigSchema,c as passwordResetTokenPayloadSchema,u as permissionStringSchema,i as rateLimitConfigSchema,s as refreshTokenPayloadSchema,g as refreshTokenSchema,d as resourceActionSchema,p as updateUserSchema};
package/package.json CHANGED
@@ -1,22 +1,15 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-auth/core",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
- "main": "./dist/index.cjs",
8
- "module": "./dist/index.js",
7
+ "main": "./dist/index.js",
9
8
  "types": "./dist/index.d.ts",
10
9
  "exports": {
11
10
  ".": {
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
- }
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
20
13
  }
21
14
  },
22
15
  "files": [
@@ -35,8 +28,7 @@
35
28
  "zod": "^4.4.3"
36
29
  },
37
30
  "scripts": {
38
- "build": "bun build src/index.ts --outdir dist --target bun",
39
- "build:declaration": "tsgo --declaration --emitDeclarationOnly --outDir dist -p tsconfig/app.json",
31
+ "build": "tsgo --build tsconfig/build.json && resolve-aliases -p tsconfig/build.json",
40
32
  "build:prod": "NODE_ENV=production tsdown",
41
33
  "prepublishOnly": "bun run build:prod",
42
34
  "typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
@@ -50,9 +42,6 @@
50
42
  "test:coverage": "bun test --coverage",
51
43
  "test:unit": "bun test src/__tests__/unit/",
52
44
  "test:integration": "bun test src/__tests__/integration/",
53
- "clean": "rm -rf dist out .cache"
54
- },
55
- "devDependencies": {
56
- "@types/bun": "^1.3.14"
45
+ "clean": "rimraf dist out .cache"
57
46
  }
58
47
  }
package/dist/index.cjs DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("zod"),t=require("@longzai-intelligence/error");const n=e.z.object({secret:e.z.string().min(1,`JWT 密钥不能为空`),accessExpiresIn:e.z.string().default(`15m`),refreshExpiresIn:e.z.string().default(`7d`)}),r=e.z.object({minLength:e.z.number().int().positive().default(8),requireUppercase:e.z.boolean().default(!0),requireLowercase:e.z.boolean().default(!0),requireNumber:e.z.boolean().default(!0),requireSpecial:e.z.boolean().default(!1),historyCount:e.z.number().int().nonnegative().default(5),expireDays:e.z.number().int().nonnegative().default(0)}),i=e.z.object({windowSeconds:e.z.number().int().positive().default(60),maxRequests:e.z.number().int().positive().default(100)}),a=e.z.object({jwt:n,passwordPolicy:r,defaultTenantId:e.z.string().min(1).default(`default`)}),o=e.z.object({sub:e.z.string(),type:e.z.literal(`access`),tenantId:e.z.string().optional(),iss:e.z.string().optional(),aud:e.z.string().optional(),jti:e.z.string().optional(),roles:e.z.array(e.z.string()).optional(),permissions:e.z.array(e.z.string()).optional()}),s=e.z.object({sub:e.z.string(),sessionId:e.z.string(),type:e.z.literal(`refresh`)}),c=e.z.object({sub:e.z.string(),type:e.z.literal(`password_reset`)}),l=e.z.object({sub:e.z.string(),type:e.z.literal(`mfa_pending`)}),u=e.z.string().regex(/^[a-zA-Z0-9_-]+:[a-zA-Z0-9_-]+$/,`权限格式应为 resource:action`),d=e.z.object({resource:e.z.string().min(1),action:e.z.string().min(1)}),f=e.z.object({email:e.z.string().email(`邮箱格式无效`),username:e.z.string().min(3,`用户名至少 3 个字符`).max(50,`用户名最多 50 个字符`),password:e.z.string().min(8,`密码至少 8 个字符`).max(128,`密码最多 128 个字符`),displayName:e.z.string().optional()}),p=e.z.object({displayName:e.z.string().optional(),avatarUrl:e.z.string().url(`头像 URL 格式无效`).optional()}),m=e.z.object({currentPassword:e.z.string(`请输入当前密码`),newPassword:e.z.string().min(8,`新密码至少 8 个字符`).max(128,`新密码最多 128 个字符`)}),h=e.z.object({email:e.z.string().email(`邮箱格式无效`),password:e.z.string(`请输入密码`)}),g=e.z.object({refreshToken:e.z.string(`请输入刷新令牌`)});var _=class extends t.DomainError{constructor(e=`认证令牌已过期`){super(e,`TOKEN_EXPIRED`)}},v=class extends t.DomainError{constructor(e=`无效的认证令牌`){super(e,`TOKEN_INVALID`)}},y=class extends t.DomainError{constructor(e=`未认证,请先登录`){super(e,`TOKEN_MISSING`)}},b=class extends t.DomainError{constructor(e=`需要多因素认证验证`){super(e,`MFA_REQUIRED`)}},x=class extends t.DomainError{constructor(e=`用户名或密码错误`){super(e,`INVALID_CREDENTIALS`)}},S=class extends t.DomainError{constructor(e=`账户已被禁用`){super(e,`ACCOUNT_DISABLED`)}},C=class extends t.DomainError{constructor(e=`用户不存在`){super(e,`USER_NOT_FOUND`)}},w=class extends t.DomainError{constructor(e=`用户已存在`){super(e,`USER_ALREADY_EXISTS`)}},T=class extends t.DomainError{constructor(e=`密码不符合策略要求`){super(e,`PASSWORD_POLICY_VIOLATION`)}},E=class extends t.DomainError{constructor(e=`会话不存在`){super(e,`SESSION_NOT_FOUND`)}},D=class extends t.DomainError{constructor(e=`会话已过期`){super(e,`SESSION_EXPIRED`)}},O=class extends t.DomainError{constructor(e=`请求过于频繁,请稍后再试`){super(e,`RATE_LIMIT_EXCEEDED`)}};exports.AccountDisabledError=S,exports.InvalidCredentialsError=x,exports.MfaRequiredError=b,exports.PasswordPolicyViolationError=T,exports.RateLimitExceededError=O,exports.SessionExpiredError=D,exports.SessionNotFoundError=E,exports.TokenExpiredError=_,exports.TokenInvalidError=v,exports.TokenMissingError=y,exports.UserAlreadyExistsError=w,exports.UserNotFoundError=C,exports.accessTokenPayloadSchema=o,exports.authConfigSchema=a,exports.changePasswordSchema=m,exports.createUserSchema=f,exports.jwtConfigSchema=n,exports.loginSchema=h,exports.mfaPendingTokenPayloadSchema=l,exports.passwordPolicyConfigSchema=r,exports.passwordResetTokenPayloadSchema=c,exports.permissionStringSchema=u,exports.rateLimitConfigSchema=i,exports.refreshTokenPayloadSchema=s,exports.refreshTokenSchema=g,exports.resourceActionSchema=d,exports.updateUserSchema=p;
package/dist/index.d.cts DELETED
@@ -1,532 +0,0 @@
1
- import { z } from "zod";
2
- import { DomainError } from "@longzai-intelligence/error";
3
-
4
- //#region src/types/token.types.d.ts
5
- type AccessTokenPayload = {
6
- sub: string;
7
- type: "access";
8
- tenantId?: string;
9
- iss?: string;
10
- aud?: string;
11
- jti?: string;
12
- roles?: string[];
13
- permissions?: string[];
14
- };
15
- type RefreshTokenPayload = {
16
- sub: string;
17
- sessionId: string;
18
- type: "refresh";
19
- };
20
- type PasswordResetTokenPayload = {
21
- sub: string;
22
- type: "password_reset";
23
- };
24
- type MfaPendingTokenPayload = {
25
- sub: string;
26
- type: "mfa_pending";
27
- };
28
- type TokenPayload = AccessTokenPayload | RefreshTokenPayload | PasswordResetTokenPayload | MfaPendingTokenPayload;
29
- //#endregion
30
- //#region src/types/auth-context.types.d.ts
31
- type UserInfo = {
32
- userId: string;
33
- tenantId?: string;
34
- };
35
- type AuthContext = {
36
- userId: string;
37
- tenantId?: string;
38
- };
39
- //#endregion
40
- //#region src/types/permission.types.d.ts
41
- type ResourceAction = {
42
- resource: string;
43
- action: string;
44
- };
45
- type PermissionCheckFn = (userId: string, resource: string, action: string) => Promise<void>;
46
- type TenantPermissionCheckFn = (userId: string, tenantId: string, resource: string, action: string) => Promise<void>;
47
- //#endregion
48
- //#region src/types/config.types.d.ts
49
- type JwtConfig = {
50
- secret: string;
51
- accessExpiresIn: string;
52
- refreshExpiresIn: string;
53
- };
54
- type PasswordPolicyConfig = {
55
- minLength: number;
56
- requireUppercase: boolean;
57
- requireLowercase: boolean;
58
- requireNumber: boolean;
59
- requireSpecial: boolean;
60
- historyCount: number;
61
- expireDays: number;
62
- };
63
- type AuthConfig = {
64
- jwt: JwtConfig;
65
- passwordPolicy: PasswordPolicyConfig;
66
- defaultTenantId: string;
67
- };
68
- //#endregion
69
- //#region src/types/password.types.d.ts
70
- type PasswordValidationResult = {
71
- valid: boolean;
72
- errors: string[];
73
- };
74
- //#endregion
75
- //#region src/types/rate-limit.types.d.ts
76
- type RateLimitConfig = {
77
- windowSeconds: number;
78
- maxRequests: number;
79
- };
80
- //#endregion
81
- //#region src/types/logger.types.d.ts
82
- type LoggerService = {
83
- debug(message: string, context?: Record<string, unknown>): void;
84
- info(message: string, context?: Record<string, unknown>): void;
85
- warn(message: string, context?: Record<string, unknown>): void;
86
- error(message: string, context?: Record<string, unknown>): void;
87
- };
88
- //#endregion
89
- //#region src/types/auth-api.types.d.ts
90
- type LoginRequest = {
91
- email: string;
92
- password: string;
93
- };
94
- type LoginResponse = {
95
- accessToken: string;
96
- refreshToken: string;
97
- };
98
- type RegisterRequest = {
99
- email: string;
100
- password: string;
101
- name: string;
102
- };
103
- type RegisterResponse = {
104
- userId: string;
105
- message: string;
106
- };
107
- type RefreshTokenRequest = {
108
- refreshToken: string;
109
- };
110
- type RefreshTokenResponse = {
111
- accessToken: string;
112
- refreshToken: string;
113
- };
114
- type PasswordResetRequest = {
115
- email: string;
116
- };
117
- type PasswordResetConfirmRequest = {
118
- token: string;
119
- password: string;
120
- };
121
- type ChangePasswordRequest = {
122
- oldPassword: string;
123
- newPassword: string;
124
- };
125
- type MessageResponse = {
126
- message: string;
127
- };
128
- type MeResponse = {
129
- userId: string;
130
- tenantId?: string;
131
- };
132
- //#endregion
133
- //#region src/types/user.types.d.ts
134
- type UserStatus = "active" | "disabled" | "locked";
135
- type User = {
136
- id: string;
137
- email: string;
138
- username: string;
139
- passwordHash: string;
140
- displayName: string | null;
141
- avatarUrl: string | null;
142
- status: UserStatus;
143
- mfaEnabled: boolean;
144
- mfaSecret: string | null;
145
- failedLoginAttempts: number;
146
- lockedUntil: string | null;
147
- passwordChangedAt: string | null;
148
- lastLoginAt: string | null;
149
- createdAt: string;
150
- updatedAt: string;
151
- };
152
- type CreateUserInput = {
153
- email: string;
154
- username: string;
155
- passwordHash: string;
156
- displayName?: string;
157
- avatarUrl?: string;
158
- };
159
- type UpdateUserInput = {
160
- displayName?: string;
161
- avatarUrl?: string;
162
- };
163
- //#endregion
164
- //#region src/types/session.types.d.ts
165
- type Session = {
166
- id: string;
167
- userId: string;
168
- tenantId: string;
169
- refreshTokenHash: string;
170
- deviceInfo: string | null;
171
- ipAddress: string | null;
172
- userAgent: string | null;
173
- expiresAt: string;
174
- createdAt: string;
175
- };
176
- type CreateSessionInput = {
177
- userId: string;
178
- tenantId: string;
179
- refreshTokenHash: string;
180
- deviceInfo?: string;
181
- ipAddress?: string;
182
- userAgent?: string;
183
- expiresAt: string;
184
- };
185
- type SessionInfo = Session;
186
- //#endregion
187
- //#region src/types/tenant.types.d.ts
188
- type TenantStatus = "active" | "suspended";
189
- type Tenant = {
190
- id: string;
191
- name: string;
192
- slug: string;
193
- status: TenantStatus;
194
- maxUsers: number;
195
- settings: string | null;
196
- createdAt: string;
197
- updatedAt: string;
198
- };
199
- type CreateTenantInput = {
200
- name: string;
201
- slug: string;
202
- maxUsers?: number;
203
- settings?: string;
204
- };
205
- type UpdateTenantInput = {
206
- name?: string;
207
- maxUsers?: number;
208
- settings?: string;
209
- };
210
- //#endregion
211
- //#region src/types/tenant-member.types.d.ts
212
- type TenantMemberRole = "owner" | "admin" | "member";
213
- type TenantMember = {
214
- id: string;
215
- tenantId: string;
216
- userId: string;
217
- role: TenantMemberRole;
218
- joinedAt: string;
219
- };
220
- type CreateTenantMemberInput = {
221
- tenantId: string;
222
- userId: string;
223
- role?: TenantMemberRole;
224
- };
225
- //#endregion
226
- //#region src/schemas/auth-config.schema.d.ts
227
- declare const jwtConfigSchema: z.ZodObject<{
228
- secret: z.ZodString;
229
- accessExpiresIn: z.ZodDefault<z.ZodString>;
230
- refreshExpiresIn: z.ZodDefault<z.ZodString>;
231
- }, z.core.$strip>;
232
- declare const passwordPolicyConfigSchema: z.ZodObject<{
233
- minLength: z.ZodDefault<z.ZodNumber>;
234
- requireUppercase: z.ZodDefault<z.ZodBoolean>;
235
- requireLowercase: z.ZodDefault<z.ZodBoolean>;
236
- requireNumber: z.ZodDefault<z.ZodBoolean>;
237
- requireSpecial: z.ZodDefault<z.ZodBoolean>;
238
- historyCount: z.ZodDefault<z.ZodNumber>;
239
- expireDays: z.ZodDefault<z.ZodNumber>;
240
- }, z.core.$strip>;
241
- declare const rateLimitConfigSchema: z.ZodObject<{
242
- windowSeconds: z.ZodDefault<z.ZodNumber>;
243
- maxRequests: z.ZodDefault<z.ZodNumber>;
244
- }, z.core.$strip>;
245
- declare const authConfigSchema: z.ZodObject<{
246
- jwt: z.ZodObject<{
247
- secret: z.ZodString;
248
- accessExpiresIn: z.ZodDefault<z.ZodString>;
249
- refreshExpiresIn: z.ZodDefault<z.ZodString>;
250
- }, z.core.$strip>;
251
- passwordPolicy: z.ZodObject<{
252
- minLength: z.ZodDefault<z.ZodNumber>;
253
- requireUppercase: z.ZodDefault<z.ZodBoolean>;
254
- requireLowercase: z.ZodDefault<z.ZodBoolean>;
255
- requireNumber: z.ZodDefault<z.ZodBoolean>;
256
- requireSpecial: z.ZodDefault<z.ZodBoolean>;
257
- historyCount: z.ZodDefault<z.ZodNumber>;
258
- expireDays: z.ZodDefault<z.ZodNumber>;
259
- }, z.core.$strip>;
260
- defaultTenantId: z.ZodDefault<z.ZodString>;
261
- }, z.core.$strip>;
262
- //#endregion
263
- //#region src/schemas/token.schema.d.ts
264
- declare const accessTokenPayloadSchema: z.ZodObject<{
265
- sub: z.ZodString;
266
- type: z.ZodLiteral<"access">;
267
- tenantId: z.ZodOptional<z.ZodString>;
268
- iss: z.ZodOptional<z.ZodString>;
269
- aud: z.ZodOptional<z.ZodString>;
270
- jti: z.ZodOptional<z.ZodString>;
271
- roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
272
- permissions: z.ZodOptional<z.ZodArray<z.ZodString>>;
273
- }, z.core.$strip>;
274
- declare const refreshTokenPayloadSchema: z.ZodObject<{
275
- sub: z.ZodString;
276
- sessionId: z.ZodString;
277
- type: z.ZodLiteral<"refresh">;
278
- }, z.core.$strip>;
279
- declare const passwordResetTokenPayloadSchema: z.ZodObject<{
280
- sub: z.ZodString;
281
- type: z.ZodLiteral<"password_reset">;
282
- }, z.core.$strip>;
283
- declare const mfaPendingTokenPayloadSchema: z.ZodObject<{
284
- sub: z.ZodString;
285
- type: z.ZodLiteral<"mfa_pending">;
286
- }, z.core.$strip>;
287
- //#endregion
288
- //#region src/schemas/permission.schema.d.ts
289
- declare const permissionStringSchema: z.ZodString;
290
- declare const resourceActionSchema: z.ZodObject<{
291
- resource: z.ZodString;
292
- action: z.ZodString;
293
- }, z.core.$strip>;
294
- //#endregion
295
- //#region src/schemas/user.schema.d.ts
296
- declare const createUserSchema: z.ZodObject<{
297
- email: z.ZodString;
298
- username: z.ZodString;
299
- password: z.ZodString;
300
- displayName: z.ZodOptional<z.ZodString>;
301
- }, z.core.$strip>;
302
- declare const updateUserSchema: z.ZodObject<{
303
- displayName: z.ZodOptional<z.ZodString>;
304
- avatarUrl: z.ZodOptional<z.ZodString>;
305
- }, z.core.$strip>;
306
- declare const changePasswordSchema: z.ZodObject<{
307
- currentPassword: z.ZodString;
308
- newPassword: z.ZodString;
309
- }, z.core.$strip>;
310
- //#endregion
311
- //#region src/schemas/session.schema.d.ts
312
- declare const loginSchema: z.ZodObject<{
313
- email: z.ZodString;
314
- password: z.ZodString;
315
- }, z.core.$strip>;
316
- declare const refreshTokenSchema: z.ZodObject<{
317
- refreshToken: z.ZodString;
318
- }, z.core.$strip>;
319
- //#endregion
320
- //#region src/ports/auth-backend.port.d.ts
321
- type UserAuthInfo = {
322
- userId: string;
323
- email: string;
324
- tenantId: string;
325
- status: UserStatus;
326
- passwordHash: string;
327
- mfaEnabled: boolean;
328
- mfaSecret: string | null;
329
- failedLoginAttempts: number;
330
- lockedUntil: string | null;
331
- };
332
- type VerifyPasswordResult = {
333
- success: boolean;
334
- user?: User;
335
- error?: string;
336
- };
337
- type TenantValidateResult = {
338
- valid: boolean;
339
- tenant?: Tenant;
340
- error?: string;
341
- };
342
- type UserPort = {
343
- findById(userId: string): Promise<User | null>;
344
- findByEmail(email: string): Promise<User | null>;
345
- findByUsername(username: string): Promise<User | null>;
346
- findAuthInfo(userId: string): Promise<UserAuthInfo | null>;
347
- findAuthInfoByEmail(email: string): Promise<UserAuthInfo | null>;
348
- findPermissions(userId: string, tenantId: string): Promise<ResourceAction[]>;
349
- isSuperAdmin(userId: string, tenantId: string): Promise<boolean>;
350
- create(input: CreateUserInput): Promise<User>;
351
- update(userId: string, input: UpdateUserInput): Promise<User>;
352
- verifyPassword(email: string, password: string): Promise<VerifyPasswordResult>;
353
- updatePassword(userId: string, newPasswordHash: string): Promise<void>;
354
- };
355
- type SessionPort = {
356
- create(input: CreateSessionInput): Promise<Session>;
357
- findById(sessionId: string): Promise<Session | null>;
358
- findByRefreshTokenHash(hash: string): Promise<Session | null>;
359
- revoke(sessionId: string): Promise<void>;
360
- revokeAllByUser(userId: string): Promise<void>;
361
- };
362
- type TokenPort = {
363
- signAccessToken(payload: AccessTokenPayload): Promise<string>;
364
- signRefreshToken(payload: RefreshTokenPayload): Promise<string>;
365
- verifyAccessToken(token: string): Promise<AccessTokenPayload>;
366
- verifyRefreshToken(token: string): Promise<RefreshTokenPayload>;
367
- };
368
- type AuthBackendPort = {
369
- user: UserPort;
370
- session: SessionPort;
371
- token: TokenPort;
372
- };
373
- //#endregion
374
- //#region src/ports/identity.port.d.ts
375
- type TenantPort = {
376
- findById(tenantId: string): Promise<Tenant | null>;
377
- findBySlug(slug: string): Promise<Tenant | null>;
378
- create(input: CreateTenantInput): Promise<Tenant>;
379
- validateStatus(tenantId: string): Promise<TenantValidateResult>;
380
- };
381
- type TenantMemberPort = {
382
- getMember(tenantId: string, userId: string): Promise<TenantMember | null>;
383
- addMember(tenantId: string, userId: string, role: string): Promise<TenantMember>;
384
- removeMember(tenantId: string, userId: string): Promise<void>;
385
- isMember(tenantId: string, userId: string): Promise<boolean>;
386
- };
387
- type AuditLogEntry = {
388
- id: string;
389
- action: string;
390
- resource: string;
391
- resourceId?: string;
392
- userId?: string;
393
- tenantId?: string;
394
- success: boolean;
395
- metadata?: Record<string, unknown>;
396
- ipAddress?: string;
397
- userAgent?: string;
398
- createdAt: string;
399
- hashChain?: string;
400
- previousHash?: string;
401
- };
402
- type AuditLogQueryParams = {
403
- page?: number;
404
- pageSize?: number;
405
- action?: string;
406
- resource?: string;
407
- userId?: string;
408
- tenantId?: string;
409
- startDate?: string;
410
- endDate?: string;
411
- };
412
- type PaginatedResult<T> = {
413
- items: T[];
414
- pagination: {
415
- page: number;
416
- pageSize: number;
417
- total: number;
418
- totalPages: number;
419
- hasPrev: boolean;
420
- hasNext: boolean;
421
- };
422
- };
423
- type AuditStatistics = {
424
- totalEntries: number;
425
- successCount: number;
426
- failureCount: number;
427
- topActions: {
428
- action: string;
429
- count: number;
430
- }[];
431
- topResources: {
432
- resource: string;
433
- count: number;
434
- }[];
435
- };
436
- type IntegrityVerificationResult = {
437
- valid: boolean;
438
- brokenAt: string | null;
439
- totalChecked: number;
440
- };
441
- type AuditLogPort = {
442
- save(entry: AuditLogEntry): Promise<AuditLogEntry>;
443
- findById(id: string): Promise<AuditLogEntry | null>;
444
- query(params: AuditLogQueryParams): Promise<PaginatedResult<AuditLogEntry>>;
445
- getStatistics(filter: AuditStatsFilter): Promise<AuditStatistics>;
446
- deleteOlderThan(date: Date): Promise<number>;
447
- verifyIntegrity(startId?: string): Promise<IntegrityVerificationResult>;
448
- };
449
- type AuditStatsFilter = {
450
- startDate?: string;
451
- endDate?: string;
452
- tenantId?: string;
453
- };
454
- type IdentityAuthBackend = AuthBackendPort & {
455
- tenant: TenantPort;
456
- tenantMember: TenantMemberPort;
457
- audit: AuditLogPort;
458
- };
459
- type TenantValidateFn = (tenantId: string) => Promise<TenantValidateResult>;
460
- //#endregion
461
- //#region src/ports/password-hash.port.d.ts
462
- type PasswordHasher = {
463
- hash(password: string): Promise<string>;
464
- verify(password: string, hash: string): Promise<boolean>;
465
- };
466
- //#endregion
467
- //#region src/ports/strategy.port.d.ts
468
- type TokenVerifyResult<T> = {
469
- success: boolean;
470
- payload?: T;
471
- error?: string;
472
- };
473
- type TokenSigner = {
474
- signAccessToken(payload: AccessTokenPayload): Promise<string>;
475
- signRefreshToken(payload: RefreshTokenPayload): Promise<string>;
476
- };
477
- type TokenVerifier = {
478
- verifyAccessToken(token: string): Promise<TokenVerifyResult<AccessTokenPayload>>;
479
- verifyRefreshToken(token: string): Promise<TokenVerifyResult<RefreshTokenPayload>>;
480
- };
481
- type AuthStrategy = {
482
- name: string;
483
- verify(credentials: unknown): Promise<AccessTokenPayload>;
484
- };
485
- type RateLimiter = {
486
- check(key: string): Promise<{
487
- allowed: boolean;
488
- remaining: number;
489
- resetAt: Date;
490
- }>;
491
- reset(key: string): Promise<void>;
492
- };
493
- //#endregion
494
- //#region src/errors/auth.errors.d.ts
495
- declare class TokenExpiredError extends DomainError {
496
- constructor(message?: string);
497
- }
498
- declare class TokenInvalidError extends DomainError {
499
- constructor(message?: string);
500
- }
501
- declare class TokenMissingError extends DomainError {
502
- constructor(message?: string);
503
- }
504
- declare class MfaRequiredError extends DomainError {
505
- constructor(message?: string);
506
- }
507
- declare class InvalidCredentialsError extends DomainError {
508
- constructor(message?: string);
509
- }
510
- declare class AccountDisabledError extends DomainError {
511
- constructor(message?: string);
512
- }
513
- declare class UserNotFoundError extends DomainError {
514
- constructor(message?: string);
515
- }
516
- declare class UserAlreadyExistsError extends DomainError {
517
- constructor(message?: string);
518
- }
519
- declare class PasswordPolicyViolationError extends DomainError {
520
- constructor(message?: string);
521
- }
522
- declare class SessionNotFoundError extends DomainError {
523
- constructor(message?: string);
524
- }
525
- declare class SessionExpiredError extends DomainError {
526
- constructor(message?: string);
527
- }
528
- declare class RateLimitExceededError extends DomainError {
529
- constructor(message?: string);
530
- }
531
- //#endregion
532
- export { type AccessTokenPayload, AccountDisabledError, type AuditLogEntry, type AuditLogPort, type AuditLogQueryParams, type AuditStatistics, type AuditStatsFilter, type AuthBackendPort, type AuthConfig, type AuthContext, type AuthStrategy, type ChangePasswordRequest, type CreateSessionInput, type CreateTenantInput, type CreateTenantMemberInput, type CreateUserInput, type IdentityAuthBackend, type IntegrityVerificationResult, InvalidCredentialsError, type JwtConfig, type LoggerService, type LoginRequest, type LoginResponse, type MeResponse, type MessageResponse, type MfaPendingTokenPayload, MfaRequiredError, type PaginatedResult, type PasswordHasher, type PasswordPolicyConfig, PasswordPolicyViolationError, type PasswordResetConfirmRequest, type PasswordResetRequest, type PasswordResetTokenPayload, type PasswordValidationResult, type PermissionCheckFn, type RateLimitConfig, RateLimitExceededError, type RateLimiter, type RefreshTokenPayload, type RefreshTokenRequest, type RefreshTokenResponse, type RegisterRequest, type RegisterResponse, type ResourceAction, type Session, SessionExpiredError, type SessionInfo, SessionNotFoundError, type SessionPort, type Tenant, type TenantMember, type TenantMemberPort, type TenantMemberRole, type TenantPermissionCheckFn, type TenantPort, type TenantStatus, type TenantValidateFn, type TenantValidateResult, TokenExpiredError, TokenInvalidError, TokenMissingError, type TokenPayload, type TokenPort, type TokenSigner, type TokenVerifier, type TokenVerifyResult, type UpdateTenantInput, type UpdateUserInput, type User, UserAlreadyExistsError, type UserAuthInfo, type UserInfo, UserNotFoundError, type UserPort, type UserStatus, type VerifyPasswordResult, accessTokenPayloadSchema, authConfigSchema, changePasswordSchema, createUserSchema, jwtConfigSchema, loginSchema, mfaPendingTokenPayloadSchema, passwordPolicyConfigSchema, passwordResetTokenPayloadSchema, permissionStringSchema, rateLimitConfigSchema, refreshTokenPayloadSchema, refreshTokenSchema, resourceActionSchema, updateUserSchema };