@lenan-soft/auth 1.0.1

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,129 @@
1
+ /**
2
+ * JWT payload structure
3
+ */
4
+ interface JwtPayload {
5
+ /** User ID (subject) */
6
+ sub: string;
7
+ /** User email */
8
+ email: string;
9
+ /** Issued at timestamp */
10
+ iat?: number;
11
+ /** Expiration timestamp */
12
+ exp?: number;
13
+ }
14
+ /**
15
+ * Token response containing access and refresh tokens
16
+ */
17
+ interface AuthTokens {
18
+ /** Short-lived access token */
19
+ accessToken: string;
20
+ /** Long-lived refresh token */
21
+ refreshToken: string;
22
+ }
23
+ /**
24
+ * Base user interface - minimal fields required by the auth system
25
+ * Consumers should extend this with their own user properties
26
+ */
27
+ interface BaseUser {
28
+ /** Unique user identifier */
29
+ id: string;
30
+ /** User email address */
31
+ email: string;
32
+ }
33
+ /**
34
+ * User with password hash - used internally for authentication
35
+ */
36
+ interface UserWithPassword extends BaseUser {
37
+ /** Bcrypt hashed password */
38
+ passwordHash: string;
39
+ }
40
+ /**
41
+ * User with refresh token - used for token refresh operations
42
+ */
43
+ interface UserWithRefreshToken extends BaseUser {
44
+ /** Hashed refresh token (nullable when logged out) */
45
+ hashedRefreshToken: string | null;
46
+ }
47
+ /**
48
+ * Full auth user interface combining all auth-related fields
49
+ */
50
+ interface AuthUser extends BaseUser {
51
+ passwordHash: string;
52
+ hashedRefreshToken: string | null;
53
+ }
54
+ /**
55
+ * Login credentials
56
+ */
57
+ interface LoginCredentials {
58
+ email: string;
59
+ password: string;
60
+ }
61
+ /**
62
+ * Registration data
63
+ */
64
+ interface RegisterData {
65
+ email: string;
66
+ password: string;
67
+ }
68
+ /**
69
+ * Auth state for frontend applications
70
+ */
71
+ interface AuthState<TUser extends BaseUser = BaseUser> {
72
+ /** Current authenticated user or null */
73
+ user: TUser | null;
74
+ /** Current tokens or null */
75
+ tokens: AuthTokens | null;
76
+ /** Whether auth state is being loaded/validated */
77
+ isLoading: boolean;
78
+ /** Whether user is authenticated */
79
+ isAuthenticated: boolean;
80
+ /** Auth error if any */
81
+ error: string | null;
82
+ }
83
+ /**
84
+ * Token storage interface for frontend applications
85
+ * Implement this to use different storage backends (localStorage, SecureStore, etc.)
86
+ */
87
+ interface TokenStorage {
88
+ getItem(key: string): Promise<string | null> | string | null;
89
+ setItem(key: string, value: string): Promise<void> | void;
90
+ removeItem(key: string): Promise<void> | void;
91
+ }
92
+ /**
93
+ * Auth client configuration for frontend HTTP client
94
+ */
95
+ interface AuthClientConfig {
96
+ /** Base URL for auth API endpoints */
97
+ baseUrl: string;
98
+ /** Token storage implementation */
99
+ tokenStorage: TokenStorage;
100
+ /** Custom headers to include in requests */
101
+ headers?: Record<string, string>;
102
+ /** Access token storage key (default: 'lenan_access_token') */
103
+ accessTokenKey?: string;
104
+ /** Refresh token storage key (default: 'lenan_refresh_token') */
105
+ refreshTokenKey?: string;
106
+ }
107
+ /**
108
+ * Auth API endpoints configuration
109
+ */
110
+ interface AuthEndpoints {
111
+ login: string;
112
+ register: string;
113
+ refresh: string;
114
+ logout: string;
115
+ me: string;
116
+ }
117
+ /**
118
+ * Default auth endpoints
119
+ */
120
+ declare const DEFAULT_AUTH_ENDPOINTS: AuthEndpoints;
121
+ /**
122
+ * Default token storage keys
123
+ */
124
+ declare const TOKEN_STORAGE_KEYS: {
125
+ readonly ACCESS_TOKEN: "lenan_access_token";
126
+ readonly REFRESH_TOKEN: "lenan_refresh_token";
127
+ };
128
+
129
+ export { type AuthClientConfig, type AuthEndpoints, type AuthState, type AuthTokens, type AuthUser, type BaseUser, DEFAULT_AUTH_ENDPOINTS, type JwtPayload, type LoginCredentials, type RegisterData, TOKEN_STORAGE_KEYS, type TokenStorage, type UserWithPassword, type UserWithRefreshToken };
@@ -0,0 +1,129 @@
1
+ /**
2
+ * JWT payload structure
3
+ */
4
+ interface JwtPayload {
5
+ /** User ID (subject) */
6
+ sub: string;
7
+ /** User email */
8
+ email: string;
9
+ /** Issued at timestamp */
10
+ iat?: number;
11
+ /** Expiration timestamp */
12
+ exp?: number;
13
+ }
14
+ /**
15
+ * Token response containing access and refresh tokens
16
+ */
17
+ interface AuthTokens {
18
+ /** Short-lived access token */
19
+ accessToken: string;
20
+ /** Long-lived refresh token */
21
+ refreshToken: string;
22
+ }
23
+ /**
24
+ * Base user interface - minimal fields required by the auth system
25
+ * Consumers should extend this with their own user properties
26
+ */
27
+ interface BaseUser {
28
+ /** Unique user identifier */
29
+ id: string;
30
+ /** User email address */
31
+ email: string;
32
+ }
33
+ /**
34
+ * User with password hash - used internally for authentication
35
+ */
36
+ interface UserWithPassword extends BaseUser {
37
+ /** Bcrypt hashed password */
38
+ passwordHash: string;
39
+ }
40
+ /**
41
+ * User with refresh token - used for token refresh operations
42
+ */
43
+ interface UserWithRefreshToken extends BaseUser {
44
+ /** Hashed refresh token (nullable when logged out) */
45
+ hashedRefreshToken: string | null;
46
+ }
47
+ /**
48
+ * Full auth user interface combining all auth-related fields
49
+ */
50
+ interface AuthUser extends BaseUser {
51
+ passwordHash: string;
52
+ hashedRefreshToken: string | null;
53
+ }
54
+ /**
55
+ * Login credentials
56
+ */
57
+ interface LoginCredentials {
58
+ email: string;
59
+ password: string;
60
+ }
61
+ /**
62
+ * Registration data
63
+ */
64
+ interface RegisterData {
65
+ email: string;
66
+ password: string;
67
+ }
68
+ /**
69
+ * Auth state for frontend applications
70
+ */
71
+ interface AuthState<TUser extends BaseUser = BaseUser> {
72
+ /** Current authenticated user or null */
73
+ user: TUser | null;
74
+ /** Current tokens or null */
75
+ tokens: AuthTokens | null;
76
+ /** Whether auth state is being loaded/validated */
77
+ isLoading: boolean;
78
+ /** Whether user is authenticated */
79
+ isAuthenticated: boolean;
80
+ /** Auth error if any */
81
+ error: string | null;
82
+ }
83
+ /**
84
+ * Token storage interface for frontend applications
85
+ * Implement this to use different storage backends (localStorage, SecureStore, etc.)
86
+ */
87
+ interface TokenStorage {
88
+ getItem(key: string): Promise<string | null> | string | null;
89
+ setItem(key: string, value: string): Promise<void> | void;
90
+ removeItem(key: string): Promise<void> | void;
91
+ }
92
+ /**
93
+ * Auth client configuration for frontend HTTP client
94
+ */
95
+ interface AuthClientConfig {
96
+ /** Base URL for auth API endpoints */
97
+ baseUrl: string;
98
+ /** Token storage implementation */
99
+ tokenStorage: TokenStorage;
100
+ /** Custom headers to include in requests */
101
+ headers?: Record<string, string>;
102
+ /** Access token storage key (default: 'lenan_access_token') */
103
+ accessTokenKey?: string;
104
+ /** Refresh token storage key (default: 'lenan_refresh_token') */
105
+ refreshTokenKey?: string;
106
+ }
107
+ /**
108
+ * Auth API endpoints configuration
109
+ */
110
+ interface AuthEndpoints {
111
+ login: string;
112
+ register: string;
113
+ refresh: string;
114
+ logout: string;
115
+ me: string;
116
+ }
117
+ /**
118
+ * Default auth endpoints
119
+ */
120
+ declare const DEFAULT_AUTH_ENDPOINTS: AuthEndpoints;
121
+ /**
122
+ * Default token storage keys
123
+ */
124
+ declare const TOKEN_STORAGE_KEYS: {
125
+ readonly ACCESS_TOKEN: "lenan_access_token";
126
+ readonly REFRESH_TOKEN: "lenan_refresh_token";
127
+ };
128
+
129
+ export { type AuthClientConfig, type AuthEndpoints, type AuthState, type AuthTokens, type AuthUser, type BaseUser, DEFAULT_AUTH_ENDPOINTS, type JwtPayload, type LoginCredentials, type RegisterData, TOKEN_STORAGE_KEYS, type TokenStorage, type UserWithPassword, type UserWithRefreshToken };
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ // src/shared/types.ts
2
+ var DEFAULT_AUTH_ENDPOINTS = {
3
+ login: "/auth/login",
4
+ register: "/auth/register",
5
+ refresh: "/auth/refresh",
6
+ logout: "/auth/logout",
7
+ me: "/auth/me"
8
+ };
9
+ var TOKEN_STORAGE_KEYS = {
10
+ ACCESS_TOKEN: "lenan_access_token",
11
+ REFRESH_TOKEN: "lenan_refresh_token"
12
+ };
13
+ export {
14
+ DEFAULT_AUTH_ENDPOINTS,
15
+ TOKEN_STORAGE_KEYS
16
+ };
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/types.ts"],"sourcesContent":["/**\n * JWT payload structure\n */\nexport interface JwtPayload {\n /** User ID (subject) */\n sub: string;\n /** User email */\n email: string;\n /** Issued at timestamp */\n iat?: number;\n /** Expiration timestamp */\n exp?: number;\n}\n\n/**\n * Token response containing access and refresh tokens\n */\nexport interface AuthTokens {\n /** Short-lived access token */\n accessToken: string;\n /** Long-lived refresh token */\n refreshToken: string;\n}\n\n/**\n * Base user interface - minimal fields required by the auth system\n * Consumers should extend this with their own user properties\n */\nexport interface BaseUser {\n /** Unique user identifier */\n id: string;\n /** User email address */\n email: string;\n}\n\n/**\n * User with password hash - used internally for authentication\n */\nexport interface UserWithPassword extends BaseUser {\n /** Bcrypt hashed password */\n passwordHash: string;\n}\n\n/**\n * User with refresh token - used for token refresh operations\n */\nexport interface UserWithRefreshToken extends BaseUser {\n /** Hashed refresh token (nullable when logged out) */\n hashedRefreshToken: string | null;\n}\n\n/**\n * Full auth user interface combining all auth-related fields\n */\nexport interface AuthUser extends BaseUser {\n passwordHash: string;\n hashedRefreshToken: string | null;\n}\n\n/**\n * Login credentials\n */\nexport interface LoginCredentials {\n email: string;\n password: string;\n}\n\n/**\n * Registration data\n */\nexport interface RegisterData {\n email: string;\n password: string;\n}\n\n/**\n * Auth state for frontend applications\n */\nexport interface AuthState<TUser extends BaseUser = BaseUser> {\n /** Current authenticated user or null */\n user: TUser | null;\n /** Current tokens or null */\n tokens: AuthTokens | null;\n /** Whether auth state is being loaded/validated */\n isLoading: boolean;\n /** Whether user is authenticated */\n isAuthenticated: boolean;\n /** Auth error if any */\n error: string | null;\n}\n\n/**\n * Token storage interface for frontend applications\n * Implement this to use different storage backends (localStorage, SecureStore, etc.)\n */\nexport interface TokenStorage {\n getItem(key: string): Promise<string | null> | string | null;\n setItem(key: string, value: string): Promise<void> | void;\n removeItem(key: string): Promise<void> | void;\n}\n\n/**\n * Auth client configuration for frontend HTTP client\n */\nexport interface AuthClientConfig {\n /** Base URL for auth API endpoints */\n baseUrl: string;\n /** Token storage implementation */\n tokenStorage: TokenStorage;\n /** Custom headers to include in requests */\n headers?: Record<string, string>;\n /** Access token storage key (default: 'lenan_access_token') */\n accessTokenKey?: string;\n /** Refresh token storage key (default: 'lenan_refresh_token') */\n refreshTokenKey?: string;\n}\n\n/**\n * Auth API endpoints configuration\n */\nexport interface AuthEndpoints {\n login: string;\n register: string;\n refresh: string;\n logout: string;\n me: string;\n}\n\n/**\n * Default auth endpoints\n */\nexport const DEFAULT_AUTH_ENDPOINTS: AuthEndpoints = {\n login: \"/auth/login\",\n register: \"/auth/register\",\n refresh: \"/auth/refresh\",\n logout: \"/auth/logout\",\n me: \"/auth/me\",\n};\n\n/**\n * Default token storage keys\n */\nexport const TOKEN_STORAGE_KEYS = {\n ACCESS_TOKEN: \"lenan_access_token\",\n REFRESH_TOKEN: \"lenan_refresh_token\",\n} as const;\n"],"mappings":";AAmIO,IAAM,yBAAwC;AAAA,EACnD,OAAO;AAAA,EACP,UAAU;AAAA,EACV,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,IAAI;AACN;AAKO,IAAM,qBAAqB;AAAA,EAChC,cAAc;AAAA,EACd,eAAe;AACjB;","names":[]}