@alepha/react 0.12.0 → 0.13.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.
Files changed (85) hide show
  1. package/dist/auth/chunk-DhGyd7sr.js +28 -0
  2. package/dist/auth/index.browser.js +394 -114
  3. package/dist/auth/index.browser.js.map +1 -1
  4. package/dist/auth/index.cjs +80 -1927
  5. package/dist/auth/index.cjs.map +1 -1
  6. package/dist/auth/index.d.cts +1130 -420
  7. package/dist/auth/index.d.ts +1130 -420
  8. package/dist/auth/index.js +72 -1918
  9. package/dist/auth/index.js.map +1 -1
  10. package/dist/core/chunk-DhGyd7sr.js +28 -0
  11. package/dist/core/index.browser.js +79 -79
  12. package/dist/core/index.browser.js.map +1 -1
  13. package/dist/core/index.cjs +89 -85
  14. package/dist/core/index.cjs.map +1 -1
  15. package/dist/core/index.d.cts +1654 -154
  16. package/dist/core/index.d.ts +1654 -154
  17. package/dist/core/index.js +79 -79
  18. package/dist/core/index.js.map +1 -1
  19. package/dist/form/chunk-DhGyd7sr.js +28 -0
  20. package/dist/form/index.cjs +28 -8
  21. package/dist/form/index.cjs.map +1 -1
  22. package/dist/form/index.d.cts +215 -7
  23. package/dist/form/index.d.ts +215 -7
  24. package/dist/form/index.js +18 -3
  25. package/dist/form/index.js.map +1 -1
  26. package/dist/head/chunk-DhGyd7sr.js +28 -0
  27. package/dist/head/index.browser.js +385 -59
  28. package/dist/head/index.browser.js.map +1 -1
  29. package/dist/head/index.cjs +12 -8
  30. package/dist/head/index.cjs.map +1 -1
  31. package/dist/head/index.d.cts +1230 -24
  32. package/dist/head/index.d.ts +1230 -29
  33. package/dist/head/index.js +2 -2
  34. package/dist/head/index.js.map +1 -1
  35. package/dist/i18n/chunk-DhGyd7sr.js +28 -0
  36. package/dist/i18n/index.cjs +33 -20
  37. package/dist/i18n/index.cjs.map +1 -1
  38. package/dist/i18n/index.d.cts +282 -13
  39. package/dist/i18n/index.d.ts +282 -13
  40. package/dist/i18n/index.js +23 -14
  41. package/dist/i18n/index.js.map +1 -1
  42. package/dist/websocket/index.cjs +21 -8
  43. package/dist/websocket/index.cjs.map +1 -1
  44. package/dist/websocket/index.js +11 -2
  45. package/dist/websocket/index.js.map +1 -1
  46. package/package.json +7 -6
  47. package/src/auth/index.browser.ts +3 -6
  48. package/src/auth/index.shared.ts +0 -1
  49. package/src/auth/index.ts +3 -16
  50. package/src/auth/providers/ReactAuthProvider.ts +1 -614
  51. package/src/auth/services/ReactAuth.ts +6 -17
  52. package/src/core/descriptors/$page.ts +1 -1
  53. package/src/core/index.browser.ts +1 -0
  54. package/src/core/index.native.ts +21 -0
  55. package/src/core/index.shared-router.ts +15 -0
  56. package/src/core/index.shared.ts +0 -14
  57. package/src/core/index.ts +1 -0
  58. package/src/core/services/ReactRouter.ts +2 -2
  59. package/src/form/errors/FormValidationError.ts +20 -0
  60. package/src/form/hooks/useForm.ts +1 -1
  61. package/src/form/index.ts +1 -0
  62. package/src/head/providers/BrowserHeadProvider.ts +1 -1
  63. package/src/i18n/descriptors/$dictionary.ts +7 -3
  64. package/src/i18n/providers/I18nProvider.ts +9 -10
  65. package/src/websocket/hooks/useRoom.tsx +21 -2
  66. package/dist/auth/index.d.cts.map +0 -1
  67. package/dist/auth/index.d.ts.map +0 -1
  68. package/dist/core/index.d.cts.map +0 -1
  69. package/dist/core/index.d.ts.map +0 -1
  70. package/dist/form/index.d.cts.map +0 -1
  71. package/dist/form/index.d.ts.map +0 -1
  72. package/dist/head/index.d.cts.map +0 -1
  73. package/dist/head/index.d.ts.map +0 -1
  74. package/dist/i18n/index.d.cts.map +0 -1
  75. package/dist/i18n/index.d.ts.map +0 -1
  76. package/dist/websocket/index.d.cts.map +0 -1
  77. package/dist/websocket/index.d.ts.map +0 -1
  78. package/src/auth/descriptors/$auth.ts +0 -436
  79. package/src/auth/descriptors/$authApple.ts +0 -8
  80. package/src/auth/descriptors/$authGithub.ts +0 -81
  81. package/src/auth/descriptors/$authGoogle.ts +0 -38
  82. package/src/auth/errors/SessionExpiredError.ts +0 -6
  83. package/src/auth/schemas/tokenResponseSchema.ts +0 -11
  84. package/src/auth/schemas/tokensSchema.ts +0 -21
  85. package/src/auth/schemas/userinfoResponseSchema.ts +0 -10
@@ -1,519 +1,1126 @@
1
- import * as alepha4 from "alepha";
2
- import { Alepha, AlephaError, Async, Descriptor, KIND, Static } from "alepha";
3
- import { AccessTokenResponse, RealmDescriptor, SecurityProvider, UserAccount, UserAccountToken } from "alepha/security";
4
- import { DateTimeProvider } from "alepha/datetime";
5
- import { Configuration } from "openid-client";
6
- import * as alepha_logger0 from "alepha/logger";
7
- import * as typebox143 from "typebox";
8
- import * as alepha_server_cookies0 from "alepha/server/cookies";
9
- import { Cookies, ServerCookiesProvider } from "alepha/server/cookies";
10
- import * as alepha_server0 from "alepha/server";
11
- import { HttpClient } from "alepha/server";
12
- import { HttpVirtualClient, ServerLinksProvider } from "alepha/server/links";
1
+ import * as alepha20 from "alepha";
2
+ import { Alepha, AlephaError, Async, Descriptor, FileLike, InstantiableClass, LogLevel, LoggerInterface, Static, StreamLike, TArray, TFile, TObject, TRecord, TSchema, TStream, TString, TVoid } from "alepha";
3
+ import dayjsDuration from "dayjs/plugin/duration.js";
4
+ import DayjsApi, { Dayjs, ManipulateType, PluginFunc } from "dayjs";
5
+ import { IncomingMessage, Server, ServerResponse } from "node:http";
6
+ import { Readable } from "node:stream";
7
+ import { ReadableStream } from "node:stream/web";
13
8
 
14
- //#region src/auth/schemas/tokensSchema.d.ts
15
- declare const tokensSchema: typebox143.TObject<{
16
- provider: typebox143.TString;
17
- access_token: typebox143.TString;
18
- issued_at: typebox143.TNumber;
19
- expires_in: typebox143.TOptional<typebox143.TNumber>;
20
- refresh_token: typebox143.TOptional<typebox143.TString>;
21
- refresh_token_expires_in: typebox143.TOptional<typebox143.TNumber>;
22
- refresh_expires_in: typebox143.TOptional<typebox143.TNumber>;
23
- id_token: typebox143.TOptional<typebox143.TString>;
24
- scope: typebox143.TOptional<typebox143.TString>;
9
+ //#region ../alepha/src/security/schemas/userAccountInfoSchema.d.ts
10
+ declare const userAccountInfoSchema: alepha20.TObject<{
11
+ id: alepha20.TString;
12
+ name: alepha20.TOptional<alepha20.TString>;
13
+ email: alepha20.TOptional<alepha20.TString>;
14
+ username: alepha20.TOptional<alepha20.TString>;
15
+ picture: alepha20.TOptional<alepha20.TString>;
16
+ sessionId: alepha20.TOptional<alepha20.TString>;
17
+ organizations: alepha20.TOptional<alepha20.TArray<alepha20.TString>>;
18
+ roles: alepha20.TOptional<alepha20.TArray<alepha20.TString>>;
25
19
  }>;
26
- type Tokens = Static<typeof tokensSchema>;
20
+ type UserAccount = Static<typeof userAccountInfoSchema>;
27
21
  //#endregion
28
- //#region src/auth/services/ReactAuth.d.ts
29
- /**
30
- * Browser, SSR friendly, service to handle authentication.
31
- */
32
- declare class ReactAuth {
33
- protected readonly log: alepha_logger0.Logger;
34
- protected readonly alepha: Alepha;
35
- protected readonly httpClient: HttpClient;
36
- static path: {
37
- login: string;
38
- callback: string;
39
- logout: string;
40
- token: string;
41
- refresh: string;
42
- userinfo: string;
43
- };
44
- protected readonly onBeginTransition: alepha4.HookDescriptor<"react:transition:begin">;
45
- protected readonly onFetchRequest: alepha4.HookDescriptor<"client:onRequest">;
22
+ //#region ../alepha/src/logger/schemas/logEntrySchema.d.ts
23
+ declare const logEntrySchema: alepha20.TObject<{
24
+ level: alepha20.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
25
+ message: alepha20.TString;
26
+ service: alepha20.TString;
27
+ module: alepha20.TString;
28
+ context: alepha20.TOptional<alepha20.TString>;
29
+ app: alepha20.TOptional<alepha20.TString>;
30
+ data: alepha20.TOptional<alepha20.TAny>;
31
+ timestamp: alepha20.TNumber;
32
+ }>;
33
+ type LogEntry = Static<typeof logEntrySchema>;
34
+ //#endregion
35
+ //#region ../alepha/src/datetime/providers/DateTimeProvider.d.ts
36
+ type DateTime = DayjsApi.Dayjs;
37
+ type Duration = dayjsDuration.Duration;
38
+ type DurationLike = number | dayjsDuration.Duration | [number, ManipulateType];
39
+ declare class DateTimeProvider {
40
+ static PLUGINS: Array<PluginFunc<any>>;
41
+ protected alepha: Alepha;
42
+ protected ref: DateTime | null;
43
+ protected readonly timeouts: Timeout[];
44
+ protected readonly intervals: Interval[];
45
+ constructor();
46
+ protected readonly onStart: alepha20.HookDescriptor<"start">;
47
+ protected readonly onStop: alepha20.HookDescriptor<"stop">;
48
+ setLocale(locale: string): void;
49
+ isDateTime(value: unknown): value is DateTime;
46
50
  /**
47
- * Get the current authenticated user.
51
+ * Create a new UTC DateTime instance.
52
+ */
53
+ utc(date: string | number | Date | Dayjs | null | undefined): DateTime;
54
+ /**
55
+ * Create a new DateTime instance.
56
+ */
57
+ of(date: string | number | Date | Dayjs | null | undefined): DateTime;
58
+ /**
59
+ * Get the current date as a string.
60
+ */
61
+ toISOString(date?: Date | string | DateTime): string;
62
+ /**
63
+ * Get the current date.
64
+ */
65
+ now(): DateTime;
66
+ /**
67
+ * Get the current date as a string.
48
68
  *
49
- * Alias for `alepha.state.get("user")`
69
+ * This is much faster than `DateTimeProvider.now().toISOString()` as it avoids creating a DateTime instance.
50
70
  */
51
- get user(): UserAccountToken | undefined;
52
- ping(): Promise<{
53
- name?: string | undefined;
54
- email?: string | undefined;
55
- username?: string | undefined;
56
- picture?: string | undefined;
57
- sessionId?: string | undefined;
58
- organizations?: string[] | undefined;
59
- roles?: string[] | undefined;
60
- id: string;
61
- } | undefined>;
62
- login(provider: string, options: {
63
- hostname?: string;
64
- username?: string;
65
- password?: string;
66
- redirect?: string;
67
- [extra: string]: any;
68
- }): Promise<Tokens>;
69
- logout(): void;
71
+ nowISOString(): string;
72
+ /**
73
+ * Get the current date as milliseconds since epoch.
74
+ *
75
+ * This is much faster than `DateTimeProvider.now().valueOf()` as it avoids creating a DateTime instance.
76
+ */
77
+ nowMillis(): number;
78
+ /**
79
+ * Get the current date as a string.
80
+ *
81
+ * @protected
82
+ */
83
+ protected getCurrentDate(): DateTime;
84
+ /**
85
+ * Create a new Duration instance.
86
+ */
87
+ duration: (duration: DurationLike, unit?: ManipulateType) => Duration;
88
+ isDurationLike(value: unknown): value is DurationLike;
89
+ /**
90
+ * Return a promise that resolves after the next tick.
91
+ * It uses `setTimeout` with 0 ms delay.
92
+ */
93
+ tick(): Promise<void>;
94
+ /**
95
+ * Wait for a certain duration.
96
+ *
97
+ * You can clear the timeout by using the `AbortSignal` API.
98
+ * Aborted signal will resolve the promise immediately, it does not reject it.
99
+ */
100
+ wait(duration: DurationLike, options?: {
101
+ signal?: AbortSignal;
102
+ now?: number;
103
+ }): Promise<void>;
104
+ createInterval(run: () => unknown, duration: DurationLike, start?: boolean): Interval;
105
+ /**
106
+ * Run a callback after a certain duration.
107
+ */
108
+ createTimeout(callback: () => void, duration: DurationLike, now?: number): Timeout;
109
+ clearTimeout(timeout: Timeout): void;
110
+ clearInterval(interval: Interval): void;
111
+ /**
112
+ * Run a function with a deadline.
113
+ */
114
+ deadline<T>(fn: (signal: AbortSignal) => Promise<T>, duration: DurationLike): Promise<T>;
115
+ /**
116
+ * Add time to the current date.
117
+ */
118
+ travel(duration: DurationLike, unit?: ManipulateType): Promise<void>;
119
+ /**
120
+ * Stop the time.
121
+ */
122
+ pause(): DateTime;
123
+ /**
124
+ * Reset the reference date.
125
+ */
126
+ reset(): void;
127
+ }
128
+ interface Interval {
129
+ timer?: any;
130
+ duration: number;
131
+ run: () => unknown;
132
+ }
133
+ interface Timeout {
134
+ now: number;
135
+ timer?: any;
136
+ duration: number;
137
+ callback: () => void;
138
+ clear: () => void;
70
139
  }
71
140
  //#endregion
72
- //#region src/auth/providers/ReactAuthProvider.d.ts
73
- declare class ReactAuthProvider {
74
- protected readonly log: alepha_logger0.Logger;
141
+ //#region ../alepha/src/logger/providers/LogDestinationProvider.d.ts
142
+ declare abstract class LogDestinationProvider {
143
+ abstract write(message: string, entry: LogEntry): void;
144
+ }
145
+ //#endregion
146
+ //#region ../alepha/src/logger/providers/LogFormatterProvider.d.ts
147
+ declare abstract class LogFormatterProvider {
148
+ abstract format(entry: LogEntry): string;
149
+ }
150
+ //#endregion
151
+ //#region ../alepha/src/logger/services/Logger.d.ts
152
+ declare class Logger implements LoggerInterface {
75
153
  protected readonly alepha: Alepha;
76
- protected readonly serverCookiesProvider: ServerCookiesProvider;
154
+ protected readonly formatter: LogFormatterProvider;
155
+ protected readonly destination: LogDestinationProvider;
77
156
  protected readonly dateTimeProvider: DateTimeProvider;
78
- protected readonly serverLinksProvider: ServerLinksProvider;
79
- protected readonly reactAuth: ReactAuth;
80
- protected readonly authorizationCode: alepha_server_cookies0.AbstractCookieDescriptor<typebox143.TObject<{
81
- provider: typebox143.TString;
82
- codeVerifier: typebox143.TOptional<typebox143.TString>;
83
- redirectUri: typebox143.TOptional<typebox143.TString>;
84
- state: typebox143.TOptional<typebox143.TString>;
85
- nonce: typebox143.TOptional<typebox143.TString>;
86
- }>>;
87
- readonly tokens: alepha_server_cookies0.AbstractCookieDescriptor<typebox143.TObject<{
88
- provider: typebox143.TString;
89
- access_token: typebox143.TString;
90
- issued_at: typebox143.TNumber;
91
- expires_in: typebox143.TOptional<typebox143.TNumber>;
92
- refresh_token: typebox143.TOptional<typebox143.TString>;
93
- refresh_token_expires_in: typebox143.TOptional<typebox143.TNumber>;
94
- refresh_expires_in: typebox143.TOptional<typebox143.TNumber>;
95
- id_token: typebox143.TOptional<typebox143.TString>;
96
- scope: typebox143.TOptional<typebox143.TString>;
97
- }>>;
98
- readonly onRender: alepha4.HookDescriptor<"react:server:render:begin">;
99
- get identities(): Array<AuthDescriptor>;
100
- protected readonly configure: alepha4.HookDescriptor<"configure">;
101
- protected getAccessTokens(tokens: Tokens): string | undefined;
102
- /**
103
- * Fill request headers with access token from cookies or fallback to provider's fallback function.
104
- */
105
- protected readonly onRequest: alepha4.HookDescriptor<"server:onRequest">;
106
- /**
107
- * Convert cookies to tokens.
108
- * If the tokens are expired, try to refresh them using the refresh token.
109
- */
110
- protected cookiesToTokens(cookies: Cookies): Promise<Tokens | undefined>;
111
- protected refreshTokens(tokens: Tokens): Promise<Tokens | undefined>;
112
- /**
113
- * Get user information.
114
- */
115
- readonly userinfo: alepha_server0.RouteDescriptor<{
116
- response: typebox143.TObject<{
117
- user: typebox143.TOptional<typebox143.TObject<{
118
- id: typebox143.TString;
119
- name: typebox143.TOptional<typebox143.TString>;
120
- email: typebox143.TOptional<typebox143.TString>;
121
- username: typebox143.TOptional<typebox143.TString>;
122
- picture: typebox143.TOptional<typebox143.TString>;
123
- sessionId: typebox143.TOptional<typebox143.TString>;
124
- organizations: typebox143.TOptional<typebox143.TArray<typebox143.TString>>;
125
- roles: typebox143.TOptional<typebox143.TArray<typebox143.TString>>;
126
- }>>;
127
- api: typebox143.TObject<{
128
- prefix: typebox143.TOptional<typebox143.TString>;
129
- links: typebox143.TArray<typebox143.TObject<{
130
- name: typebox143.TString;
131
- group: typebox143.TOptional<typebox143.TString>;
132
- path: typebox143.TString;
133
- method: typebox143.TOptional<typebox143.TString>;
134
- requestBodyType: typebox143.TOptional<typebox143.TString>;
135
- service: typebox143.TOptional<typebox143.TString>;
136
- }>>;
137
- }>;
138
- }>;
139
- }>;
157
+ protected readonly levels: Record<string, number>;
158
+ protected readonly service: string;
159
+ protected readonly module: string;
160
+ protected readonly app?: string;
161
+ protected appLogLevel: string;
162
+ protected logLevel: LogLevel;
163
+ constructor(service: string, module: string);
164
+ get context(): string | undefined;
165
+ get level(): string;
166
+ parseLevel(level: string, app: string): LogLevel;
167
+ private matchesPattern;
168
+ asLogLevel(something: string): LogLevel;
169
+ error(message: string, data?: unknown): void;
170
+ warn(message: string, data?: unknown): void;
171
+ info(message: string, data?: unknown): void;
172
+ debug(message: string, data?: unknown): void;
173
+ trace(message: string, data?: unknown): void;
174
+ protected log(level: LogLevel, message: string, data?: unknown): void;
175
+ protected emit(entry: LogEntry, message?: string): void;
176
+ }
177
+ //#endregion
178
+ //#region ../alepha/src/logger/index.d.ts
179
+ declare const envSchema$3: alepha20.TObject<{
140
180
  /**
141
- * Refresh a token for internal providers.
142
- */
143
- readonly refresh: alepha_server0.RouteDescriptor<{
144
- query: typebox143.TObject<{
145
- provider: typebox143.TString;
146
- }>;
147
- body: typebox143.TObject<{
148
- refresh_token: typebox143.TString;
149
- access_token: typebox143.TOptional<typebox143.TString>;
150
- }>;
151
- response: typebox143.TObject<{
152
- provider: typebox143.TString;
153
- access_token: typebox143.TString;
154
- issued_at: typebox143.TNumber;
155
- expires_in: typebox143.TOptional<typebox143.TNumber>;
156
- refresh_token: typebox143.TOptional<typebox143.TString>;
157
- refresh_token_expires_in: typebox143.TOptional<typebox143.TNumber>;
158
- refresh_expires_in: typebox143.TOptional<typebox143.TNumber>;
159
- id_token: typebox143.TOptional<typebox143.TString>;
160
- scope: typebox143.TOptional<typebox143.TString>;
161
- }>;
162
- }>;
181
+ * Default log level for the application.
182
+ *
183
+ * Default by environment:
184
+ * - dev = info
185
+ * - prod = info
186
+ * - test = error
187
+ *
188
+ * Levels are: "trace" | "debug" | "info" | "warn" | "error" | "silent"
189
+ *
190
+ * Level can be set for a specific module:
191
+ *
192
+ * @example
193
+ * LOG_LEVEL=my.module.name:debug,info # Set debug level for my.module.name and info for all other modules
194
+ * LOG_LEVEL=alepha:trace, info # Set trace level for all alepha modules and info for all other modules
195
+ */
196
+ LOG_LEVEL: alepha20.TOptional<alepha20.TString>;
163
197
  /**
164
- * Login for local password-based authentication.
165
- */
166
- readonly token: alepha_server0.RouteDescriptor<{
167
- query: typebox143.TObject<{
168
- provider: typebox143.TString;
169
- }>;
170
- body: typebox143.TObject<{
171
- username: typebox143.TString;
172
- password: typebox143.TString;
173
- }>;
174
- response: typebox143.TObject<{
175
- provider: typebox143.TString;
176
- access_token: typebox143.TString;
177
- issued_at: typebox143.TNumber;
178
- expires_in: typebox143.TOptional<typebox143.TNumber>;
179
- refresh_token: typebox143.TOptional<typebox143.TString>;
180
- refresh_token_expires_in: typebox143.TOptional<typebox143.TNumber>;
181
- refresh_expires_in: typebox143.TOptional<typebox143.TNumber>;
182
- id_token: typebox143.TOptional<typebox143.TString>;
183
- scope: typebox143.TOptional<typebox143.TString>;
184
- user: typebox143.TObject<{
185
- id: typebox143.TString;
186
- name: typebox143.TOptional<typebox143.TString>;
187
- email: typebox143.TOptional<typebox143.TString>;
188
- username: typebox143.TOptional<typebox143.TString>;
189
- picture: typebox143.TOptional<typebox143.TString>;
190
- sessionId: typebox143.TOptional<typebox143.TString>;
191
- organizations: typebox143.TOptional<typebox143.TArray<typebox143.TString>>;
192
- roles: typebox143.TOptional<typebox143.TArray<typebox143.TString>>;
193
- }>;
194
- api: typebox143.TObject<{
195
- prefix: typebox143.TOptional<typebox143.TString>;
196
- links: typebox143.TArray<typebox143.TObject<{
197
- name: typebox143.TString;
198
- group: typebox143.TOptional<typebox143.TString>;
199
- path: typebox143.TString;
200
- method: typebox143.TOptional<typebox143.TString>;
201
- requestBodyType: typebox143.TOptional<typebox143.TString>;
202
- service: typebox143.TOptional<typebox143.TString>;
203
- }>>;
204
- }>;
205
- }>;
206
- }>;
198
+ * Built-in log formats.
199
+ * - "json" - JSON format, useful for structured logging and log aggregation. {@link JsonFormatterProvider}
200
+ * - "pretty" - Simple text format, human-readable, with colors. {@link SimpleFormatterProvider}
201
+ * - "raw" - Raw format, no formatting, just the message. {@link RawFormatterProvider}
202
+ */
203
+ LOG_FORMAT: alepha20.TOptional<alepha20.TUnsafe<"json" | "pretty" | "raw">>;
204
+ }>;
205
+ declare module "alepha" {
206
+ interface Env extends Partial<Static<typeof envSchema$3>> {}
207
+ interface State {
208
+ /**
209
+ * Current log level for the application or specific modules.
210
+ */
211
+ "alepha.logger.level"?: string;
212
+ }
213
+ interface Hooks {
214
+ log: {
215
+ message?: string;
216
+ entry: LogEntry;
217
+ };
218
+ }
219
+ }
220
+ //#endregion
221
+ //#region ../alepha/src/security/interfaces/UserAccountToken.d.ts
222
+ /**
223
+ * Add contextual metadata to a user account info.
224
+ * E.g. UserAccountToken is a UserAccountInfo during a request.
225
+ */
226
+ interface UserAccountToken extends UserAccount {
207
227
  /**
208
- * Oauth2/OIDC login route.
228
+ * Access token for the user.
209
229
  */
210
- readonly login: alepha_server0.RouteDescriptor<{
211
- query: typebox143.TObject<{
212
- provider: typebox143.TString;
213
- redirect_uri: typebox143.TOptional<typebox143.TString>;
214
- }>;
215
- }>;
230
+ token?: string;
216
231
  /**
217
- * Callback for OAuth2/OIDC providers.
218
- * It handles the authorization code flow and retrieves the access token.
232
+ * Realm name of the user.
219
233
  */
220
- readonly callback: alepha_server0.RouteDescriptor<alepha_server0.RequestConfigSchema>;
234
+ realm?: string;
221
235
  /**
222
- * Logout route for OAuth2/OIDC providers.
236
+ * Is user dedicated to his own resources for this scope ?
237
+ * Mostly, Admin is false and Customer is true.
223
238
  */
224
- readonly logout: alepha_server0.RouteDescriptor<{
225
- query: typebox143.TObject<{
226
- post_logout_redirect_uri: typebox143.TOptional<typebox143.TString>;
227
- }>;
228
- }>;
229
- protected provider(opts: string | {
230
- provider: string;
231
- }): AuthDescriptor;
232
- protected setTokens(tokens: Tokens, cookies?: Cookies): void;
233
- }
234
- interface OAuth2Profile {
235
- sub: string;
236
- email?: string;
237
- name?: string;
238
- given_name?: string;
239
- family_name?: string;
240
- middle_name?: string;
241
- nickname?: string;
242
- preferred_username?: string;
243
- profile?: string;
244
- picture?: string;
245
- website?: string;
246
- email_verified?: boolean;
247
- gender?: string;
248
- birthdate?: string;
249
- zoneinfo?: string;
250
- locale?: string;
251
- phone_number?: string;
252
- phone_number_verified?: boolean;
253
- address?: {
254
- formatted?: string;
255
- street_address?: string;
256
- locality?: string;
257
- region?: string;
258
- postal_code?: string;
259
- country?: string;
239
+ ownership?: string | boolean;
240
+ }
241
+ //#endregion
242
+ //#region ../alepha/src/security/providers/SecurityProvider.d.ts
243
+ declare const envSchema$2: alepha20.TObject<{
244
+ APP_SECRET: alepha20.TString;
245
+ }>;
246
+ declare module "alepha" {
247
+ interface Env extends Partial<Static<typeof envSchema$2>> {}
248
+ }
249
+ //#endregion
250
+ //#region ../alepha/src/server/constants/routeMethods.d.ts
251
+ declare const routeMethods: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "CONNECT", "TRACE"];
252
+ type RouteMethod = (typeof routeMethods)[number];
253
+ //#endregion
254
+ //#region ../alepha/src/router/providers/RouterProvider.d.ts
255
+ declare abstract class RouterProvider<T extends Route = Route> {
256
+ protected routePathRegex: RegExp;
257
+ protected tree: Tree<T>;
258
+ protected cache: Map<string, RouteMatch<T>>;
259
+ match(path: string): RouteMatch<T>;
260
+ protected test(path: string): void;
261
+ protected push(route: T): void;
262
+ protected createRouteMatch(path: string): RouteMatch<T>;
263
+ protected mapParams(match: RouteMatch<T>): RouteMatch<T>;
264
+ protected createParts(path: string): string[];
265
+ }
266
+ interface RouteMatch<T extends Route> {
267
+ route?: T;
268
+ params?: Record<string, string>;
269
+ }
270
+ interface Route {
271
+ path: string;
272
+ /**
273
+ * Rename a param in the route.
274
+ * This is automatically filled when you have scenarios like:
275
+ * `/customers/:id` and `/customers/:userId/payments`
276
+ *
277
+ * In this case, `:id` will be renamed to `:userId` in the second route.
278
+ */
279
+ mapParams?: Record<string, string>;
280
+ }
281
+ interface Tree<T extends Route> {
282
+ route?: T;
283
+ children: {
284
+ [key: string]: Tree<T>;
285
+ };
286
+ param?: {
287
+ route?: T;
288
+ name: string;
289
+ children: {
290
+ [key: string]: Tree<T>;
291
+ };
292
+ };
293
+ wildcard?: {
294
+ route: T;
260
295
  };
261
- updated_at?: number;
262
- [key: string]: unknown;
263
296
  }
264
297
  //#endregion
265
- //#region src/auth/descriptors/$auth.d.ts
298
+ //#region ../alepha/src/server/helpers/ServerReply.d.ts
266
299
  /**
267
- * Creates an authentication provider descriptor for handling user login flows.
268
- *
269
- * Supports multiple authentication strategies: credentials (username/password), OAuth2,
270
- * and OIDC (OpenID Connect). Handles token management, user profile retrieval, and
271
- * integration with both external identity providers (Auth0, Keycloak) and internal realms.
272
- *
273
- * **Authentication Types**: Credentials, OAuth2 (Google, GitHub), OIDC, External providers
274
- *
275
- * @example
276
- * ```ts
277
- * class AuthProviders {
278
- * // Internal credentials-based auth
279
- * credentials = $auth({
280
- * realm: this.userRealm,
281
- * credentials: {
282
- * account: async ({ username, password }) => {
283
- * return await this.validateUser(username, password);
284
- * }
285
- * }
286
- * });
300
+ * Helper for building server replies.
301
+ */
302
+ declare class ServerReply {
303
+ headers: Record<string, string> & {
304
+ "set-cookie"?: string[];
305
+ };
306
+ status?: number;
307
+ body?: any;
308
+ /**
309
+ * Redirect to a given URL with optional status code (default 302).
310
+ */
311
+ redirect(url: string, status?: number): void;
312
+ /**
313
+ * Set the response status code.
314
+ */
315
+ setStatus(status: number): this;
316
+ /**
317
+ * Set a response header.
318
+ */
319
+ setHeader(name: string, value: string): this;
320
+ /**
321
+ * Set the response body.
322
+ */
323
+ setBody(body: any): this;
324
+ }
325
+ //#endregion
326
+ //#region ../alepha/src/server/services/UserAgentParser.d.ts
327
+ interface UserAgentInfo {
328
+ os: "Windows" | "Android" | "Ubuntu" | "MacOS" | "iOS" | "Linux" | "FreeBSD" | "OpenBSD" | "ChromeOS" | "BlackBerry" | "Symbian" | "Windows Phone";
329
+ browser: "Chrome" | "Firefox" | "Safari" | "Edge" | "Opera" | "Internet Explorer" | "Brave" | "Vivaldi" | "Samsung Browser" | "UC Browser" | "Yandex";
330
+ device: "MOBILE" | "DESKTOP" | "TABLET";
331
+ }
332
+ /**
333
+ * Simple User-Agent parser to detect OS, browser, and device type.
334
+ * This parser is not exhaustive and may not cover all edge cases.
287
335
  *
288
- * // External OIDC provider
289
- * keycloak = $auth({
290
- * oidc: {
291
- * issuer: "https://auth.example.com",
292
- * clientId: "my-app",
293
- * clientSecret: "secret",
294
- * redirectUri: "/auth/callback"
295
- * }
296
- * });
297
- * }
298
- * ```
336
+ * Use result for non
299
337
  */
300
- declare const $auth: {
301
- (options: AuthDescriptorOptions): AuthDescriptor;
302
- [KIND]: typeof AuthDescriptor;
303
- };
304
- type AuthDescriptorOptions = {
338
+ declare class UserAgentParser {
339
+ parse(userAgent?: string): UserAgentInfo;
340
+ }
341
+ //#endregion
342
+ //#region ../alepha/src/server/interfaces/ServerRequest.d.ts
343
+ type TRequestBody = TObject | TString | TArray | TRecord | TStream;
344
+ type TResponseBody = TObject | TString | TRecord | TFile | TArray | TStream | TVoid;
345
+ interface RequestConfigSchema {
346
+ body?: TRequestBody;
347
+ params?: TObject;
348
+ query?: TObject;
349
+ headers?: TObject;
350
+ response?: TResponseBody;
351
+ }
352
+ interface ServerRequestConfig<TConfig extends RequestConfigSchema = RequestConfigSchema> {
353
+ body: TConfig["body"] extends TRequestBody ? Static<TConfig["body"]> : any;
354
+ headers: TConfig["headers"] extends TObject ? Static<TConfig["headers"]> : Record<string, string>;
355
+ params: TConfig["params"] extends TObject ? Static<TConfig["params"]> : Record<string, string>;
356
+ query: TConfig["query"] extends TObject ? Static<TConfig["query"]> : Record<string, any>;
357
+ }
358
+ type ServerRequestConfigEntry<TConfig extends RequestConfigSchema = RequestConfigSchema> = Partial<ServerRequestConfig<TConfig>>;
359
+ interface ServerRequest<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRequestConfig<TConfig> {
305
360
  /**
306
- * Name of the identity provider.
307
- * If not provided, it will be derived from the property key.
361
+ * HTTP method used for this request.
308
362
  */
309
- name?: string;
363
+ method: RouteMethod;
310
364
  /**
311
- * If true, auth provider will be skipped.
365
+ * Full request URL.
312
366
  */
313
- disabled?: boolean;
314
- } & (AuthExternal | AuthInternal);
367
+ url: URL;
368
+ /**
369
+ * Unique request ID assigned to this request.
370
+ */
371
+ requestId: string;
372
+ /**
373
+ * Client IP address.
374
+ * Will parse `X-Forwarded-For` header if present.
375
+ */
376
+ ip?: string;
377
+ /**
378
+ * Value of the `Host` header sent by the client.
379
+ */
380
+ host?: string;
381
+ /**
382
+ * Browser user agent information.
383
+ * Information are not guaranteed to be accurate. Use with caution.
384
+ *
385
+ * @see {@link UserAgentParser}
386
+ */
387
+ userAgent: UserAgentInfo;
388
+ /**
389
+ * Arbitrary metadata attached to the request. Can be used by middlewares to store information.
390
+ */
391
+ metadata: Record<string, any>;
392
+ /**
393
+ * Reply object to be used to send response.
394
+ */
395
+ reply: ServerReply;
396
+ /**
397
+ * The raw underlying request object (Web Request).
398
+ */
399
+ raw: ServerRawRequest;
400
+ }
401
+ interface ServerRoute<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Route {
402
+ /**
403
+ * Handler function for this route.
404
+ */
405
+ handler: ServerHandler<TConfig>;
406
+ /**
407
+ * HTTP method for this route.
408
+ */
409
+ method?: RouteMethod;
410
+ /**
411
+ * Request/response schema for this route.
412
+ *
413
+ * Request schema contains:
414
+ * - body, for POST/PUT/PATCH requests
415
+ * - params, for URL parameters (e.g. /user/:id)
416
+ * - query, for URL query parameters (e.g. /user?id=123)
417
+ * - headers, for HTTP headers
418
+ *
419
+ * Response schema contains:
420
+ * - response
421
+ *
422
+ * Response schema is used to validate and serialize the response sent by the handler.
423
+ */
424
+ schema?: TConfig;
425
+ /**
426
+ * @see ServerLoggerProvider
427
+ */
428
+ silent?: boolean;
429
+ }
430
+ type ServerResponseBody<TConfig extends RequestConfigSchema = RequestConfigSchema> = TConfig["response"] extends TResponseBody ? Static<TConfig["response"]> : ResponseBodyType;
431
+ type ResponseKind = "json" | "text" | "void" | "file" | "any";
432
+ type ResponseBodyType = string | Buffer | StreamLike | undefined | null | void;
433
+ type ServerHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
434
+ interface ServerResponse$1 {
435
+ body: string | Buffer | ArrayBuffer | Readable | ReadableStream;
436
+ headers: Record<string, string>;
437
+ status: number;
438
+ }
439
+ type ServerRouteRequestHandler = (request: ServerRequestData) => Promise<ServerResponse$1>;
440
+ interface ServerRouteMatcher extends Route {
441
+ handler: ServerRouteRequestHandler;
442
+ }
443
+ interface ServerRequestData {
444
+ method: RouteMethod;
445
+ url: URL;
446
+ headers: Record<string, string>;
447
+ query: Record<string, string>;
448
+ params: Record<string, string>;
449
+ raw: ServerRawRequest;
450
+ }
451
+ interface ServerRawRequest {
452
+ node?: NodeRequestEvent;
453
+ web?: WebRequestEvent;
454
+ }
455
+ interface NodeRequestEvent {
456
+ req: IncomingMessage;
457
+ res: ServerResponse;
458
+ }
459
+ interface WebRequestEvent {
460
+ req: Request;
461
+ res?: Response;
462
+ }
463
+ //#endregion
464
+ //#region ../alepha/src/server/services/ServerRequestParser.d.ts
465
+ declare class ServerRequestParser {
466
+ protected readonly alepha: Alepha;
467
+ protected readonly userAgentParser: UserAgentParser;
468
+ createServerRequest(rawRequest: ServerRequestData): ServerRequest;
469
+ getRequestId(request: ServerRequestData): string | undefined;
470
+ getRequestUserAgent(request: ServerRequestData): UserAgentInfo;
471
+ getRequestIp(request: ServerRequestData): string | undefined;
472
+ }
473
+ //#endregion
474
+ //#region ../alepha/src/server/providers/ServerTimingProvider.d.ts
475
+ type TimingMap = Record<string, [number, number]>;
476
+ declare class ServerTimingProvider {
477
+ protected readonly log: Logger;
478
+ protected readonly alepha: Alepha;
479
+ options: {
480
+ prefix: string;
481
+ disabled: boolean;
482
+ };
483
+ readonly onRequest: alepha20.HookDescriptor<"server:onRequest">;
484
+ readonly onResponse: alepha20.HookDescriptor<"server:onResponse">;
485
+ protected get handlerName(): string;
486
+ beginTiming(name: string): void;
487
+ endTiming(name: string): void;
488
+ protected setDuration(name: string, timing: TimingMap): void;
489
+ }
490
+ //#endregion
491
+ //#region ../alepha/src/server/providers/ServerRouterProvider.d.ts
492
+ /**
493
+ * Main router for all routes on the server side.
494
+ *
495
+ * - $route => generic route
496
+ * - $action => action route (for API calls)
497
+ * - $page => React route (for SSR)
498
+ */
499
+ declare class ServerRouterProvider extends RouterProvider<ServerRouteMatcher> {
500
+ protected readonly log: Logger;
501
+ protected readonly alepha: Alepha;
502
+ protected readonly routes: ServerRoute[];
503
+ protected readonly serverTimingProvider: ServerTimingProvider;
504
+ protected readonly serverRequestParser: ServerRequestParser;
505
+ /**
506
+ * Get all registered routes, optionally filtered by a pattern.
507
+ *
508
+ * Pattern accept simple wildcard '*' at the end.
509
+ * Example: '/api/*' will match all routes starting with '/api/' but '/api/' will match only that exact route.
510
+ */
511
+ getRoutes(pattern?: string): ServerRoute[];
512
+ createRoute<TConfig extends RequestConfigSchema = RequestConfigSchema>(route: ServerRoute<TConfig>): void;
513
+ protected getContextId(headers: Record<string, string>): string;
514
+ protected processRequest(request: ServerRequest, route: ServerRoute, responseKind: ResponseKind): Promise<{
515
+ status: number;
516
+ headers: Record<string, string> & {
517
+ "set-cookie"?: string[];
518
+ };
519
+ body: any;
520
+ }>;
521
+ protected runRouteHandler(route: ServerRoute, request: ServerRequest, responseKind: ResponseKind): Promise<void>;
522
+ serializeResponse(route: ServerRoute, reply: ServerReply, responseKind: ResponseKind): void;
523
+ protected getResponseType(schema?: RequestConfigSchema): ResponseKind;
524
+ protected errorHandler(route: ServerRoute, request: ServerRequest, error: Error): Promise<void>;
525
+ validateRequest(route: {
526
+ schema?: RequestConfigSchema;
527
+ }, request: ServerRequestConfig): void;
528
+ }
529
+ //#endregion
530
+ //#region ../alepha/src/server/providers/ServerProvider.d.ts
315
531
  /**
316
- * When you let an external service handle authentication. (e.g. Keycloak, Auth0, etc.)
532
+ * Base server provider to handle incoming requests and route them.
533
+ *
534
+ * This is the default implementation for serverless environments.
535
+ *
536
+ * ServerProvider supports both Node.js HTTP requests and Web (Fetch API) requests.
317
537
  */
318
- type AuthExternal = {
538
+ declare class ServerProvider {
539
+ protected readonly log: Logger;
540
+ protected readonly alepha: Alepha;
541
+ protected readonly dateTimeProvider: DateTimeProvider;
542
+ protected readonly router: ServerRouterProvider;
543
+ protected readonly internalServerErrorMessage = "Internal Server Error";
544
+ get hostname(): string;
319
545
  /**
320
- * Only OIDC is supported for external authentication.
546
+ * When a Node.js HTTP request is received from outside. (Vercel, AWS Lambda, etc.)
321
547
  */
322
- oidc: OidcOptions;
548
+ protected readonly onNodeRequest: alepha20.HookDescriptor<"node:request">;
323
549
  /**
324
- * For anonymous access, this will expect a service account access token.
550
+ * When a Web (Fetch API) request is received from outside. (Netlify, Cloudflare Workers, etc.)
551
+ */
552
+ protected readonly onWebRequest: alepha20.HookDescriptor<"web:request">;
553
+ /**
554
+ * Handle Node.js HTTP request event.
325
555
  *
326
- * ```ts
327
- * class App {
328
- * anonymous = $serviceAccount(...);
329
- * auth = $auth({
330
- * // ... config ...
331
- * fallback: this.anonymous,
332
- * })
333
- * }
334
- * ```
556
+ * Technically, we just convert Node.js request to Web Standard Request.
335
557
  */
336
- fallback?: () => Async<AccessToken>;
337
- };
558
+ handleNodeRequest(nodeRequestEvent: NodeRequestEvent): Promise<void>;
559
+ /**
560
+ * Handle Web (Fetch API) request event.
561
+ */
562
+ handleWebRequest(ev: WebRequestEvent): Promise<void>;
563
+ /**
564
+ * Helper for Vite development mode to let Vite handle (or not) 404.
565
+ */
566
+ protected isViteNotFound(url?: string, route?: Route, params?: Record<string, string>): boolean;
567
+ }
568
+ //#endregion
569
+ //#region ../alepha/src/cache/providers/CacheProvider.d.ts
338
570
  /**
339
- * When using your own authentication system, e.g. using a database to store user accounts.
340
- * This is usually used with a custom login form.
571
+ * Cache provider interface.
341
572
  *
342
- * This relies on the `realm`, which is used to create/verify the access token.
573
+ * All methods are asynchronous and return promises.
574
+ * Values are stored as Uint8Array.
343
575
  */
344
- type AuthInternal = {
345
- realm: RealmDescriptor;
346
- } & ({
576
+ declare abstract class CacheProvider {
347
577
  /**
348
- * The common username/password authentication.
578
+ * Get the value of a key.
349
579
  *
350
- * - It uses the OAuth2 Client Credentials flow to obtain an access token.
580
+ * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
581
+ * @param key The key of the value to get.
351
582
  *
352
- * This is usually used with a custom login form on your website or mobile app.
583
+ * @return The value of the key, or undefined if the key does not exist.
353
584
  */
354
- credentials: CredentialsOptions;
355
- } | {
585
+ abstract get(name: string, key: string): Promise<Uint8Array | undefined>;
356
586
  /**
357
- * OAuth2 authentication. Delegates authentication to an OAuth2 provider. (e.g. Google, GitHub, etc.)
587
+ * Set the string value of a key.
358
588
  *
359
- * - It uses the OAuth2 Authorization Code flow to obtain an access token and user information.
589
+ * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
590
+ * @param key The key of the value to set.
591
+ * @param value The value to set.
592
+ * @param ttl The time-to-live of the key, in milliseconds.
360
593
  *
361
- * This is usually used with a login button that redirects to the OAuth2 provider.
594
+ * @return The value of the key.
362
595
  */
363
- oauth: OAuth2Options;
364
- } | {
596
+ abstract set(name: string, key: string, value: Uint8Array, ttl?: number): Promise<Uint8Array>;
365
597
  /**
366
- * Like OAuth2, but uses OIDC (OpenID Connect) for authentication and user information retrieval.
367
- * OIDC is an identity layer on top of OAuth2, providing user authentication and profile information.
598
+ * Remove the specified keys.
368
599
  *
369
- * - It uses the OAuth2 Authorization Code flow to obtain an access token and user information.
370
- * - PCKE (Proof Key for Code Exchange) is recommended for security.
600
+ * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
601
+ * @param keys The keys to delete.
602
+ */
603
+ abstract del(name: string, ...keys: string[]): Promise<void>;
604
+ abstract has(name: string, key: string): Promise<boolean>;
605
+ abstract keys(name: string, filter?: string): Promise<string[]>;
606
+ /**
607
+ * Remove all keys from all cache names.
608
+ */
609
+ abstract clear(): Promise<void>;
610
+ }
611
+ //#endregion
612
+ //#region ../alepha/src/cache/descriptors/$cache.d.ts
613
+ interface CacheDescriptorOptions<TReturn = any, TParameter extends any[] = any[]> {
614
+ /**
615
+ * The cache name. This is useful for invalidating multiple caches at once.
371
616
  *
372
- * This is usually used with a login button that redirects to the OIDC provider.
373
- */
374
- oidc: OidcOptions;
375
- });
376
- type CredentialsOptions = {
377
- account: (credentials: {
378
- username: string;
379
- password: string;
380
- }) => Async<UserAccount>;
381
- };
382
- interface OidcOptions {
617
+ * Store key as `cache:$name:$key`.
618
+ *
619
+ * @default Name of the key of the class.
620
+ */
621
+ name?: string;
622
+ /**
623
+ * Function which returns cached data.
624
+ */
625
+ handler?: (...args: TParameter) => TReturn;
626
+ /**
627
+ * The key generator for the cache.
628
+ * If not provided, the arguments will be json.stringify().
629
+ */
630
+ key?: (...args: TParameter) => string;
383
631
  /**
384
- * URL of the OIDC issuer.
632
+ * The store provider for the cache.
633
+ * If not provided, the default store provider will be used.
385
634
  */
386
- issuer: string;
635
+ provider?: InstantiableClass<CacheProvider> | "memory";
387
636
  /**
388
- * Client ID for the OIDC client.
637
+ * The time-to-live for the cache in seconds.
638
+ * Set 0 to skip expiration.
639
+ *
640
+ * @default 300 (5 minutes).
389
641
  */
390
- clientId: string;
642
+ ttl?: DurationLike;
391
643
  /**
392
- * Client secret for the OIDC client.
393
- * Optional if PKCE (Proof Key for Code Exchange) is used.
644
+ * If the cache is disabled.
394
645
  */
395
- clientSecret?: string;
646
+ disabled?: boolean;
647
+ }
648
+ declare class CacheDescriptor<TReturn = any, TParameter extends any[] = any[]> extends Descriptor<CacheDescriptorOptions<TReturn, TParameter>> {
649
+ protected readonly env: {
650
+ CACHE_ENABLED: boolean;
651
+ CACHE_DEFAULT_TTL: number;
652
+ };
653
+ protected readonly dateTimeProvider: DateTimeProvider;
654
+ protected readonly provider: CacheProvider;
655
+ protected encoder: TextEncoder;
656
+ protected decoder: TextDecoder;
657
+ protected codes: {
658
+ BINARY: number;
659
+ JSON: number;
660
+ STRING: number;
661
+ };
662
+ get container(): string;
663
+ run(...args: TParameter): Promise<TReturn>;
664
+ key(...args: TParameter): string;
665
+ invalidate(...keys: string[]): Promise<void>;
666
+ set(key: string, value: TReturn, ttl?: DurationLike): Promise<void>;
667
+ get(key: string): Promise<TReturn | undefined>;
668
+ protected serialize<TReturn>(value: TReturn): Uint8Array;
669
+ protected deserialize<TReturn>(uint8Array: Uint8Array): Promise<TReturn>;
670
+ protected $provider(): CacheProvider;
671
+ }
672
+ interface CacheDescriptorFn<TReturn = any, TParameter extends any[] = any[]> extends CacheDescriptor<TReturn, TParameter> {
396
673
  /**
397
- * Redirect URI for the OIDC client.
398
- * This is where the user will be redirected after authentication.
674
+ * Run the cache descriptor with the provided arguments.
399
675
  */
400
- redirectUri?: string;
676
+ (...args: TParameter): Promise<TReturn>;
677
+ }
678
+ //#endregion
679
+ //#region ../alepha/src/server/services/HttpClient.d.ts
680
+ declare class HttpClient {
681
+ protected readonly log: Logger;
682
+ protected readonly alepha: Alepha;
683
+ readonly cache: CacheDescriptorFn<HttpClientCache, any[]>;
684
+ protected readonly pendingRequests: HttpClientPendingRequests;
685
+ fetchAction(args: FetchActionArgs): Promise<FetchResponse>;
686
+ fetch<T extends TSchema>(url: string, request?: RequestInitWithOptions<T>): Promise<FetchResponse<Static<T>>>;
687
+ protected url(host: string, action: HttpAction, args: ServerRequestConfigEntry): string;
688
+ protected body(init: RequestInit, headers: Record<string, string>, action: HttpAction, args?: ServerRequestConfigEntry): Promise<void>;
689
+ protected responseData(response: Response, options: FetchOptions): Promise<any>;
690
+ protected isMaybeFile(response: Response): boolean;
691
+ protected createFileLike(response: Response, defaultFileName?: string): FileLike;
692
+ pathVariables(url: string, action: {
693
+ schema?: {
694
+ params?: TObject;
695
+ };
696
+ }, args?: ServerRequestConfigEntry): string;
697
+ queryParams(url: string, action: {
698
+ schema?: {
699
+ query?: TObject;
700
+ };
701
+ }, args?: ServerRequestConfigEntry): string;
702
+ }
703
+ interface FetchOptions<T extends TSchema = TSchema> {
401
704
  /**
402
- * For external auth providers only.
403
- * Take the ID token instead of the access token for validation.
705
+ * Key to identify the request in the pending requests.
404
706
  */
405
- useIdToken?: boolean;
707
+ key?: string;
406
708
  /**
407
- * URI to redirect the user after logout.
709
+ * The schema to validate the response against.
408
710
  */
409
- logoutUri?: string;
711
+ schema?: {
712
+ response?: T;
713
+ };
410
714
  /**
411
- * Optional scope for the OIDC client.
412
- * @default "openid profile email".
715
+ * Built-in cache options.
413
716
  */
414
- scope?: string;
415
- account?: (tokens: {
416
- access_token: string;
417
- user: OAuth2Profile;
418
- id_token?: string;
419
- expires_in?: number;
420
- scope?: string;
421
- }) => Async<UserAccount>;
717
+ localCache?: boolean | number | DurationLike;
422
718
  }
423
- interface OAuth2Options {
719
+ type RequestInitWithOptions<T extends TSchema = TSchema> = RequestInit & FetchOptions<T>;
720
+ interface FetchResponse<T = any> {
721
+ data: T;
722
+ status: number;
723
+ statusText: string;
724
+ headers: Headers;
725
+ raw?: Response;
726
+ }
727
+ type HttpClientPendingRequests = Record<string, Promise<any> | undefined>;
728
+ interface HttpClientCache {
729
+ data: any;
730
+ etag?: string;
731
+ }
732
+ interface FetchActionArgs {
733
+ action: HttpAction;
734
+ host?: string;
735
+ config?: ServerRequestConfigEntry;
736
+ options?: ClientRequestOptions;
737
+ }
738
+ interface HttpAction {
739
+ method?: string;
740
+ prefix?: string;
741
+ path: string;
742
+ requestBodyType?: string;
743
+ schema?: {
744
+ params?: TObject;
745
+ query?: TObject;
746
+ body?: TRequestBody;
747
+ response?: TResponseBody;
748
+ };
749
+ }
750
+ //#endregion
751
+ //#region ../alepha/src/server/descriptors/$action.d.ts
752
+ interface ActionDescriptorOptions<TConfig extends RequestConfigSchema> extends Omit<ServerRoute, "handler" | "path" | "schema" | "mapParams"> {
424
753
  /**
425
- * URL of the OAuth2 authorization endpoint.
754
+ * Name of the action.
755
+ *
756
+ * - It will be used to generate the route path if `path` is not provided.
757
+ * - It will be used to generate the permission name if `security` is enabled.
758
+ */
759
+ name?: string;
760
+ /**
761
+ * Group actions together.
762
+ *
763
+ * - If not provided, the service name containing the route will be used.
764
+ * - It will be used as Tag for documentation purposes.
765
+ * - It will be used for permission name generation if `security` is enabled.
766
+ *
767
+ * @example
768
+ * ```ts
769
+ * // group = "MyController"
770
+ * class MyController {
771
+ * hello = $action({ handler: () => "Hello World" });
772
+ * }
773
+ *
774
+ * // group = "users"
775
+ * class MyOtherController {
776
+ * group = "users";
777
+ * a1 = $action({ handler: () => "Action 1", group: this.group });
778
+ * a2 = $action({ handler: () => "Action 2", group: this.group });
779
+ * }
780
+ * ```
426
781
  */
427
- clientId: string;
782
+ group?: string;
428
783
  /**
429
- * Client secret for the OAuth2 client.
784
+ * Pathname of the route. If not provided, property key is used.
430
785
  */
431
- clientSecret: string;
786
+ path?: string;
432
787
  /**
433
- * URL of the OAuth2 authorization endpoint.
788
+ * The route method.
789
+ *
790
+ * - If not provided, it will be set to "GET" by default.
791
+ * - If not provider and a body is provided, it will be set to "POST".
792
+ *
793
+ * Wildcard methods are not supported for now. (e.g. "ALL", "ANY", etc.)
434
794
  */
435
- authorization: string;
795
+ method?: RouteMethod;
436
796
  /**
437
- * URL of the OAuth2 token endpoint.
797
+ * The config schema of the route.
798
+ * - body: The request body schema.
799
+ * - params: Path variables schema.
800
+ * - query: The request query-params schema.
801
+ * - response: The response schema.
438
802
  */
439
- token: string;
803
+ schema?: TConfig;
440
804
  /**
441
- * Function to retrieve user profile information from the OAuth2 tokens.
805
+ * A short description of the action. Used for documentation purposes.
442
806
  */
443
- userinfo: (tokens: Tokens) => Async<OAuth2Profile>;
444
- account?: (tokens: {
445
- access_token: string;
446
- user: OAuth2Profile;
447
- id_token?: string;
448
- expires_in?: number;
449
- scope?: string;
450
- }) => Async<UserAccount>;
807
+ description?: string;
451
808
  /**
452
- * URL of the OAuth2 authorization endpoint.
809
+ * Disable the route. Useful with env variables do disable one specific route.
810
+ * Route won't be available in the API but can still be called locally!
453
811
  */
454
- redirectUri?: string;
812
+ disabled?: boolean;
455
813
  /**
456
- * URL of the OAuth2 authorization endpoint.
814
+ * Main route handler. This is where the route logic is implemented.
457
815
  */
458
- scope?: string;
816
+ handler: ServerActionHandler<TConfig>;
459
817
  }
460
- declare class AuthDescriptor extends Descriptor<AuthDescriptorOptions> {
461
- protected readonly securityProvider: SecurityProvider;
462
- protected readonly dateTimeProvider: DateTimeProvider;
463
- oauth?: Configuration;
818
+ declare class ActionDescriptor<TConfig extends RequestConfigSchema> extends Descriptor<ActionDescriptorOptions<TConfig>> {
819
+ protected readonly log: Logger;
820
+ protected readonly env: {
821
+ SERVER_API_PREFIX: string;
822
+ };
823
+ protected readonly httpClient: HttpClient;
824
+ protected readonly serverProvider: ServerProvider;
825
+ protected readonly serverRouterProvider: ServerRouterProvider;
826
+ protected onInit(): void;
827
+ get prefix(): string;
828
+ get route(): ServerRoute;
829
+ /**
830
+ * Returns the name of the action.
831
+ */
464
832
  get name(): string;
465
- get jwks_uri(): string;
466
- get scope(): string | undefined;
467
- get redirect_uri(): string | undefined;
468
833
  /**
469
- * Refreshes the access token using the refresh token.
470
- * Can be used on oauth2, oidc or credentials auth providers.
834
+ * Returns the group of the action. (e.g. "orders", "admin", etc.)
471
835
  */
472
- refresh(refreshToken: string, accessToken?: string): Promise<AccessTokenResponse>;
836
+ get group(): string;
473
837
  /**
474
- * Extracts user information from the access token.
475
- * This is used to create a user account from the access token.
838
+ * Returns the HTTP method of the action.
476
839
  */
477
- user(tokens: Tokens): Promise<UserAccount>;
478
- protected getUserFromIdToken(idToken: string): OAuth2Profile;
479
- prepare(): Promise<void>;
840
+ get method(): RouteMethod;
841
+ /**
842
+ * Returns the path of the action.
843
+ *
844
+ * Path is prefixed by `/api` by default.
845
+ */
846
+ get path(): string;
847
+ get schema(): TConfig | undefined;
848
+ getBodyContentType(): string | undefined;
849
+ /**
850
+ * Call the action handler directly.
851
+ * There is no HTTP layer involved.
852
+ */
853
+ run(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<ClientRequestResponse<TConfig>>;
854
+ /**
855
+ * Works like `run`, but always fetches (http request) the route.
856
+ */
857
+ fetch(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<FetchResponse<ClientRequestResponse<TConfig>>>;
480
858
  }
481
- type AccessToken = string | {
482
- token: () => Async<string>;
859
+ type ClientRequestEntry<TConfig extends RequestConfigSchema, T = ClientRequestEntryContainer<TConfig>> = { [K in keyof T as T[K] extends undefined ? never : K]: T[K] };
860
+ type ClientRequestEntryContainer<TConfig extends RequestConfigSchema> = {
861
+ body: TConfig["body"] extends TObject ? Static<TConfig["body"]> : undefined;
862
+ params: TConfig["params"] extends TObject ? Static<TConfig["params"]> : undefined;
863
+ headers?: TConfig["headers"] extends TObject ? Static<TConfig["headers"]> : undefined;
864
+ query?: TConfig["query"] extends TObject ? Partial<Static<TConfig["query"]>> : undefined;
483
865
  };
866
+ interface ClientRequestOptions extends FetchOptions {
867
+ /**
868
+ * Standard request fetch options.
869
+ */
870
+ request?: RequestInit;
871
+ }
872
+ type ClientRequestResponse<TConfig extends RequestConfigSchema> = TConfig["response"] extends TSchema ? Static<TConfig["response"]> : any;
873
+ /**
874
+ * Specific handler for server actions.
875
+ */
876
+ type ServerActionHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerActionRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
877
+ /**
878
+ * Server Action Request Interface
879
+ *
880
+ * Can be extended with module augmentation to add custom properties (like `user` in Server Security).
881
+ *
882
+ * This is NOT Server Request, but a specific type for actions.
883
+ */
884
+ interface ServerActionRequest<TConfig extends RequestConfigSchema> extends ServerRequest<TConfig> {}
885
+ //#endregion
886
+ //#region ../alepha/src/server/schemas/errorSchema.d.ts
887
+ declare const errorSchema: alepha20.TObject<{
888
+ error: alepha20.TString;
889
+ status: alepha20.TInteger;
890
+ message: alepha20.TString;
891
+ details: alepha20.TOptional<alepha20.TString>;
892
+ requestId: alepha20.TOptional<alepha20.TString>;
893
+ cause: alepha20.TOptional<alepha20.TObject<{
894
+ name: alepha20.TString;
895
+ message: alepha20.TString;
896
+ }>>;
897
+ }>;
898
+ type ErrorSchema = Static<typeof errorSchema>;
899
+ //#endregion
900
+ //#region ../alepha/src/server/errors/HttpError.d.ts
901
+ declare class HttpError extends AlephaError {
902
+ name: string;
903
+ static is: (error: unknown, status?: number) => error is HttpErrorLike;
904
+ static toJSON(error: HttpError): ErrorSchema;
905
+ readonly error: string;
906
+ readonly status: number;
907
+ readonly requestId?: string;
908
+ readonly details?: string;
909
+ readonly reason?: {
910
+ name: string;
911
+ message: string;
912
+ };
913
+ constructor(options: Partial<ErrorSchema>, cause?: unknown);
914
+ }
915
+ interface HttpErrorLike extends Error {
916
+ status: number;
917
+ }
918
+ //#endregion
919
+ //#region ../alepha/src/server/providers/BunHttpServerProvider.d.ts
920
+ declare const envSchema$1: alepha20.TObject<{
921
+ SERVER_PORT: alepha20.TInteger;
922
+ SERVER_HOST: alepha20.TString;
923
+ }>;
924
+ declare module "alepha" {
925
+ interface Env extends Partial<Static<typeof envSchema$1>> {}
926
+ }
927
+ //#endregion
928
+ //#region ../alepha/src/server/providers/NodeHttpServerProvider.d.ts
929
+ declare const envSchema: alepha20.TObject<{
930
+ SERVER_PORT: alepha20.TInteger;
931
+ SERVER_HOST: alepha20.TString;
932
+ }>;
933
+ declare module "alepha" {
934
+ interface Env extends Partial<Static<typeof envSchema>> {}
935
+ }
484
936
  //#endregion
485
- //#region src/auth/descriptors/$authGithub.d.ts
937
+ //#region ../alepha/src/server/index.d.ts
938
+ declare module "alepha" {
939
+ interface State {
940
+ "alepha.node.server"?: Server;
941
+ }
942
+ interface Hooks {
943
+ "action:onRequest": {
944
+ action: ActionDescriptor<RequestConfigSchema>;
945
+ request: ServerRequest;
946
+ options: ClientRequestOptions;
947
+ };
948
+ "action:onResponse": {
949
+ action: ActionDescriptor<RequestConfigSchema>;
950
+ request: ServerRequest;
951
+ options: ClientRequestOptions;
952
+ response: any;
953
+ };
954
+ "server:onRequest": {
955
+ route: ServerRoute;
956
+ request: ServerRequest;
957
+ };
958
+ "server:onError": {
959
+ route: ServerRoute;
960
+ request: ServerRequest;
961
+ error: Error;
962
+ };
963
+ "server:onSend": {
964
+ route: ServerRoute;
965
+ request: ServerRequest;
966
+ };
967
+ "server:onResponse": {
968
+ route: ServerRoute;
969
+ request: ServerRequest;
970
+ response: ServerResponse$1;
971
+ };
972
+ "client:onRequest": {
973
+ route: HttpAction;
974
+ config: ServerRequestConfigEntry;
975
+ options: ClientRequestOptions;
976
+ headers: Record<string, string>;
977
+ request: RequestInit;
978
+ };
979
+ "client:beforeFetch": {
980
+ url: string;
981
+ options: FetchOptions;
982
+ request: RequestInit;
983
+ };
984
+ "client:onError": {
985
+ route?: HttpAction;
986
+ error: HttpError;
987
+ };
988
+ "node:request": NodeRequestEvent;
989
+ "web:request": WebRequestEvent;
990
+ }
991
+ }
992
+ //#endregion
993
+ //#region ../alepha/src/security/index.d.ts
994
+ declare module "alepha" {
995
+ interface Hooks {
996
+ "security:user:created": {
997
+ realm: string;
998
+ user: UserAccount;
999
+ };
1000
+ }
1001
+ }
486
1002
  /**
487
- * Already configured GitHub authentication descriptor.
1003
+ * Provides comprehensive authentication and authorization capabilities with JWT tokens, role-based access control, and user management.
488
1004
  *
489
- * Uses OAuth2 to authenticate users via their GitHub accounts.
490
- * Upon successful authentication, it links the GitHub account to a user session.
1005
+ * The security module enables building secure applications using descriptors like `$realm`, `$role`, and `$permission`
1006
+ * on class properties. It offers JWT-based authentication, fine-grained permissions, service accounts, and seamless
1007
+ * integration with various authentication providers and user management systems.
491
1008
  *
492
- * Environment Variables:
493
- * - `GITHUB_CLIENT_ID`: The client ID obtained from the GitHub Developer Settings.
494
- * - `GITHUB_CLIENT_SECRET`: The client secret obtained from the GitHub Developer Settings.
1009
+ * @see {@link $realm}
1010
+ * @see {@link $role}
1011
+ * @see {@link $permission}
1012
+ * @module alepha.security
495
1013
  */
496
- declare const $authGithub: (realm: RealmDescriptor, options: Partial<OidcOptions>) => AuthDescriptor;
497
1014
  //#endregion
498
- //#region src/auth/descriptors/$authGoogle.d.ts
1015
+ //#region ../alepha/src/server-security/providers/ServerBasicAuthProvider.d.ts
1016
+ interface BasicAuthOptions {
1017
+ username: string;
1018
+ password: string;
1019
+ }
1020
+ //#endregion
1021
+ //#region ../alepha/src/server-security/providers/ServerSecurityProvider.d.ts
1022
+ type ServerRouteSecure = {
1023
+ realm?: string;
1024
+ basic?: BasicAuthOptions;
1025
+ };
1026
+ //#endregion
1027
+ //#region ../alepha/src/server-security/index.d.ts
1028
+ declare module "alepha" {
1029
+ interface State {
1030
+ /**
1031
+ * Real (or fake) user account, used for internal actions.
1032
+ *
1033
+ * If you define this, you assume that all actions are executed by this user by default.
1034
+ * > To force a different user, you need to pass it explicitly in the options.
1035
+ */
1036
+ "alepha.server.security.system.user"?: UserAccountToken;
1037
+ /**
1038
+ * The authenticated user account attached to the server request state.
1039
+ *
1040
+ * @internal
1041
+ */
1042
+ "alepha.server.request.user"?: UserAccount;
1043
+ }
1044
+ }
1045
+ declare module "alepha/server" {
1046
+ interface ServerRequest<TConfig> {
1047
+ user?: UserAccountToken;
1048
+ }
1049
+ interface ServerActionRequest<TConfig> {
1050
+ user: UserAccountToken;
1051
+ }
1052
+ interface ServerRoute {
1053
+ /**
1054
+ * If true, the route will be protected by the security provider.
1055
+ * All actions are secure by default, but you can disable it for specific actions.
1056
+ */
1057
+ secure?: boolean | ServerRouteSecure;
1058
+ }
1059
+ interface ClientRequestOptions extends FetchOptions {
1060
+ /**
1061
+ * Forward user from the previous request.
1062
+ * If "system", use system user. @see {ServerSecurityProvider.localSystemUser}
1063
+ * If "context", use the user from the current context (e.g. request).
1064
+ *
1065
+ * @default "system" if provided, else "context" if available.
1066
+ */
1067
+ user?: UserAccountToken | "system" | "context";
1068
+ }
1069
+ }
499
1070
  /**
500
- * Already configured Google authentication descriptor.
1071
+ * Plugin for Alepha Server that provides security features. Based on the Alepha Security module.
501
1072
  *
502
- * Uses OpenID Connect (OIDC) to authenticate users via their Google accounts.
503
- * Upon successful authentication, it links the Google account to a user session.
1073
+ * By default, all $action will be guarded by a permission check.
504
1074
  *
505
- * Environment Variables:
506
- * - `GOOGLE_CLIENT_ID`: The client ID obtained from the Google Developer Console.
507
- * - `GOOGLE_CLIENT_SECRET`: The client secret obtained from the Google Developer Console.
1075
+ * @see {@link ServerSecurityProvider}
1076
+ * @module alepha.server.security
508
1077
  */
509
- declare const $authGoogle: (realm: RealmDescriptor, options: Partial<OidcOptions>) => AuthDescriptor;
510
1078
  //#endregion
511
- //#region src/auth/errors/SessionExpiredError.d.ts
512
- declare class SessionExpiredError extends AlephaError {
513
- readonly name = "SessionExpiredError";
514
- readonly status = 401;
1079
+ //#region ../alepha/src/server-links/schemas/apiLinksResponseSchema.d.ts
1080
+ declare const apiLinksResponseSchema: alepha20.TObject<{
1081
+ prefix: alepha20.TOptional<alepha20.TString>;
1082
+ links: alepha20.TArray<alepha20.TObject<{
1083
+ name: alepha20.TString;
1084
+ group: alepha20.TOptional<alepha20.TString>;
1085
+ path: alepha20.TString;
1086
+ method: alepha20.TOptional<alepha20.TString>;
1087
+ requestBodyType: alepha20.TOptional<alepha20.TString>;
1088
+ service: alepha20.TOptional<alepha20.TString>;
1089
+ }>>;
1090
+ }>;
1091
+ type ApiLinksResponse = Static<typeof apiLinksResponseSchema>;
1092
+ //#endregion
1093
+ //#region ../alepha/src/server-links/providers/LinkProvider.d.ts
1094
+ type HttpVirtualClient<T> = { [K in keyof T as T[K] extends ActionDescriptor<RequestConfigSchema> ? K : never]: T[K] extends ActionDescriptor<infer Schema> ? VirtualAction<Schema> : never };
1095
+ interface VirtualAction<T extends RequestConfigSchema> extends Pick<ActionDescriptor<T>, "name" | "run" | "fetch"> {
1096
+ (config?: ClientRequestEntry<T>, opts?: ClientRequestOptions): Promise<ClientRequestResponse<T>>;
1097
+ can: () => boolean;
515
1098
  }
516
1099
  //#endregion
1100
+ //#region ../alepha/src/server-links/index.d.ts
1101
+ declare module "alepha" {
1102
+ interface State {
1103
+ /**
1104
+ * API links attached to the server request state.
1105
+ *
1106
+ * @see {@link ApiLinksResponse}
1107
+ * @internal
1108
+ */
1109
+ "alepha.server.request.apiLinks"?: ApiLinksResponse;
1110
+ }
1111
+ }
1112
+ /**
1113
+ * Provides server-side link management and remote capabilities for client-server interactions.
1114
+ *
1115
+ * The server-links module enables declarative link definitions using `$remote` and `$client` descriptors,
1116
+ * facilitating seamless API endpoint management and client-server communication. It integrates with server
1117
+ * security features to ensure safe and controlled access to resources.
1118
+ *
1119
+ * @see {@link $remote}
1120
+ * @see {@link $client}
1121
+ * @module alepha.server.links
1122
+ */
1123
+ //#endregion
517
1124
  //#region src/auth/hooks/useAuth.d.ts
518
1125
  declare const useAuth: <T extends object = any>() => {
519
1126
  user: {
@@ -536,7 +1143,53 @@ declare const useAuth: <T extends object = any>() => {
536
1143
  can: <Api extends object = any>(name: keyof HttpVirtualClient<Api>) => boolean;
537
1144
  };
538
1145
  //#endregion
539
- //#region src/auth/index.d.ts
1146
+ //#region ../alepha/src/server-cookies/descriptors/$cookie.d.ts
1147
+ interface Cookies {
1148
+ req: Record<string, string>;
1149
+ res: Record<string, Cookie | null>;
1150
+ }
1151
+ interface Cookie {
1152
+ value: string;
1153
+ path?: string;
1154
+ maxAge?: number;
1155
+ secure?: boolean;
1156
+ httpOnly?: boolean;
1157
+ sameSite?: "strict" | "lax" | "none";
1158
+ domain?: string;
1159
+ }
1160
+ //#endregion
1161
+ //#region ../alepha/src/server-cookies/index.d.ts
1162
+ declare module "alepha/server" {
1163
+ interface ServerRequest {
1164
+ cookies: Cookies;
1165
+ }
1166
+ }
1167
+ /**
1168
+ * Provides HTTP cookie management capabilities for server requests and responses with type-safe cookie descriptors.
1169
+ *
1170
+ * The server-cookies module enables declarative cookie handling using the `$cookie` descriptor on class properties.
1171
+ * It offers automatic cookie parsing, secure cookie configuration, and seamless integration with server routes
1172
+ * for managing user sessions, preferences, and authentication tokens.
1173
+ *
1174
+ * @see {@link $cookie}
1175
+ * @module alepha.server.cookies
1176
+ */
1177
+ //#endregion
1178
+ //#region ../alepha/src/server-auth/schemas/tokensSchema.d.ts
1179
+ declare const tokensSchema: alepha20.TObject<{
1180
+ provider: alepha20.TString;
1181
+ access_token: alepha20.TString;
1182
+ issued_at: alepha20.TNumber;
1183
+ expires_in: alepha20.TOptional<alepha20.TNumber>;
1184
+ refresh_token: alepha20.TOptional<alepha20.TString>;
1185
+ refresh_token_expires_in: alepha20.TOptional<alepha20.TNumber>;
1186
+ refresh_expires_in: alepha20.TOptional<alepha20.TNumber>;
1187
+ id_token: alepha20.TOptional<alepha20.TString>;
1188
+ scope: alepha20.TOptional<alepha20.TString>;
1189
+ }>;
1190
+ type Tokens = Static<typeof tokensSchema>;
1191
+ //#endregion
1192
+ //#region ../alepha/src/server-auth/index.d.ts
540
1193
  declare module "alepha" {
541
1194
  interface State {
542
1195
  /**
@@ -547,6 +1200,63 @@ declare module "alepha" {
547
1200
  "alepha.server.request.user"?: UserAccount;
548
1201
  }
549
1202
  }
1203
+ /**
1204
+ * Allow authentication services for server applications.
1205
+ * It provides login and logout functionalities.
1206
+ *
1207
+ * There are multiple authentication providers available (e.g., Google, GitHub).
1208
+ * You can also delegate authentication to your own OIDC/OAuth2, for example using Keycloak or Auth0.
1209
+ *
1210
+ * It's cookie-based and SSR friendly.
1211
+ *
1212
+ * @see {@link $auth}
1213
+ * @see {@link ServerAuthProvider}
1214
+ * @module alepha.server.auth
1215
+ */
1216
+ //#endregion
1217
+ //#region src/auth/services/ReactAuth.d.ts
1218
+ /**
1219
+ * Browser, SSR friendly, service to handle authentication.
1220
+ */
1221
+ declare class ReactAuth {
1222
+ protected readonly log: Logger;
1223
+ protected readonly alepha: Alepha;
1224
+ protected readonly httpClient: HttpClient;
1225
+ protected readonly onBeginTransition: alepha20.HookDescriptor<"react:transition:begin">;
1226
+ protected readonly onFetchRequest: alepha20.HookDescriptor<"client:onRequest">;
1227
+ /**
1228
+ * Get the current authenticated user.
1229
+ *
1230
+ * Alias for `alepha.state.get("user")`
1231
+ */
1232
+ get user(): UserAccountToken | undefined;
1233
+ ping(): Promise<{
1234
+ name?: string | undefined;
1235
+ email?: string | undefined;
1236
+ username?: string | undefined;
1237
+ picture?: string | undefined;
1238
+ sessionId?: string | undefined;
1239
+ organizations?: string[] | undefined;
1240
+ roles?: string[] | undefined;
1241
+ id: string;
1242
+ } | undefined>;
1243
+ login(provider: string, options: {
1244
+ hostname?: string;
1245
+ username?: string;
1246
+ password?: string;
1247
+ redirect?: string;
1248
+ [extra: string]: any;
1249
+ }): Promise<Tokens>;
1250
+ logout(): void;
1251
+ }
1252
+ //#endregion
1253
+ //#region src/auth/providers/ReactAuthProvider.d.ts
1254
+ declare class ReactAuthProvider {
1255
+ protected readonly alepha: Alepha;
1256
+ readonly onRender: alepha20.HookDescriptor<"react:server:render:begin">;
1257
+ }
1258
+ //#endregion
1259
+ //#region src/auth/index.d.ts
550
1260
  declare module "@alepha/react" {
551
1261
  interface ReactRouterState {
552
1262
  user?: UserAccount;
@@ -558,7 +1268,7 @@ declare module "@alepha/react" {
558
1268
  * @see {@link ReactAuthProvider}
559
1269
  * @module alepha.react.auth
560
1270
  */
561
- declare const AlephaReactAuth: alepha4.Service<alepha4.Module>;
1271
+ declare const AlephaReactAuth: alepha20.Service<alepha20.Module>;
562
1272
  //#endregion
563
- export { $auth, $authGithub, $authGoogle, AccessToken, AlephaReactAuth, AuthDescriptor, AuthDescriptorOptions, AuthExternal, AuthInternal, CredentialsOptions, OAuth2Options, OAuth2Profile, OidcOptions, ReactAuth, ReactAuthProvider, SessionExpiredError, useAuth };
1273
+ export { AlephaReactAuth, ReactAuth, ReactAuthProvider, useAuth };
564
1274
  //# sourceMappingURL=index.d.cts.map