@longzai-intelligence-auth/core 0.0.1 → 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/index.d.ts CHANGED
@@ -15,7 +15,8 @@ export { accessTokenPayloadSchema, refreshTokenPayloadSchema, passwordResetToken
15
15
  export { permissionStringSchema, resourceActionSchema, } from "./schemas/permission.schema";
16
16
  export { createUserSchema, updateUserSchema, changePasswordSchema, } from "./schemas/user.schema";
17
17
  export { loginSchema, refreshTokenSchema, } from "./schemas/session.schema";
18
- export type { AuthBackendPort, LocalAuthBackend, IdentityAuthBackend, UserPort, SessionPort, TokenPort, TenantPort, TenantMemberPort, UserAuthInfo, VerifyPasswordResult, TenantValidateResult, UserRolePort, UserAuthPort, TenantValidateFn, } from "./ports/auth-backend.port";
18
+ export type { AuthBackendPort, UserPort, SessionPort, TokenPort, UserAuthInfo, VerifyPasswordResult, TenantValidateResult, } from "./ports/auth-backend.port";
19
+ export type { IdentityAuthBackend, TenantPort, TenantMemberPort, AuditLogPort, AuditLogEntry, AuditLogQueryParams, PaginatedResult, AuditStatistics, AuditStatsFilter, IntegrityVerificationResult, TenantValidateFn, } from "./ports/identity.port";
19
20
  export type { PasswordHasher } from "./ports/password-hash.port";
20
21
  export type { AuthStrategy, TokenSigner, TokenVerifier, TokenVerifyResult, RateLimiter, } from "./ports/strategy.port";
21
22
  export { TokenExpiredError, TokenInvalidError, TokenMissingError, MfaRequiredError, InvalidCredentialsError, AccountDisabledError, UserNotFoundError, UserAlreadyExistsError, PasswordPolicyViolationError, SessionNotFoundError, SessionExpiredError, RateLimitExceededError, } from "./errors/auth.errors";
@@ -1,4 +1,4 @@
1
- import type { User, CreateUserInput, UpdateUserInput, UserStatus, Session, CreateSessionInput, Tenant, CreateTenantInput, TenantMember, AccessTokenPayload, RefreshTokenPayload, ResourceAction } from "../types";
1
+ import type { User, CreateUserInput, UpdateUserInput, UserStatus, Session, CreateSessionInput, Tenant, AccessTokenPayload, RefreshTokenPayload, ResourceAction } from "../types";
2
2
  export type UserAuthInfo = {
3
3
  userId: string;
4
4
  email: string;
@@ -46,28 +46,8 @@ export type TokenPort = {
46
46
  verifyAccessToken(token: string): Promise<AccessTokenPayload>;
47
47
  verifyRefreshToken(token: string): Promise<RefreshTokenPayload>;
48
48
  };
49
- export type TenantPort = {
50
- findById(tenantId: string): Promise<Tenant | null>;
51
- findBySlug(slug: string): Promise<Tenant | null>;
52
- create(input: CreateTenantInput): Promise<Tenant>;
53
- validateStatus(tenantId: string): Promise<TenantValidateResult>;
54
- };
55
- export type TenantMemberPort = {
56
- getMember(tenantId: string, userId: string): Promise<TenantMember | null>;
57
- addMember(tenantId: string, userId: string, role: string): Promise<TenantMember>;
58
- removeMember(tenantId: string, userId: string): Promise<void>;
59
- isMember(tenantId: string, userId: string): Promise<boolean>;
60
- };
61
- export type LocalAuthBackend = {
49
+ export type AuthBackendPort = {
62
50
  user: UserPort;
63
51
  session: SessionPort;
64
52
  token: TokenPort;
65
53
  };
66
- export type IdentityAuthBackend = LocalAuthBackend & {
67
- tenant: TenantPort;
68
- tenantMember: TenantMemberPort;
69
- };
70
- export type AuthBackendPort = IdentityAuthBackend;
71
- export type UserRolePort = UserPort;
72
- export type UserAuthPort = UserPort;
73
- export type TenantValidateFn = (tenantId: string) => Promise<TenantValidateResult>;
@@ -0,0 +1,87 @@
1
+ import type { Tenant, CreateTenantInput, TenantMember } from "../types";
2
+ import type { AuthBackendPort, TenantValidateResult } from "./auth-backend.port";
3
+ export type TenantPort = {
4
+ findById(tenantId: string): Promise<Tenant | null>;
5
+ findBySlug(slug: string): Promise<Tenant | null>;
6
+ create(input: CreateTenantInput): Promise<Tenant>;
7
+ validateStatus(tenantId: string): Promise<TenantValidateResult>;
8
+ };
9
+ export type TenantMemberPort = {
10
+ getMember(tenantId: string, userId: string): Promise<TenantMember | null>;
11
+ addMember(tenantId: string, userId: string, role: string): Promise<TenantMember>;
12
+ removeMember(tenantId: string, userId: string): Promise<void>;
13
+ isMember(tenantId: string, userId: string): Promise<boolean>;
14
+ };
15
+ export type AuditLogEntry = {
16
+ id: string;
17
+ action: string;
18
+ resource: string;
19
+ resourceId?: string;
20
+ userId?: string;
21
+ tenantId?: string;
22
+ success: boolean;
23
+ metadata?: Record<string, unknown>;
24
+ ipAddress?: string;
25
+ userAgent?: string;
26
+ createdAt: string;
27
+ hashChain?: string;
28
+ previousHash?: string;
29
+ };
30
+ export type AuditLogQueryParams = {
31
+ page?: number;
32
+ pageSize?: number;
33
+ action?: string;
34
+ resource?: string;
35
+ userId?: string;
36
+ tenantId?: string;
37
+ startDate?: string;
38
+ endDate?: string;
39
+ };
40
+ export type PaginatedResult<T> = {
41
+ items: T[];
42
+ pagination: {
43
+ page: number;
44
+ pageSize: number;
45
+ total: number;
46
+ totalPages: number;
47
+ hasPrev: boolean;
48
+ hasNext: boolean;
49
+ };
50
+ };
51
+ export type AuditStatistics = {
52
+ totalEntries: number;
53
+ successCount: number;
54
+ failureCount: number;
55
+ topActions: {
56
+ action: string;
57
+ count: number;
58
+ }[];
59
+ topResources: {
60
+ resource: string;
61
+ count: number;
62
+ }[];
63
+ };
64
+ export type IntegrityVerificationResult = {
65
+ valid: boolean;
66
+ brokenAt: string | null;
67
+ totalChecked: number;
68
+ };
69
+ export type AuditLogPort = {
70
+ save(entry: AuditLogEntry): Promise<AuditLogEntry>;
71
+ findById(id: string): Promise<AuditLogEntry | null>;
72
+ query(params: AuditLogQueryParams): Promise<PaginatedResult<AuditLogEntry>>;
73
+ getStatistics(filter: AuditStatsFilter): Promise<AuditStatistics>;
74
+ deleteOlderThan(date: Date): Promise<number>;
75
+ verifyIntegrity(startId?: string): Promise<IntegrityVerificationResult>;
76
+ };
77
+ export type AuditStatsFilter = {
78
+ startDate?: string;
79
+ endDate?: string;
80
+ tenantId?: string;
81
+ };
82
+ export type IdentityAuthBackend = AuthBackendPort & {
83
+ tenant: TenantPort;
84
+ tenantMember: TenantMemberPort;
85
+ audit: AuditLogPort;
86
+ };
87
+ export type TenantValidateFn = (tenantId: string) => Promise<TenantValidateResult>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,4 @@
1
- export type { AuthBackendPort, LocalAuthBackend, IdentityAuthBackend, UserPort, SessionPort, TokenPort, TenantPort, TenantMemberPort, UserAuthInfo, VerifyPasswordResult, TenantValidateResult, } from "./auth-backend.port";
1
+ export type { AuthBackendPort, UserPort, SessionPort, TokenPort, UserAuthInfo, VerifyPasswordResult, TenantValidateResult, } from "./auth-backend.port";
2
2
  export type { PasswordHasher } from "./password-hash.port";
3
3
  export type { AuthStrategy, TokenSigner, TokenVerifier, TokenVerifyResult, RateLimiter, } from "./strategy.port";
4
+ export type { IdentityAuthBackend, TenantPort, TenantMemberPort, AuditLogPort, AuditLogEntry, AuditLogQueryParams, PaginatedResult, AuditStatistics, AuditStatsFilter, IntegrityVerificationResult, TenantValidateFn, } from "./identity.port";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-auth/core",
3
- "version": "0.0.1",
4
- "license": "MIT",
3
+ "version": "0.0.2",
4
+ "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "main": "./dist/index.cjs",
@@ -35,11 +35,19 @@
35
35
  "zod": "^4.4.3"
36
36
  },
37
37
  "scripts": {
38
- "build": "tsgo --build",
39
- "typecheck": "tsgo --noEmit",
38
+ "build": "bun build src/index.ts --outdir dist --target bun",
39
+ "build:declaration": "tsgo --declaration --emitDeclarationOnly --outDir dist -p tsconfig/app.json",
40
+ "build:prod": "NODE_ENV=production tsdown",
41
+ "prepublishOnly": "bun run build:prod",
42
+ "typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
43
+ "typecheck:app": "tsgo --noEmit -p tsconfig/app.json",
44
+ "typecheck:node": "tsgo --noEmit -p tsconfig/node.json",
45
+ "typecheck:test": "tsgo --noEmit -p tsconfig/test.json",
40
46
  "lint": "oxlint && oxfmt --check",
41
47
  "lint:fix": "oxlint --fix && oxfmt",
42
48
  "test": "bun test",
49
+ "test:watch": "bun test --watch",
50
+ "test:coverage": "bun test --coverage",
43
51
  "clean": "rm -rf dist out .cache"
44
52
  }
45
53
  }