@xeno-js/shared 2.0.0 → 3.0.0

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,214 @@
1
+ /**
2
+ * @description Represents a value that may be `null`.
3
+ * Prefer this over `T | null` in all public APIs so intent is self-documenting.
4
+
5
+ *
6
+ * @author Xeno
7
+ * @version 1.0.0
8
+ * @since 2025-09-30
9
+ * @link https://github.com/xeno-js/xeno-js
10
+ */
11
+ type Nullable<T> = T | null;
12
+ /**
13
+ * @description Represents a value that may be `undefined`.
14
+ * Prefer this over `T | undefined` in all public APIs.
15
+
16
+ *
17
+ * @author Xeno
18
+ * @version 1.0.0
19
+ * @since 2025-09-30
20
+ * @link https://github.com/xeno-js/xeno-js
21
+ */
22
+ type Optional<T> = T | undefined;
23
+ /**
24
+ * @description Represents a value that may be either `null` or `undefined`.
25
+ * Use when a value is absent regardless of the reason.
26
+
27
+ *
28
+ * @author Xeno
29
+ * @version 1.0.0
30
+ * @since 2025-09-30
31
+ * @link https://github.com/xeno-js/xeno-js
32
+ */
33
+ type Maybe<T> = T | null | undefined;
34
+ /**
35
+ * @description Represents a concrete (instantiable) class.
36
+ * Used by IoC containers and auto-wiring utilities to bind concrete implementations.
37
+ *
38
+ * @template T The instance type produced by `new`.
39
+ * @template TArgs Constructor parameter tuple; defaults to `any[]`.
40
+
41
+ *
42
+ * @author Xeno
43
+ * @version 1.0.0
44
+ * @since 2025-09-30
45
+ * @link https://github.com/xeno-js/xeno-js
46
+ */
47
+ type Constructor<T, TArgs extends Dictionary[] = Dictionary[]> = new (...args: TArgs) => T;
48
+ /**
49
+ * @description Represents an abstract class that cannot be instantiated directly.
50
+ * Used for binding abstract base classes in the IoC container without requiring
51
+ * a concrete constructor signature.
52
+ *
53
+ * @template T The instance type produced by subclasses.
54
+
55
+ *
56
+ * @author Xeno
57
+ * @version 1.0.0
58
+ * @since 2025-09-30
59
+ * @link https://github.com/xeno-js/xeno-js
60
+ */
61
+ type AbstractConstructor<T> = abstract new (...args: Dictionary[]) => T;
62
+ /**
63
+ * @description A plain-object dictionary with string keys and uniform value type.
64
+ * Prefer over `{ [key: string]: V }` for self-documenting intent.
65
+
66
+ *
67
+ * @author Xeno
68
+ * @version 1.0.0
69
+ * @since 2025-09-30
70
+ * @link https://github.com/xeno-js/xeno-js
71
+ */
72
+ type Dictionary<V = unknown> = Record<string, V>;
73
+ /**
74
+ * @description Produces a new type with only the keys `K` made required;
75
+ * all other keys retain their original optionality.
76
+
77
+ *
78
+ * @author Xeno
79
+ * @version 1.0.0
80
+ * @since 2025-09-30
81
+ * @link https://github.com/xeno-js/xeno-js
82
+ */
83
+ type RequireKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
84
+ /**
85
+ * @description Produces a new type where property `K` is overridden with type `V`.
86
+ * Useful for narrowing a property inside a generic base type.
87
+
88
+ *
89
+ * @author Xeno
90
+ * @version 1.0.0
91
+ * @since 2025-09-30
92
+ * @link https://github.com/xeno-js/xeno-js
93
+ */
94
+ type Override<T, K extends keyof T, V> = Omit<T, K> & Record<K, V>;
95
+ /**
96
+ * @description Extracts only the keys of `T` whose values are assignable to `V`.
97
+ *
98
+ * @example
99
+ * type StringKeys = KeysOfType<{ a: string; b: number; c: string }, string>;
100
+ * // => 'a' | 'c'
101
+
102
+ *
103
+ * @author Xeno
104
+ * @version 1.0.0
105
+ * @since 2025-09-30
106
+ * @link https://github.com/xeno-js/xeno-js
107
+ */
108
+ type KeysOfType<T, V> = {
109
+ [K in keyof T]: T[K] extends V ? K : never;
110
+ }[keyof T];
111
+ /**
112
+ * @description Generic factory function that produces a value of type `T`.
113
+ *
114
+ * `TArgs` defaults to an empty tuple for zero-argument factories, enabling
115
+ * usage both as a plain provider (`Factory<T>`) and as a parameterised
116
+ * creator (`Factory<T, [config: MyConfig]>`).
117
+ *
118
+ * @template T The type of the value produced.
119
+ * @template TArgs Tuple of constructor/factory argument types.
120
+ *
121
+ * @example
122
+ * // Zero-argument factory
123
+ * const makeLogger: Factory<ILoggerService> = () => new ConsoleLogger();
124
+ *
125
+ * // Parameterised factory
126
+ * const makeRepo: Factory<IRepository<Entity>, [tx: Transaction]> =
127
+ * (tx) => new DrizzleRepository(tx);
128
+
129
+ *
130
+ * @author Xeno
131
+ * @version 1.0.0
132
+ * @since 2025-09-30
133
+ * @link https://github.com/xeno-js/xeno-js
134
+ */
135
+ type Factory<T, TArgs extends unknown[] = []> = (...args: TArgs) => T;
136
+ /**
137
+ * @description Async variant of `Factory<T, TArgs>`.
138
+ * Use when the construction process involves I/O (e.g. DB pool acquisition).
139
+ *
140
+ * @template T The type of the resolved value.
141
+ * @template TArgs Tuple of factory argument types.
142
+
143
+ *
144
+ * @author Xeno
145
+ * @version 1.0.0
146
+ * @since 2025-09-30
147
+ * @link https://github.com/xeno-js/xeno-js
148
+ */
149
+ type AsyncFactory<T, TArgs extends unknown[] = []> = (...args: TArgs) => Promise<T>;
150
+ /**
151
+ * @description Delegate used by application-layer services to perform lazy,
152
+ * symbol-keyed dependency resolution without coupling to the concrete container.
153
+ *
154
+ * This is the **only** sanctioned way to resolve dependencies at runtime outside
155
+ * of constructor injection. Never inject the raw IoC container into services.
156
+ *
157
+ * @template T Narrows the return type at each call site.
158
+ *
159
+ * @example
160
+ * class NexusMediator {
161
+ * constructor(private readonly resolve: Resolver) {}
162
+ *
163
+ * send<TResult>(command: ICommand): Promise<TResult> {
164
+ * const handler = this.resolve<ICommandHandler<typeof command, TResult>>(
165
+ * command.resolverToken,
166
+ * );
167
+ * return handler.execute(command);
168
+ * }
169
+ * }
170
+
171
+ *
172
+ * @author Xeno
173
+ * @version 1.0.0
174
+ * @since 2025-09-30
175
+ * @link https://github.com/xeno-js/xeno-js
176
+ */
177
+ type Resolver<T = unknown> = (token: symbol) => T;
178
+ /**
179
+ * @description Async variant of `Resolver` for containers that resolve
180
+ * dependencies asynchronously (e.g. lazy module loading, remote config).
181
+ *
182
+ * @template T Narrows the resolved type at each call site.
183
+
184
+ *
185
+ * @author Xeno
186
+ * @version 1.0.0
187
+ * @since 2025-09-30
188
+ * @link https://github.com/xeno-js/xeno-js
189
+ */
190
+ type AsyncResolver = <T>(token: symbol) => Promise<T>;
191
+ /**
192
+ * @description Represents a globally unique identifier (GUID/UUID) as a string.
193
+ * The format is typically 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.
194
+
195
+ *
196
+ * @author Xeno
197
+ * @version 1.0.0
198
+ * @since 2025-09-30
199
+ * @link https://github.com/xeno-js/xeno-js
200
+ */
201
+ type Guid = `${string}-${string}-${string}-${string}-${string}`;
202
+ /**
203
+ * @description Represents a function that performs setup or configuration
204
+ * based on the provided options of type `T`.
205
+
206
+ *
207
+ * @author Xeno
208
+ * @version 1.0.0
209
+ * @since 2025-09-30
210
+ * @link https://github.com/xeno-js/xeno-js
211
+ */
212
+ type SetupAction<T, E = undefined> = (options: T, config: E) => void;
213
+
214
+ export type { AbstractConstructor as A, Constructor as C, Dictionary as D, Factory as F, Guid as G, KeysOfType as K, Maybe as M, Nullable as N, Optional as O, RequireKeys as R, SetupAction as S, AsyncFactory as a, AsyncResolver as b, Override as c, Resolver as d };
@@ -0,0 +1,230 @@
1
+ import { O as Optional, G as Guid, M as Maybe } from './common.types-DT8JtZ0E.js';
2
+ import { R as ResultType } from './result.types-DRyxvpQs.js';
3
+
4
+ /**
5
+ * @file auth.types.ts
6
+ * @description Defines types related to authentication and authorization.
7
+
8
+ *
9
+ * @author Xeno
10
+ * @version 1.0.0
11
+ * @since 2025-09-30
12
+ * @link https://github.com/xeno-js/xeno-js
13
+ */
14
+ /**
15
+ * @description An interface representing the claims associated with an authenticated user. This typically includes standard claims such as 'sub' (subject) and 'email', as well as any additional claims that may be relevant to the application's authorization logic.
16
+
17
+ *
18
+ * @author Xeno
19
+ * @version 1.0.0
20
+ * @since 2025-09-30
21
+ * @link https://github.com/xeno-js/xeno-js
22
+ */
23
+ interface AuthClaims {
24
+ /**
25
+ * The unique identifier for the user (subject).
26
+
27
+ *
28
+ * @author Xeno
29
+ * @version 1.0.0
30
+ * @since 2025-09-30
31
+ * @link https://github.com/xeno-js/xeno-js
32
+ */
33
+ readonly sub: string;
34
+ /**
35
+ * The user's email
36
+ *
37
+ * @author Xeno
38
+ * @version 1.0.0
39
+ * @since 2025-09-30
40
+ * @link https://github.com/xeno-js/xeno-js
41
+ */
42
+ readonly email: Optional<string>;
43
+ readonly name: Optional<string>;
44
+ /**
45
+ * The tenant ID associated with the user, if applicable. This is useful in multi-tenant applications to identify which tenant the user belongs to.
46
+
47
+ *
48
+ * @author Xeno
49
+ * @version 1.0.0
50
+ * @since 2025-09-30
51
+ * @link https://github.com/xeno-js/xeno-js
52
+ */
53
+ readonly tenantId: Optional<string>;
54
+ /**
55
+ * An array of roles assigned to the user. This can be used for role-based access control (RBAC) to determine what actions the user is authorized to perform.
56
+
57
+ *
58
+ * @author Xeno
59
+ * @version 1.0.0
60
+ * @since 2025-09-30
61
+ * @link https://github.com/xeno-js/xeno-js
62
+ */
63
+ readonly roles: Optional<string[]>;
64
+ /**
65
+ * An array of permissions assigned to the user. This can be used for permission-based access control to determine what specific operations the user is authorized to perform.
66
+
67
+ *
68
+ * @author Xeno
69
+ * @version 1.0.0
70
+ * @since 2025-09-30
71
+ * @link https://github.com/xeno-js/xeno-js
72
+ */
73
+ readonly permissions: Optional<string[]>;
74
+ }
75
+ /**
76
+ * @description An interface representing the context of an authenticated user, including their unique identifier and tenant ID. This context can be used throughout the application to enforce authorization rules and access control based on the user's identity and associated claims.
77
+ *
78
+ * @author Xeno
79
+ * @version 1.0.0
80
+ * @since 2025-09-30
81
+ * @link https://github.com/xeno-js/xeno-js
82
+ */
83
+ interface UserContext {
84
+ /**
85
+ * The unique identifier for the user (subject).
86
+ * @author Xeno
87
+ * @version 1.0.0
88
+ * @since 2025-09-30
89
+ * @link https://github.com/xeno-js/xeno-js
90
+ */
91
+ readonly userId: Optional<Guid>;
92
+ /**
93
+ * The tenant ID associated with the user, if applicable. This is useful in multi-tenant applications to identify which tenant the user belongs to.
94
+ * @author Xeno
95
+ * @version 1.0.0
96
+ * @since 2025-09-30
97
+ * @link https://github.com/xeno-js/xeno-js
98
+ */
99
+ readonly tenantId: Optional<Guid>;
100
+ }
101
+ interface Session {
102
+ readonly accessToken: string;
103
+ readonly refreshToken: string;
104
+ readonly expiresAt: Optional<number>;
105
+ readonly user: AuthClaims;
106
+ }
107
+ type Provider = 'apple' | 'discord' | 'facebook' | 'github' | 'gitlab' | 'google' | 'linkedin' | 'linkedin_oidc' | 'spotify';
108
+
109
+ /**
110
+ * @description Generic mapper interface defining a contract for mapping objects of type TSource to type TDestination. Mappers are used to convert data between different layers of the application, such as transforming DTOs to domain entities or vice versa. This interface defines a contract that all mappers must implement, ensuring consistency and maintainability of the code.
111
+ * @template TSource The type of the source object to be mapped.
112
+ * @template TDestination The type of the destination object resulting from the mapping.
113
+ * @example
114
+ * // Example of a UserMapper that maps a UserDTO to a UserEntity
115
+ * class UserMapper implements IBaseMapper<UserDTO, UserEntity> {
116
+ * map(source: UserDTO): UserEntity {
117
+ * // Mapping logic here
118
+ * }
119
+ * }
120
+
121
+ *
122
+ * @author Xeno
123
+ * @version 1.0.0
124
+ * @since 2025-09-30
125
+ * @link https://github.com/xeno-js/xeno-js
126
+ */
127
+ interface IBaseMapper<TSource, TDestination> {
128
+ /**
129
+ * @description Maps an object of type TSource to an object of type TDestination. The implementation of this method should contain the logic for transforming the source object into the desired destination format, which may involve copying properties, converting data types, or applying any necessary transformations to ensure that the resulting object is correctly structured for its intended use.
130
+ * @param source The source object of type TSource that needs to be mapped to type TDestination. This object contains the data that will be transformed and returned as a new object of the destination type.
131
+ * @returns An object of type TDestination that is the result of mapping the source object. The returned object should be a new instance that represents the transformed data according to the mapping logic defined in the implementation of this method.
132
+
133
+ *
134
+ * @author Xeno
135
+ * @version 1.0.0
136
+ * @since 2025-09-30
137
+ * @link https://github.com/xeno-js/xeno-js
138
+ */
139
+ map(source: TSource): TDestination;
140
+ }
141
+
142
+ /**
143
+ * @description IAuthService defines the contract for authentication services.
144
+ * It provides methods to check if a user is authenticated and to retrieve the user's claims.
145
+ *
146
+ * @author Xeno
147
+ * @version 1.0.0
148
+ * @since 2025-09-30
149
+ * @link https://github.com/xeno-js/xeno-js
150
+ */
151
+ interface IBaseAuthService {
152
+ /**
153
+ * Checks if the user is authenticated.
154
+ * @returns A promise that resolves to true if the user is authenticated, false otherwise.
155
+ *
156
+ * @author Xeno
157
+ * @version 1.0.0
158
+ * @since 2025-09-30
159
+ * @link https://github.com/xeno-js/xeno-js
160
+ */
161
+ isAuthenticated(): Promise<boolean>;
162
+ /**
163
+ * Retrieves the user's claims.
164
+ * @returns A promise that resolves to the user's claims, or null if not authenticated.
165
+ *
166
+ * @author Xeno
167
+ * @version 1.0.0
168
+ * @since 2025-09-30
169
+ * @link https://github.com/xeno-js/xeno-js
170
+ */
171
+ getUser(): Promise<ResultType<Maybe<AuthClaims>>>;
172
+ /**
173
+ * Authenticates a user based on a token.
174
+ * @param token The token to authenticate the user.
175
+ * @returns A promise that resolves to the user's claims, or null if not authenticated.
176
+ *
177
+ * @author Xeno
178
+ * @version 1.0.0
179
+ * @since 2025-09-30
180
+ * @link https://github.com/xeno-js/xeno-js
181
+ */
182
+ authenticate(token: string): Promise<ResultType<AuthClaims>>;
183
+ }
184
+ /**
185
+ * @description IAuthService defines the contract for authentication services.
186
+ * It provides methods to check if a user is authenticated and to retrieve the user's claims.
187
+
188
+ *
189
+ * @author Xeno
190
+ * @version 1.0.0
191
+ * @since 2025-09-30
192
+ * @link https://github.com/xeno-js/xeno-js
193
+ */
194
+ interface IAuthService {
195
+ /**
196
+ * Signs in a user by the specified provider.
197
+ * @param provider The provider to use for signing in the user.
198
+ * @returns A promise that resolves to the URL for the specified provider.
199
+ */
200
+ signInWithProvider(provider: Provider): Promise<ResultType<{
201
+ url: string;
202
+ }>>;
203
+ /**
204
+ * @description Gets the current session of the user.
205
+ * @returns A promise that resolves to the current session of the user.
206
+ */
207
+ getSession(): Promise<ResultType<Maybe<Session>>>;
208
+ /**
209
+ * @description Signs out the user.
210
+ * @returns A promise that resolves when the user is signed out.
211
+ */
212
+ signOut(): Promise<ResultType<void>>;
213
+ /**
214
+ * @description Exchanges the code for a session.
215
+ * @param code the code to exchange for a session
216
+ * @returns A promise that resolves to the session wit
217
+ */
218
+ exchangeCodeForSession(code: string): Promise<ResultType<Optional<Session>>>;
219
+ }
220
+ /**
221
+ * @description An extended version of the IAuthService interface that includes additional methods for managing user sessions.
222
+ * @author Xeno
223
+ * @version 1.0.0
224
+ * @since 2025-09-30
225
+ * @link https://github.com/xeno-js/xeno-js
226
+ */
227
+ interface IExtendendAuthService extends IBaseAuthService, IAuthService {
228
+ }
229
+
230
+ export type { AuthClaims as A, IAuthService as I, Provider as P, Session as S, UserContext as U, IBaseAuthService as a, IBaseMapper as b, IExtendendAuthService as c };
@@ -0,0 +1,230 @@
1
+ import { O as Optional, G as Guid, M as Maybe } from './common.types-DT8JtZ0E.cjs';
2
+ import { R as ResultType } from './result.types-BNTzjCgR.cjs';
3
+
4
+ /**
5
+ * @file auth.types.ts
6
+ * @description Defines types related to authentication and authorization.
7
+
8
+ *
9
+ * @author Xeno
10
+ * @version 1.0.0
11
+ * @since 2025-09-30
12
+ * @link https://github.com/xeno-js/xeno-js
13
+ */
14
+ /**
15
+ * @description An interface representing the claims associated with an authenticated user. This typically includes standard claims such as 'sub' (subject) and 'email', as well as any additional claims that may be relevant to the application's authorization logic.
16
+
17
+ *
18
+ * @author Xeno
19
+ * @version 1.0.0
20
+ * @since 2025-09-30
21
+ * @link https://github.com/xeno-js/xeno-js
22
+ */
23
+ interface AuthClaims {
24
+ /**
25
+ * The unique identifier for the user (subject).
26
+
27
+ *
28
+ * @author Xeno
29
+ * @version 1.0.0
30
+ * @since 2025-09-30
31
+ * @link https://github.com/xeno-js/xeno-js
32
+ */
33
+ readonly sub: string;
34
+ /**
35
+ * The user's email
36
+ *
37
+ * @author Xeno
38
+ * @version 1.0.0
39
+ * @since 2025-09-30
40
+ * @link https://github.com/xeno-js/xeno-js
41
+ */
42
+ readonly email: Optional<string>;
43
+ readonly name: Optional<string>;
44
+ /**
45
+ * The tenant ID associated with the user, if applicable. This is useful in multi-tenant applications to identify which tenant the user belongs to.
46
+
47
+ *
48
+ * @author Xeno
49
+ * @version 1.0.0
50
+ * @since 2025-09-30
51
+ * @link https://github.com/xeno-js/xeno-js
52
+ */
53
+ readonly tenantId: Optional<string>;
54
+ /**
55
+ * An array of roles assigned to the user. This can be used for role-based access control (RBAC) to determine what actions the user is authorized to perform.
56
+
57
+ *
58
+ * @author Xeno
59
+ * @version 1.0.0
60
+ * @since 2025-09-30
61
+ * @link https://github.com/xeno-js/xeno-js
62
+ */
63
+ readonly roles: Optional<string[]>;
64
+ /**
65
+ * An array of permissions assigned to the user. This can be used for permission-based access control to determine what specific operations the user is authorized to perform.
66
+
67
+ *
68
+ * @author Xeno
69
+ * @version 1.0.0
70
+ * @since 2025-09-30
71
+ * @link https://github.com/xeno-js/xeno-js
72
+ */
73
+ readonly permissions: Optional<string[]>;
74
+ }
75
+ /**
76
+ * @description An interface representing the context of an authenticated user, including their unique identifier and tenant ID. This context can be used throughout the application to enforce authorization rules and access control based on the user's identity and associated claims.
77
+ *
78
+ * @author Xeno
79
+ * @version 1.0.0
80
+ * @since 2025-09-30
81
+ * @link https://github.com/xeno-js/xeno-js
82
+ */
83
+ interface UserContext {
84
+ /**
85
+ * The unique identifier for the user (subject).
86
+ * @author Xeno
87
+ * @version 1.0.0
88
+ * @since 2025-09-30
89
+ * @link https://github.com/xeno-js/xeno-js
90
+ */
91
+ readonly userId: Optional<Guid>;
92
+ /**
93
+ * The tenant ID associated with the user, if applicable. This is useful in multi-tenant applications to identify which tenant the user belongs to.
94
+ * @author Xeno
95
+ * @version 1.0.0
96
+ * @since 2025-09-30
97
+ * @link https://github.com/xeno-js/xeno-js
98
+ */
99
+ readonly tenantId: Optional<Guid>;
100
+ }
101
+ interface Session {
102
+ readonly accessToken: string;
103
+ readonly refreshToken: string;
104
+ readonly expiresAt: Optional<number>;
105
+ readonly user: AuthClaims;
106
+ }
107
+ type Provider = 'apple' | 'discord' | 'facebook' | 'github' | 'gitlab' | 'google' | 'linkedin' | 'linkedin_oidc' | 'spotify';
108
+
109
+ /**
110
+ * @description Generic mapper interface defining a contract for mapping objects of type TSource to type TDestination. Mappers are used to convert data between different layers of the application, such as transforming DTOs to domain entities or vice versa. This interface defines a contract that all mappers must implement, ensuring consistency and maintainability of the code.
111
+ * @template TSource The type of the source object to be mapped.
112
+ * @template TDestination The type of the destination object resulting from the mapping.
113
+ * @example
114
+ * // Example of a UserMapper that maps a UserDTO to a UserEntity
115
+ * class UserMapper implements IBaseMapper<UserDTO, UserEntity> {
116
+ * map(source: UserDTO): UserEntity {
117
+ * // Mapping logic here
118
+ * }
119
+ * }
120
+
121
+ *
122
+ * @author Xeno
123
+ * @version 1.0.0
124
+ * @since 2025-09-30
125
+ * @link https://github.com/xeno-js/xeno-js
126
+ */
127
+ interface IBaseMapper<TSource, TDestination> {
128
+ /**
129
+ * @description Maps an object of type TSource to an object of type TDestination. The implementation of this method should contain the logic for transforming the source object into the desired destination format, which may involve copying properties, converting data types, or applying any necessary transformations to ensure that the resulting object is correctly structured for its intended use.
130
+ * @param source The source object of type TSource that needs to be mapped to type TDestination. This object contains the data that will be transformed and returned as a new object of the destination type.
131
+ * @returns An object of type TDestination that is the result of mapping the source object. The returned object should be a new instance that represents the transformed data according to the mapping logic defined in the implementation of this method.
132
+
133
+ *
134
+ * @author Xeno
135
+ * @version 1.0.0
136
+ * @since 2025-09-30
137
+ * @link https://github.com/xeno-js/xeno-js
138
+ */
139
+ map(source: TSource): TDestination;
140
+ }
141
+
142
+ /**
143
+ * @description IAuthService defines the contract for authentication services.
144
+ * It provides methods to check if a user is authenticated and to retrieve the user's claims.
145
+ *
146
+ * @author Xeno
147
+ * @version 1.0.0
148
+ * @since 2025-09-30
149
+ * @link https://github.com/xeno-js/xeno-js
150
+ */
151
+ interface IBaseAuthService {
152
+ /**
153
+ * Checks if the user is authenticated.
154
+ * @returns A promise that resolves to true if the user is authenticated, false otherwise.
155
+ *
156
+ * @author Xeno
157
+ * @version 1.0.0
158
+ * @since 2025-09-30
159
+ * @link https://github.com/xeno-js/xeno-js
160
+ */
161
+ isAuthenticated(): Promise<boolean>;
162
+ /**
163
+ * Retrieves the user's claims.
164
+ * @returns A promise that resolves to the user's claims, or null if not authenticated.
165
+ *
166
+ * @author Xeno
167
+ * @version 1.0.0
168
+ * @since 2025-09-30
169
+ * @link https://github.com/xeno-js/xeno-js
170
+ */
171
+ getUser(): Promise<ResultType<Maybe<AuthClaims>>>;
172
+ /**
173
+ * Authenticates a user based on a token.
174
+ * @param token The token to authenticate the user.
175
+ * @returns A promise that resolves to the user's claims, or null if not authenticated.
176
+ *
177
+ * @author Xeno
178
+ * @version 1.0.0
179
+ * @since 2025-09-30
180
+ * @link https://github.com/xeno-js/xeno-js
181
+ */
182
+ authenticate(token: string): Promise<ResultType<AuthClaims>>;
183
+ }
184
+ /**
185
+ * @description IAuthService defines the contract for authentication services.
186
+ * It provides methods to check if a user is authenticated and to retrieve the user's claims.
187
+
188
+ *
189
+ * @author Xeno
190
+ * @version 1.0.0
191
+ * @since 2025-09-30
192
+ * @link https://github.com/xeno-js/xeno-js
193
+ */
194
+ interface IAuthService {
195
+ /**
196
+ * Signs in a user by the specified provider.
197
+ * @param provider The provider to use for signing in the user.
198
+ * @returns A promise that resolves to the URL for the specified provider.
199
+ */
200
+ signInWithProvider(provider: Provider): Promise<ResultType<{
201
+ url: string;
202
+ }>>;
203
+ /**
204
+ * @description Gets the current session of the user.
205
+ * @returns A promise that resolves to the current session of the user.
206
+ */
207
+ getSession(): Promise<ResultType<Maybe<Session>>>;
208
+ /**
209
+ * @description Signs out the user.
210
+ * @returns A promise that resolves when the user is signed out.
211
+ */
212
+ signOut(): Promise<ResultType<void>>;
213
+ /**
214
+ * @description Exchanges the code for a session.
215
+ * @param code the code to exchange for a session
216
+ * @returns A promise that resolves to the session wit
217
+ */
218
+ exchangeCodeForSession(code: string): Promise<ResultType<Optional<Session>>>;
219
+ }
220
+ /**
221
+ * @description An extended version of the IAuthService interface that includes additional methods for managing user sessions.
222
+ * @author Xeno
223
+ * @version 1.0.0
224
+ * @since 2025-09-30
225
+ * @link https://github.com/xeno-js/xeno-js
226
+ */
227
+ interface IExtendendAuthService extends IBaseAuthService, IAuthService {
228
+ }
229
+
230
+ export type { AuthClaims as A, IAuthService as I, Provider as P, Session as S, UserContext as U, IBaseAuthService as a, IBaseMapper as b, IExtendendAuthService as c };