@plyaz/types 1.46.3 → 1.46.5

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.
@@ -0,0 +1,36 @@
1
+ import type { AuthTokens, AuthUser } from "./types";
2
+ export interface SignInCredentials {
3
+ email: string;
4
+ password: string;
5
+ rememberMe?: boolean;
6
+ }
7
+ export interface SignInResult {
8
+ user: AuthUser;
9
+ tokens: AuthTokens;
10
+ requiresMFA?: boolean;
11
+ mfaToken?: string;
12
+ }
13
+ /** User repository type based on usage */
14
+ export interface UserRepositorySignin {
15
+ findByEmail(email: string): Promise<AuthUser | null>;
16
+ findById(userId: string): Promise<AuthUser | null>;
17
+ }
18
+ /** JWT manager type based on usage */
19
+ export interface JWTManagerSignin {
20
+ generateTokens(userId: string): Promise<AuthTokens>;
21
+ verifyToken(token: string): Promise<{
22
+ userId: string;
23
+ }>;
24
+ }
25
+ /** Session manager type based on usage */
26
+ export interface SessionManagerSignin {
27
+ createSession(session: {
28
+ userId: string;
29
+ expiresAt: Date;
30
+ metadata?: Record<string, true>;
31
+ }): Promise<void>;
32
+ }
33
+ /** Password service type based on usage */
34
+ export interface PasswordServiceSignin {
35
+ verify(password: string, passwordHash: string | undefined): Promise<boolean>;
36
+ }
@@ -0,0 +1,47 @@
1
+ import type { AuthTokens, AuthUser } from "./types";
2
+ export interface SignUpData {
3
+ email: string;
4
+ password: string;
5
+ firstName?: string;
6
+ lastName?: string;
7
+ metadata?: Record<string, string>;
8
+ }
9
+ export interface SignUpResult {
10
+ user: AuthUser;
11
+ tokens: AuthTokens;
12
+ requiresVerification?: boolean;
13
+ }
14
+ /** User repository type based on usage */
15
+ export interface UserRepositorySignUp {
16
+ findByEmail(email: string): Promise<AuthUser | null>;
17
+ create(data: {
18
+ email: string;
19
+ passwordHash: string;
20
+ firstName?: string;
21
+ lastName?: string;
22
+ metadata?: Record<string, string>;
23
+ emailVerified: boolean;
24
+ }): Promise<AuthUser>;
25
+ findById(userId: string): Promise<AuthUser>;
26
+ updateEmailVerification(userId: string, verified: boolean): Promise<AuthUser | null>;
27
+ }
28
+ /** JWT manager type based on usage */
29
+ export interface JWTManagerSignUp {
30
+ generateTokens(userId: string): Promise<AuthTokens>;
31
+ generateVerificationToken(userId: string): Promise<string>;
32
+ verifyToken(token: string): Promise<{
33
+ userId: string;
34
+ }>;
35
+ }
36
+ /** Password service type based on usage */
37
+ export interface PasswordServiceSignUp {
38
+ hash(password: string): Promise<string>;
39
+ }
40
+ /** Email service type based on usage */
41
+ export interface EmailService {
42
+ sendVerificationEmail(args: {
43
+ to: string;
44
+ token: string;
45
+ userId: string;
46
+ }): Promise<void>;
47
+ }
@@ -0,0 +1,44 @@
1
+ import type { AuthAdapterUser, AuthSession, Tokens } from "./adapter-interface";
2
+ import type { AuthPermissions } from "./client";
3
+ import type { AUTHPROVIDER } from "./enums";
4
+ import type { AuthCredentials, AuthTokens, AuthUser, ConnectedAccount, Session } from "./types";
5
+ export interface AuthState {
6
+ user: AuthPermissions | null;
7
+ tokens: AuthTokens | null;
8
+ isAuthenticated: boolean;
9
+ isLoading: boolean;
10
+ session: Session | null;
11
+ sessionExpiry: Date | null;
12
+ connectedAccounts: ConnectedAccount[];
13
+ permissions: string[];
14
+ roles: string[];
15
+ lastActivity: Date | null;
16
+ rememberMe: boolean;
17
+ error: string | null;
18
+ }
19
+ export interface AuthActions {
20
+ setUser: (user: AuthUser | null) => void;
21
+ updateUser: (updates: Partial<AuthUser>) => void;
22
+ setTokens: (tokens: AuthTokens | null) => void;
23
+ refreshTokens: () => Promise<void>;
24
+ setSession: (session: Session | null) => void;
25
+ updateLastActivity: () => void;
26
+ setConnectedAccounts: (accounts: ConnectedAccount[]) => void;
27
+ addConnectedAccount: (account: ConnectedAccount) => void;
28
+ removeConnectedAccount: (accountId: string) => void;
29
+ setPermissions: (permissions: string[]) => void;
30
+ setRoles: (roles: string[]) => void;
31
+ hasPermission: (permission: string) => boolean;
32
+ hasRole: (role: string) => boolean;
33
+ signIn: (provider?: AUTHPROVIDER, credentials?: AuthCredentials) => Promise<{
34
+ user: AuthAdapterUser;
35
+ session: AuthSession;
36
+ tokens: Tokens;
37
+ }>;
38
+ signUp: (provider: AUTHPROVIDER, data?: unknown) => Promise<void>;
39
+ signOut: () => Promise<void>;
40
+ setLoading: (loading: boolean) => void;
41
+ setError: (error: string | null) => void;
42
+ clearError: () => void;
43
+ reset: () => void;
44
+ }
@@ -2,6 +2,7 @@ import type { WithExpiration, WithAuthTokens } from '../common/types';
2
2
  import type { BaseErrorContext } from '../errors';
3
3
  import type { AUTH_ERROR_DEFINITIONS, USER_ROLE_STATUS } from './enums';
4
4
  import type { AuthForm } from './schemas';
5
+ import type { JwtPayload } from "jsonwebtoken";
5
6
  /**
6
7
  * AuthToken Interface.
7
8
  * @description Represents an authentication token set returned after a successful login or refresh.
@@ -1187,3 +1188,335 @@ export interface AuthDeviceInfo {
1187
1188
  os: string;
1188
1189
  userAgent: string;
1189
1190
  }
1191
+ export interface TokenBlacklistConfig {
1192
+ redisUrl?: string;
1193
+ keyPrefix: string;
1194
+ defaultTTL: number;
1195
+ }
1196
+ export interface AuthProviderConfig {
1197
+ clientId: string;
1198
+ clientSecret: string;
1199
+ redirectUri: string;
1200
+ scopes?: string[];
1201
+ }
1202
+ export interface AuthenticationProvider {
1203
+ readonly name: string;
1204
+ readonly type: "oauth" | "traditional" | "web3";
1205
+ initialize(config: AuthProviderConfig): Promise<void>;
1206
+ authenticate(credentials: {
1207
+ code: string;
1208
+ }): Promise<{
1209
+ user: AuthUser;
1210
+ tokens: AuthTokens;
1211
+ }>;
1212
+ refreshToken(refreshToken: string): Promise<AuthTokens>;
1213
+ revokeToken(token: string): Promise<void>;
1214
+ getUserProfile(accessToken: string): Promise<AuthUser>;
1215
+ }
1216
+ export interface RoleRepository {
1217
+ /**
1218
+ * Get all roles assigned to a user
1219
+ * @param userId - User identifier
1220
+ * @returns Array of Role objects
1221
+ */
1222
+ getUserRoles(userId: string): Promise<Role[]>;
1223
+ /**
1224
+ * Get all permissions assigned to a role
1225
+ * @param roleId - Role identifier
1226
+ * @returns Array of Permission objects
1227
+ */
1228
+ getRolePermissions(roleId: string): Promise<Permission[]>;
1229
+ }
1230
+ export interface GetUserRoleRepository {
1231
+ /**
1232
+ * Get all roles assigned to a user
1233
+ * @param userId - User identifier
1234
+ * @returns Array of Role objects
1235
+ */
1236
+ getUserRoles(userId: string): Promise<Role[]>;
1237
+ }
1238
+ export interface TypedRequest {
1239
+ user?: {
1240
+ sub?: string;
1241
+ userId?: string;
1242
+ };
1243
+ params?: Record<string, string>;
1244
+ query?: Record<string, string>;
1245
+ body?: Record<string, string>;
1246
+ permissionResult?: unknown;
1247
+ }
1248
+ /**
1249
+ * Permission metadata interface
1250
+ */
1251
+ export interface PermissionMetadata {
1252
+ resource: string;
1253
+ action: string;
1254
+ conditions?: Record<string, string>;
1255
+ }
1256
+ export interface AuthRequest extends Request {
1257
+ /** Optional session ID extracted from cookies or headers */
1258
+ sessionId?: string;
1259
+ }
1260
+ export interface SessionMiddlewareConfig {
1261
+ /** Refresh threshold in seconds (default: 300 = 5 minutes) */
1262
+ refreshThreshold: number;
1263
+ /** Cookie options for tokens */
1264
+ cookieOptions: {
1265
+ httpOnly: boolean;
1266
+ secure: boolean;
1267
+ sameSite: "strict" | "lax" | "none";
1268
+ path: string;
1269
+ };
1270
+ }
1271
+ export interface CookieStoreConfig extends Partial<SessionStoreConfig> {
1272
+ /** Secret key for encryption */
1273
+ secretKey: string;
1274
+ /** Cookie name */
1275
+ cookieName: string;
1276
+ /** Cookie domain */
1277
+ domain?: string;
1278
+ /** Cookie path */
1279
+ path?: string;
1280
+ /** Secure flag (HTTPS only) */
1281
+ secure?: boolean;
1282
+ /** HttpOnly flag */
1283
+ httpOnly?: boolean;
1284
+ /** SameSite policy */
1285
+ sameSite?: "strict" | "lax" | "none";
1286
+ }
1287
+ /**
1288
+ * User context for session creation
1289
+ */
1290
+ export interface UserSessionContext {
1291
+ /** User ID */
1292
+ userId: string;
1293
+ /** User email */
1294
+ email?: string;
1295
+ /** User roles */
1296
+ roles?: string[];
1297
+ /** Additional user metadata */
1298
+ metadata?: Record<string, unknown>;
1299
+ }
1300
+ /**
1301
+ * Session creation data
1302
+ */
1303
+ export interface SessionCreationData {
1304
+ /** IP address */
1305
+ ipAddress?: string;
1306
+ /** User agent string */
1307
+ userAgent?: string;
1308
+ /** Device information */
1309
+ deviceInfo?: Record<string, unknown>;
1310
+ /** Additional session metadata */
1311
+ metadata?: Record<string, unknown>;
1312
+ }
1313
+ /**
1314
+ * Enhanced session manager configuration
1315
+ */
1316
+ export interface EnhancedSessionManagerConfig {
1317
+ /** Session store implementation */
1318
+ store: SessionStore;
1319
+ /** Default session TTL in seconds */
1320
+ sessionTTL: number;
1321
+ /** Maximum concurrent sessions per user */
1322
+ maxConcurrentSessions: number;
1323
+ /** Enable CSRF protection */
1324
+ enableCSRF: boolean;
1325
+ /** CSRF token TTL in seconds */
1326
+ csrfTTL: number;
1327
+ /** Enable session refresh */
1328
+ enableRefresh: boolean;
1329
+ /** Session refresh threshold (seconds before expiry) */
1330
+ refreshThreshold: number;
1331
+ }
1332
+ /**
1333
+ * Redis connection configuration
1334
+ */
1335
+ export interface RedisConfig {
1336
+ /** Redis host */
1337
+ host: string;
1338
+ /** Redis port */
1339
+ port: number;
1340
+ /** Redis password */
1341
+ password?: string;
1342
+ /** Redis database number */
1343
+ db?: number;
1344
+ /** Connection timeout in milliseconds */
1345
+ connectTimeout?: number;
1346
+ /** Command timeout in milliseconds */
1347
+ commandTimeout?: number;
1348
+ /** Enable TLS */
1349
+ tls?: boolean;
1350
+ }
1351
+ /**
1352
+ * Redis store configuration
1353
+ */
1354
+ export interface RedisStoreConfig extends Partial<SessionStoreConfig> {
1355
+ /** Redis connection configuration */
1356
+ redis: RedisConfig;
1357
+ /** Enable compression for large sessions */
1358
+ compression?: boolean;
1359
+ /** Serialization format */
1360
+ serialization?: "json" | "msgpack";
1361
+ }
1362
+ /**
1363
+ * Mock Redis client interface for development
1364
+ * In production, this would be replaced with actual Redis client (ioredis, node-redis, etc.)
1365
+ */
1366
+ export interface MockRedisClient {
1367
+ set(key: string, value: string, ex: number): Promise<string>;
1368
+ get(key: string): Promise<string | null>;
1369
+ del(key: string): Promise<number>;
1370
+ keys(pattern: string): Promise<string[]>;
1371
+ expire(key: string, seconds: number): Promise<number>;
1372
+ exists(key: string): Promise<number>;
1373
+ scan(cursor: string, match?: string, count?: number): Promise<[string, string[]]>;
1374
+ }
1375
+ export interface OAuthProfile {
1376
+ id: string;
1377
+ email: string;
1378
+ name: string;
1379
+ avatar?: string;
1380
+ provider: string;
1381
+ }
1382
+ /**
1383
+ * Refresh token manager configuration
1384
+ */
1385
+ export interface RefreshTokenManagerConfig {
1386
+ /** Secret key for signing tokens */
1387
+ secretKey: string;
1388
+ /** Refresh token TTL in seconds */
1389
+ tokenTTL: number;
1390
+ /** Access token TTL in seconds */
1391
+ accessTokenTTL: number;
1392
+ /** Token issuer */
1393
+ issuer: string;
1394
+ /** Token audience */
1395
+ audience: string;
1396
+ /** Enable token rotation */
1397
+ enableRotation: boolean;
1398
+ /** Enable token family tracking */
1399
+ enableFamilyTracking: boolean;
1400
+ /** Maximum token family size */
1401
+ maxFamilySize: number;
1402
+ }
1403
+ /**
1404
+ * Token pair (access + refresh)
1405
+ */
1406
+ export interface TokenPair {
1407
+ /** Access token */
1408
+ accessToken: string;
1409
+ /** Refresh token */
1410
+ refreshToken: string;
1411
+ /** Access token expiration */
1412
+ accessTokenExpiresAt: Date;
1413
+ /** Refresh token expiration */
1414
+ refreshTokenExpiresAt: Date;
1415
+ }
1416
+ /**
1417
+ * Refresh token payload
1418
+ */
1419
+ export interface RefreshTokenPayload {
1420
+ /** User ID */
1421
+ sub: string;
1422
+ /** Session ID */
1423
+ sessionId: string;
1424
+ /** Token family ID (for rotation tracking) */
1425
+ family?: string;
1426
+ /** Token generation number */
1427
+ generation?: number;
1428
+ /** Token type */
1429
+ type: "refresh";
1430
+ /** Issued at */
1431
+ iat: number;
1432
+ /** Expires at */
1433
+ exp: number;
1434
+ /** Issuer */
1435
+ iss: string;
1436
+ /** Audience */
1437
+ aud: string;
1438
+ }
1439
+ /**
1440
+ * Access token payload
1441
+ */
1442
+ export interface AccessTokenPayload {
1443
+ /** User ID */
1444
+ sub: string;
1445
+ /** Session ID */
1446
+ sessionId: string;
1447
+ /** User roles */
1448
+ roles?: string[];
1449
+ /** User permissions */
1450
+ permissions?: string[];
1451
+ /** Token type */
1452
+ type: "access";
1453
+ /** Issued at */
1454
+ iat: number;
1455
+ /** Expires at */
1456
+ exp: number;
1457
+ /** Issuer */
1458
+ iss: string;
1459
+ /** Audience */
1460
+ aud: string;
1461
+ }
1462
+ /**
1463
+ * Token family for rotation tracking
1464
+ */
1465
+ export interface TokenFamily {
1466
+ /** Family ID */
1467
+ id: string;
1468
+ /** User ID */
1469
+ userId: string;
1470
+ /** Session ID */
1471
+ sessionId: string;
1472
+ /** Current generation */
1473
+ generation: number;
1474
+ /** Created at */
1475
+ createdAt: Date;
1476
+ /** Last used at */
1477
+ lastUsedAt: Date;
1478
+ }
1479
+ export interface TokenValidatorConfig {
1480
+ /** Public key for signature verification */
1481
+ publicKey: string;
1482
+ /** Expected token issuer */
1483
+ issuer: string;
1484
+ /** Expected token audience */
1485
+ audience: string;
1486
+ /** Algorithm for verification */
1487
+ algorithm?: string;
1488
+ /** Clock tolerance in seconds */
1489
+ clockTolerance?: number;
1490
+ /** Enable blacklist checking */
1491
+ enableBlacklist?: boolean;
1492
+ }
1493
+ /**
1494
+ * Validated token payload
1495
+ */
1496
+ export interface ValidatedTokenPayload extends JwtPayload {
1497
+ /** User ID (subject) */
1498
+ sub: string;
1499
+ /** Session ID */
1500
+ sessionId?: string;
1501
+ /** User roles */
1502
+ roles?: string[];
1503
+ /** User permissions */
1504
+ permissions?: string[];
1505
+ /** Token type */
1506
+ type?: "access" | "refresh";
1507
+ }
1508
+ /**
1509
+ * Token validation result
1510
+ */
1511
+ export interface TokenValidationResult {
1512
+ /** Validation success */
1513
+ valid: boolean;
1514
+ /** Decoded payload (if valid) */
1515
+ payload?: ValidatedTokenPayload;
1516
+ /** Error details (if invalid) */
1517
+ error?: {
1518
+ code: string;
1519
+ message: string;
1520
+ details?: unknown;
1521
+ };
1522
+ }
@@ -11,7 +11,7 @@ import type { CorePlyazConfig } from '../core';
11
11
  /**
12
12
  * Available devtools tab identifiers
13
13
  */
14
- export type DevtoolsTab = 'stores' | 'actions' | 'api' | 'streaming' | 'security' | 'compliance' | 'accessibility' | 'services' | 'errors' | 'events' | 'uploads' | 'observability' | 'config' | 'storage' | 'playground' | 'runner' | 'flags' | 'mocking' | 'explorer' | 'ssr' | 'routes' | 'i18n' | 'react' | 'console' | 'shortcuts';
14
+ export type DevtoolsTab = 'stores' | 'actions' | 'api' | 'streaming' | 'security' | 'compliance' | 'accessibility' | 'services' | 'errors' | 'events' | 'uploads' | 'observability' | 'config' | 'storage' | 'playground' | 'runner' | 'flags' | 'mocking' | 'explorer' | 'types' | 'ssr' | 'routes' | 'i18n' | 'react' | 'console' | 'shortcuts';
15
15
  /**
16
16
  * Tab group configuration
17
17
  */