alepha 0.13.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/dist/api-jobs/index.d.ts +26 -26
  2. package/dist/api-users/index.d.ts +1 -1
  3. package/dist/cli/{dist-Sz2EXvQX.cjs → dist-Dl9Vl7Ur.js} +17 -13
  4. package/dist/cli/{dist-BBPjuQ56.js.map → dist-Dl9Vl7Ur.js.map} +1 -1
  5. package/dist/cli/index.d.ts +3 -11
  6. package/dist/cli/index.js +106 -74
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/email/index.js +71 -73
  9. package/dist/email/index.js.map +1 -1
  10. package/dist/orm/index.d.ts +1 -1
  11. package/dist/orm/index.js.map +1 -1
  12. package/dist/queue/index.d.ts +4 -4
  13. package/dist/retry/index.d.ts +1 -1
  14. package/dist/retry/index.js +2 -2
  15. package/dist/retry/index.js.map +1 -1
  16. package/dist/scheduler/index.d.ts +6 -6
  17. package/dist/security/index.d.ts +28 -28
  18. package/dist/server/index.js +1 -1
  19. package/dist/server/index.js.map +1 -1
  20. package/dist/server-health/index.d.ts +17 -17
  21. package/dist/server-metrics/index.js +170 -174
  22. package/dist/server-metrics/index.js.map +1 -1
  23. package/dist/server-security/index.d.ts +9 -9
  24. package/dist/vite/index.js +4 -5
  25. package/dist/vite/index.js.map +1 -1
  26. package/dist/websocket/index.d.ts +7 -7
  27. package/package.json +52 -103
  28. package/src/cli/apps/AlephaPackageBuilderCli.ts +7 -2
  29. package/src/cli/assets/appRouterTs.ts +9 -0
  30. package/src/cli/assets/indexHtml.ts +2 -1
  31. package/src/cli/assets/mainBrowserTs.ts +10 -0
  32. package/src/cli/commands/CoreCommands.ts +6 -5
  33. package/src/cli/commands/DrizzleCommands.ts +65 -57
  34. package/src/cli/commands/VerifyCommands.ts +1 -1
  35. package/src/cli/services/ProjectUtils.ts +44 -38
  36. package/src/orm/providers/DrizzleKitProvider.ts +1 -1
  37. package/src/retry/descriptors/$retry.ts +5 -3
  38. package/src/server/providers/NodeHttpServerProvider.ts +1 -1
  39. package/src/vite/helpers/boot.ts +3 -3
  40. package/dist/api-files/index.cjs +0 -1293
  41. package/dist/api-files/index.cjs.map +0 -1
  42. package/dist/api-files/index.d.cts +0 -829
  43. package/dist/api-jobs/index.cjs +0 -274
  44. package/dist/api-jobs/index.cjs.map +0 -1
  45. package/dist/api-jobs/index.d.cts +0 -654
  46. package/dist/api-notifications/index.cjs +0 -380
  47. package/dist/api-notifications/index.cjs.map +0 -1
  48. package/dist/api-notifications/index.d.cts +0 -289
  49. package/dist/api-parameters/index.cjs +0 -66
  50. package/dist/api-parameters/index.cjs.map +0 -1
  51. package/dist/api-parameters/index.d.cts +0 -84
  52. package/dist/api-users/index.cjs +0 -6009
  53. package/dist/api-users/index.cjs.map +0 -1
  54. package/dist/api-users/index.d.cts +0 -4740
  55. package/dist/api-verifications/index.cjs +0 -407
  56. package/dist/api-verifications/index.cjs.map +0 -1
  57. package/dist/api-verifications/index.d.cts +0 -207
  58. package/dist/batch/index.cjs +0 -408
  59. package/dist/batch/index.cjs.map +0 -1
  60. package/dist/batch/index.d.cts +0 -330
  61. package/dist/bin/index.cjs +0 -17
  62. package/dist/bin/index.cjs.map +0 -1
  63. package/dist/bin/index.d.cts +0 -1
  64. package/dist/bucket/index.cjs +0 -303
  65. package/dist/bucket/index.cjs.map +0 -1
  66. package/dist/bucket/index.d.cts +0 -355
  67. package/dist/cache/index.cjs +0 -241
  68. package/dist/cache/index.cjs.map +0 -1
  69. package/dist/cache/index.d.cts +0 -202
  70. package/dist/cache-redis/index.cjs +0 -84
  71. package/dist/cache-redis/index.cjs.map +0 -1
  72. package/dist/cache-redis/index.d.cts +0 -40
  73. package/dist/cli/chunk-DSlc6foC.cjs +0 -43
  74. package/dist/cli/dist-BBPjuQ56.js +0 -2778
  75. package/dist/cli/dist-Sz2EXvQX.cjs.map +0 -1
  76. package/dist/cli/index.cjs +0 -1241
  77. package/dist/cli/index.cjs.map +0 -1
  78. package/dist/cli/index.d.cts +0 -422
  79. package/dist/command/index.cjs +0 -693
  80. package/dist/command/index.cjs.map +0 -1
  81. package/dist/command/index.d.cts +0 -340
  82. package/dist/core/index.cjs +0 -2264
  83. package/dist/core/index.cjs.map +0 -1
  84. package/dist/core/index.d.cts +0 -1927
  85. package/dist/datetime/index.cjs +0 -318
  86. package/dist/datetime/index.cjs.map +0 -1
  87. package/dist/datetime/index.d.cts +0 -145
  88. package/dist/email/index.cjs +0 -10874
  89. package/dist/email/index.cjs.map +0 -1
  90. package/dist/email/index.d.cts +0 -186
  91. package/dist/fake/index.cjs +0 -34641
  92. package/dist/fake/index.cjs.map +0 -1
  93. package/dist/fake/index.d.cts +0 -74
  94. package/dist/file/index.cjs +0 -1212
  95. package/dist/file/index.cjs.map +0 -1
  96. package/dist/file/index.d.cts +0 -698
  97. package/dist/lock/index.cjs +0 -226
  98. package/dist/lock/index.cjs.map +0 -1
  99. package/dist/lock/index.d.cts +0 -361
  100. package/dist/lock-redis/index.cjs +0 -113
  101. package/dist/lock-redis/index.cjs.map +0 -1
  102. package/dist/lock-redis/index.d.cts +0 -24
  103. package/dist/logger/index.cjs +0 -521
  104. package/dist/logger/index.cjs.map +0 -1
  105. package/dist/logger/index.d.cts +0 -281
  106. package/dist/orm/index.cjs +0 -2986
  107. package/dist/orm/index.cjs.map +0 -1
  108. package/dist/orm/index.d.cts +0 -2213
  109. package/dist/queue/index.cjs +0 -1044
  110. package/dist/queue/index.cjs.map +0 -1
  111. package/dist/queue/index.d.cts +0 -1265
  112. package/dist/queue-redis/index.cjs +0 -873
  113. package/dist/queue-redis/index.cjs.map +0 -1
  114. package/dist/queue-redis/index.d.cts +0 -82
  115. package/dist/redis/index.cjs +0 -153
  116. package/dist/redis/index.cjs.map +0 -1
  117. package/dist/redis/index.d.cts +0 -82
  118. package/dist/retry/index.cjs +0 -146
  119. package/dist/retry/index.cjs.map +0 -1
  120. package/dist/retry/index.d.cts +0 -172
  121. package/dist/router/index.cjs +0 -111
  122. package/dist/router/index.cjs.map +0 -1
  123. package/dist/router/index.d.cts +0 -46
  124. package/dist/scheduler/index.cjs +0 -576
  125. package/dist/scheduler/index.cjs.map +0 -1
  126. package/dist/scheduler/index.d.cts +0 -145
  127. package/dist/security/index.cjs +0 -2402
  128. package/dist/security/index.cjs.map +0 -1
  129. package/dist/security/index.d.cts +0 -598
  130. package/dist/server/index.cjs +0 -1680
  131. package/dist/server/index.cjs.map +0 -1
  132. package/dist/server/index.d.cts +0 -810
  133. package/dist/server-auth/index.cjs +0 -3146
  134. package/dist/server-auth/index.cjs.map +0 -1
  135. package/dist/server-auth/index.d.cts +0 -1164
  136. package/dist/server-cache/index.cjs +0 -252
  137. package/dist/server-cache/index.cjs.map +0 -1
  138. package/dist/server-cache/index.d.cts +0 -164
  139. package/dist/server-compress/index.cjs +0 -141
  140. package/dist/server-compress/index.cjs.map +0 -1
  141. package/dist/server-compress/index.d.cts +0 -38
  142. package/dist/server-cookies/index.cjs +0 -234
  143. package/dist/server-cookies/index.cjs.map +0 -1
  144. package/dist/server-cookies/index.d.cts +0 -144
  145. package/dist/server-cors/index.cjs +0 -201
  146. package/dist/server-cors/index.cjs.map +0 -1
  147. package/dist/server-cors/index.d.cts +0 -140
  148. package/dist/server-health/index.cjs +0 -62
  149. package/dist/server-health/index.cjs.map +0 -1
  150. package/dist/server-health/index.d.cts +0 -58
  151. package/dist/server-helmet/index.cjs +0 -131
  152. package/dist/server-helmet/index.cjs.map +0 -1
  153. package/dist/server-helmet/index.d.cts +0 -97
  154. package/dist/server-links/index.cjs +0 -992
  155. package/dist/server-links/index.cjs.map +0 -1
  156. package/dist/server-links/index.d.cts +0 -513
  157. package/dist/server-metrics/index.cjs +0 -4535
  158. package/dist/server-metrics/index.cjs.map +0 -1
  159. package/dist/server-metrics/index.d.cts +0 -35
  160. package/dist/server-multipart/index.cjs +0 -237
  161. package/dist/server-multipart/index.cjs.map +0 -1
  162. package/dist/server-multipart/index.d.cts +0 -50
  163. package/dist/server-proxy/index.cjs +0 -186
  164. package/dist/server-proxy/index.cjs.map +0 -1
  165. package/dist/server-proxy/index.d.cts +0 -234
  166. package/dist/server-rate-limit/index.cjs +0 -241
  167. package/dist/server-rate-limit/index.cjs.map +0 -1
  168. package/dist/server-rate-limit/index.d.cts +0 -183
  169. package/dist/server-security/index.cjs +0 -316
  170. package/dist/server-security/index.cjs.map +0 -1
  171. package/dist/server-security/index.d.cts +0 -173
  172. package/dist/server-static/index.cjs +0 -170
  173. package/dist/server-static/index.cjs.map +0 -1
  174. package/dist/server-static/index.d.cts +0 -121
  175. package/dist/server-swagger/index.cjs +0 -1021
  176. package/dist/server-swagger/index.cjs.map +0 -1
  177. package/dist/server-swagger/index.d.cts +0 -382
  178. package/dist/sms/index.cjs +0 -221
  179. package/dist/sms/index.cjs.map +0 -1
  180. package/dist/sms/index.d.cts +0 -130
  181. package/dist/thread/index.cjs +0 -350
  182. package/dist/thread/index.cjs.map +0 -1
  183. package/dist/thread/index.d.cts +0 -260
  184. package/dist/topic/index.cjs +0 -282
  185. package/dist/topic/index.cjs.map +0 -1
  186. package/dist/topic/index.d.cts +0 -523
  187. package/dist/topic-redis/index.cjs +0 -71
  188. package/dist/topic-redis/index.cjs.map +0 -1
  189. package/dist/topic-redis/index.d.cts +0 -42
  190. package/dist/vite/index.cjs +0 -1077
  191. package/dist/vite/index.cjs.map +0 -1
  192. package/dist/vite/index.d.cts +0 -542
  193. package/dist/websocket/index.cjs +0 -1117
  194. package/dist/websocket/index.cjs.map +0 -1
  195. package/dist/websocket/index.d.cts +0 -861
@@ -1,1164 +0,0 @@
1
- import * as alepha304 from "alepha";
2
- import { Alepha, Async, Descriptor, KIND, Static, TSchema } from "alepha";
3
- import { AccessTokenResponse, RealmDescriptor, SecurityProvider, ServiceAccountDescriptor, UserAccount, UserAccountToken } from "alepha/security";
4
- import { DateTimeProvider, DurationLike } from "alepha/datetime";
5
- import { Configuration } from "openid-client";
6
- import * as alepha_logger2 from "alepha/logger";
7
- import * as alepha_server6 from "alepha/server";
8
- import { ActionDescriptor, ClientRequestEntry, ClientRequestOptions, ClientRequestResponse, FetchOptions, FetchResponse, HttpClient, RequestConfigSchema, ServerHandler, ServerRequest, ServerRequestConfigEntry, ServerResponseBody, ServerRouterProvider, ServerTimingProvider } from "alepha/server";
9
- import * as alepha_retry0 from "alepha/retry";
10
-
11
- //#region src/server-cookies/services/CookieParser.d.ts
12
- declare class CookieParser {
13
- parseRequestCookies(header: string): Record<string, string>;
14
- serializeResponseCookies(cookies: Record<string, Cookie | null>, isHttps: boolean): string[];
15
- cookieToString(name: string, cookie: Cookie, isHttps?: boolean): string;
16
- }
17
- //#endregion
18
- //#region src/server-cookies/providers/ServerCookiesProvider.d.ts
19
- declare class ServerCookiesProvider {
20
- protected readonly alepha: Alepha;
21
- protected readonly log: alepha_logger2.Logger;
22
- protected readonly cookieParser: CookieParser;
23
- protected readonly dateTimeProvider: DateTimeProvider;
24
- protected readonly env: {
25
- APP_SECRET: string;
26
- };
27
- protected readonly ALGORITHM = "aes-256-gcm";
28
- protected readonly IV_LENGTH = 16;
29
- protected readonly AUTH_TAG_LENGTH = 16;
30
- protected readonly SIGNATURE_LENGTH = 32;
31
- readonly onRequest: alepha304.HookDescriptor<"server:onRequest">;
32
- readonly onAction: alepha304.HookDescriptor<"action:onRequest">;
33
- readonly onSend: alepha304.HookDescriptor<"server:onSend">;
34
- protected getCookiesFromContext(cookies?: Cookies): Cookies;
35
- getCookie<T extends TSchema>(name: string, options: CookieDescriptorOptions<T>, contextCookies?: Cookies): Static<T> | undefined;
36
- setCookie<T extends TSchema>(name: string, options: CookieDescriptorOptions<T>, data: Static<T>, contextCookies?: Cookies): void;
37
- deleteCookie<T extends TSchema>(name: string, contextCookies?: Cookies): void;
38
- protected encrypt(text: string): string;
39
- protected decrypt(encryptedText: string): string;
40
- secretKey(): string;
41
- protected sign(data: string): string;
42
- }
43
- //#endregion
44
- //#region src/server-cookies/descriptors/$cookie.d.ts
45
- interface CookieDescriptorOptions<T extends TSchema> {
46
- /** The schema for the cookie's value, used for validation and type safety. */
47
- schema: T;
48
- /** The name of the cookie. */
49
- name?: string;
50
- /** The cookie's path. Defaults to "/". */
51
- path?: string;
52
- /** Time-to-live for the cookie. Maps to `Max-Age`. */
53
- ttl?: DurationLike;
54
- /** If true, the cookie is only sent over HTTPS. Defaults to true in production. */
55
- secure?: boolean;
56
- /** If true, the cookie cannot be accessed by client-side scripts. */
57
- httpOnly?: boolean;
58
- /** SameSite policy for the cookie. Defaults to "lax". */
59
- sameSite?: "strict" | "lax" | "none";
60
- /** The domain for the cookie. */
61
- domain?: string;
62
- /** If true, the cookie value will be compressed using zlib. */
63
- compress?: boolean;
64
- /** If true, the cookie value will be encrypted. Requires `COOKIE_SECRET` env var. */
65
- encrypt?: boolean;
66
- /** If true, the cookie will be signed to prevent tampering. Requires `COOKIE_SECRET` env var. */
67
- sign?: boolean;
68
- }
69
- interface AbstractCookieDescriptor<T extends TSchema> {
70
- readonly name: string;
71
- readonly options: CookieDescriptorOptions<T>;
72
- set(value: Static<T>, options?: {
73
- cookies?: Cookies;
74
- ttl?: DurationLike;
75
- }): void;
76
- get(options?: {
77
- cookies?: Cookies;
78
- }): Static<T> | undefined;
79
- del(options?: {
80
- cookies?: Cookies;
81
- }): void;
82
- }
83
- interface Cookies {
84
- req: Record<string, string>;
85
- res: Record<string, Cookie | null>;
86
- }
87
- interface Cookie {
88
- value: string;
89
- path?: string;
90
- maxAge?: number;
91
- secure?: boolean;
92
- httpOnly?: boolean;
93
- sameSite?: "strict" | "lax" | "none";
94
- domain?: string;
95
- }
96
- //#endregion
97
- //#region src/server-cookies/index.d.ts
98
- declare module "alepha/server" {
99
- interface ServerRequest {
100
- cookies: Cookies;
101
- }
102
- }
103
- /**
104
- * Provides HTTP cookie management capabilities for server requests and responses with type-safe cookie descriptors.
105
- *
106
- * The server-cookies module enables declarative cookie handling using the `$cookie` descriptor on class properties.
107
- * It offers automatic cookie parsing, secure cookie configuration, and seamless integration with server routes
108
- * for managing user sessions, preferences, and authentication tokens.
109
- *
110
- * @see {@link $cookie}
111
- * @module alepha.server.cookies
112
- */
113
- //#endregion
114
- //#region src/server-security/providers/ServerBasicAuthProvider.d.ts
115
- interface BasicAuthOptions {
116
- username: string;
117
- password: string;
118
- }
119
- //#endregion
120
- //#region src/server-security/providers/ServerSecurityProvider.d.ts
121
- type ServerRouteSecure = {
122
- realm?: string;
123
- basic?: BasicAuthOptions;
124
- };
125
- //#endregion
126
- //#region src/server-security/index.d.ts
127
- declare module "alepha" {
128
- interface State {
129
- /**
130
- * Real (or fake) user account, used for internal actions.
131
- *
132
- * If you define this, you assume that all actions are executed by this user by default.
133
- * > To force a different user, you need to pass it explicitly in the options.
134
- */
135
- "alepha.server.security.system.user"?: UserAccountToken;
136
- /**
137
- * The authenticated user account attached to the server request state.
138
- *
139
- * @internal
140
- */
141
- "alepha.server.request.user"?: UserAccount;
142
- }
143
- }
144
- declare module "alepha/server" {
145
- interface ServerRequest<TConfig> {
146
- user?: UserAccountToken;
147
- }
148
- interface ServerActionRequest<TConfig> {
149
- user: UserAccountToken;
150
- }
151
- interface ServerRoute {
152
- /**
153
- * If true, the route will be protected by the security provider.
154
- * All actions are secure by default, but you can disable it for specific actions.
155
- */
156
- secure?: boolean | ServerRouteSecure;
157
- }
158
- interface ClientRequestOptions extends FetchOptions {
159
- /**
160
- * Forward user from the previous request.
161
- * If "system", use system user. @see {ServerSecurityProvider.localSystemUser}
162
- * If "context", use the user from the current context (e.g. request).
163
- *
164
- * @default "system" if provided, else "context" if available.
165
- */
166
- user?: UserAccountToken | "system" | "context";
167
- }
168
- }
169
- /**
170
- * Plugin for Alepha Server that provides security features. Based on the Alepha Security module.
171
- *
172
- * By default, all $action will be guarded by a permission check.
173
- *
174
- * @see {@link ServerSecurityProvider}
175
- * @module alepha.server.security
176
- */
177
- //#endregion
178
- //#region src/server-links/schemas/apiLinksResponseSchema.d.ts
179
- declare const apiLinkSchema: alepha304.TObject<{
180
- name: alepha304.TString;
181
- group: alepha304.TOptional<alepha304.TString>;
182
- path: alepha304.TString;
183
- method: alepha304.TOptional<alepha304.TString>;
184
- requestBodyType: alepha304.TOptional<alepha304.TString>;
185
- service: alepha304.TOptional<alepha304.TString>;
186
- }>;
187
- declare const apiLinksResponseSchema: alepha304.TObject<{
188
- prefix: alepha304.TOptional<alepha304.TString>;
189
- links: alepha304.TArray<alepha304.TObject<{
190
- name: alepha304.TString;
191
- group: alepha304.TOptional<alepha304.TString>;
192
- path: alepha304.TString;
193
- method: alepha304.TOptional<alepha304.TString>;
194
- requestBodyType: alepha304.TOptional<alepha304.TString>;
195
- service: alepha304.TOptional<alepha304.TString>;
196
- }>>;
197
- }>;
198
- type ApiLinksResponse = Static<typeof apiLinksResponseSchema>;
199
- type ApiLink = Static<typeof apiLinkSchema>;
200
- //#endregion
201
- //#region src/server-links/providers/LinkProvider.d.ts
202
- /**
203
- * Browser, SSR friendly, service to handle links.
204
- */
205
- declare class LinkProvider {
206
- static path: {
207
- apiLinks: string;
208
- apiSchema: string;
209
- };
210
- protected readonly log: alepha_logger2.Logger;
211
- protected readonly alepha: Alepha;
212
- protected readonly httpClient: HttpClient;
213
- protected serverLinks: Array<HttpClientLink>;
214
- /**
215
- * Get applicative links registered on the server.
216
- * This does not include lazy-loaded remote links.
217
- */
218
- getServerLinks(): HttpClientLink[];
219
- /**
220
- * Register a new link for the application.
221
- */
222
- registerLink(link: HttpClientLink): void;
223
- get links(): HttpClientLink[];
224
- /**
225
- * Force browser to refresh links from the server.
226
- */
227
- fetchLinks(): Promise<HttpClientLink[]>;
228
- /**
229
- * Create a virtual client that can be used to call actions.
230
- *
231
- * Use js Proxy under the hood.
232
- */
233
- client<T extends object>(scope?: ClientScope): HttpVirtualClient<T>;
234
- /**
235
- * Check if a link with the given name exists.
236
- * @param name
237
- */
238
- can(name: string): boolean;
239
- /**
240
- * Resolve a link by its name and call it.
241
- * - If link is local, it will call the local handler.
242
- * - If link is remote, it will make a fetch request to the remote server.
243
- */
244
- follow(name: string, config?: Partial<ServerRequestConfigEntry>, options?: ClientRequestOptions & ClientScope): Promise<any>;
245
- protected createVirtualAction<T extends RequestConfigSchema>(name: string, scope?: ClientScope): VirtualAction<T>;
246
- protected followRemote(link: HttpClientLink, config?: Partial<ServerRequestConfigEntry>, options?: ClientRequestOptions): Promise<FetchResponse>;
247
- protected getLinkByName(name: string, options?: ClientScope): Promise<HttpClientLink>;
248
- }
249
- interface HttpClientLink extends ApiLink {
250
- secured?: boolean | ServerRouteSecure;
251
- prefix?: string;
252
- host?: string;
253
- service?: string;
254
- schema?: RequestConfigSchema;
255
- handler?: (request: ServerRequest, options: ClientRequestOptions) => Async<ServerResponseBody>;
256
- }
257
- interface ClientScope {
258
- group?: string;
259
- service?: string;
260
- hostname?: string;
261
- }
262
- type HttpVirtualClient<T> = { [K in keyof T as T[K] extends ActionDescriptor<RequestConfigSchema> ? K : never]: T[K] extends ActionDescriptor<infer Schema> ? VirtualAction<Schema> : never };
263
- interface VirtualAction<T extends RequestConfigSchema> extends Pick<ActionDescriptor<T>, "name" | "run" | "fetch"> {
264
- (config?: ClientRequestEntry<T>, opts?: ClientRequestOptions): Promise<ClientRequestResponse<T>>;
265
- can: () => boolean;
266
- }
267
- //#endregion
268
- //#region src/server-proxy/descriptors/$proxy.d.ts
269
- type ProxyDescriptorOptions = {
270
- /**
271
- * Path pattern to match for proxying requests.
272
- *
273
- * Supports wildcards and path parameters:
274
- * - `/api/*` - Matches all paths starting with `/api/`
275
- * - `/api/v1/*` - Matches all paths starting with `/api/v1/`
276
- * - `/users/:id` - Matches `/users/123`, `/users/abc`, etc.
277
- *
278
- * @example "/api/*"
279
- * @example "/secure/admin/*"
280
- * @example "/users/:id/posts"
281
- */
282
- path: string;
283
- /**
284
- * Target URL to which matching requests should be forwarded.
285
- *
286
- * Can be either:
287
- * - **Static string**: A fixed URL like `"https://api.example.com"`
288
- * - **Dynamic function**: A function that returns the URL, enabling runtime target resolution
289
- *
290
- * The target URL will be combined with the remaining path from the original request.
291
- *
292
- * @example "https://api.example.com"
293
- * @example () => process.env.API_URL || "http://localhost:3001"
294
- */
295
- target: string | (() => string);
296
- /**
297
- * Whether this proxy is disabled.
298
- *
299
- * When `true`, requests matching the path will not be proxied and will be handled
300
- * by other routes or return 404. Useful for feature toggles or conditional proxying.
301
- *
302
- * @default false
303
- * @example !process.env.ENABLE_PROXY
304
- */
305
- disabled?: boolean;
306
- /**
307
- * Hook called before forwarding the request to the target server.
308
- *
309
- * Use this to:
310
- * - Add authentication headers
311
- * - Modify request headers or body
312
- * - Add request tracking/logging
313
- * - Transform the request before forwarding
314
- *
315
- * @param request - The original incoming server request
316
- * @param proxyRequest - The request that will be sent to the target (modifiable)
317
- *
318
- * @example
319
- * ```ts
320
- * beforeRequest: async (request, proxyRequest) => {
321
- * proxyRequest.headers = {
322
- * ...proxyRequest.headers,
323
- * 'Authorization': `Bearer ${await getToken()}`,
324
- * 'X-Request-ID': generateRequestId()
325
- * };
326
- * }
327
- * ```
328
- */
329
- beforeRequest?: (request: ServerRequest, proxyRequest: RequestInit) => Async<void>;
330
- /**
331
- * Hook called after receiving the response from the target server.
332
- *
333
- * Use this to:
334
- * - Log response details for monitoring
335
- * - Add custom headers to the response
336
- * - Transform response data
337
- * - Handle error responses
338
- *
339
- * @param request - The original incoming server request
340
- * @param proxyResponse - The response received from the target server
341
- *
342
- * @example
343
- * ```ts
344
- * afterResponse: async (request, proxyResponse) => {
345
- * console.log(`Proxy ${request.method} ${request.url} -> ${proxyResponse.status}`);
346
- *
347
- * if (!proxyResponse.ok) {
348
- * await logError(`Proxy error: ${proxyResponse.status}`, { request, response: proxyResponse });
349
- * }
350
- * }
351
- * ```
352
- */
353
- afterResponse?: (request: ServerRequest, proxyResponse: Response) => Async<void>;
354
- /**
355
- * Function to rewrite the URL before sending to the target server.
356
- *
357
- * Use this to:
358
- * - Remove or add path prefixes
359
- * - Transform path parameters
360
- * - Modify query parameters
361
- * - Change the URL structure entirely
362
- *
363
- * The function receives a mutable URL object and should modify it in-place.
364
- *
365
- * @param url - The URL object to modify (mutable)
366
- *
367
- * @example
368
- * ```ts
369
- * // Remove /api prefix when forwarding
370
- * rewrite: (url) => {
371
- * url.pathname = url.pathname.replace('/api', '');
372
- * }
373
- * ```
374
- *
375
- * @example
376
- * ```ts
377
- * // Add version prefix
378
- * rewrite: (url) => {
379
- * url.pathname = `/v2${url.pathname}`;
380
- * }
381
- * ```
382
- */
383
- rewrite?: (url: URL) => void;
384
- };
385
- //#endregion
386
- //#region src/server-proxy/providers/ServerProxyProvider.d.ts
387
- declare class ServerProxyProvider {
388
- protected readonly log: alepha_logger2.Logger;
389
- protected readonly routerProvider: ServerRouterProvider;
390
- protected readonly alepha: Alepha;
391
- protected readonly configure: alepha304.HookDescriptor<"configure">;
392
- createProxy(options: ProxyDescriptorOptions): void;
393
- createProxyHandler(target: string, options: Omit<ProxyDescriptorOptions, "path">): ServerHandler;
394
- private getRawRequestBody;
395
- }
396
- //#endregion
397
- //#region src/server-links/descriptors/$remote.d.ts
398
- interface RemoteDescriptorOptions {
399
- /**
400
- * The URL of the remote service.
401
- * You can use a function to generate the URL dynamically.
402
- * You probably should use $env(env) to get the URL from the environment.
403
- *
404
- * @example
405
- * ```ts
406
- * import { $remote } from "alepha/server";
407
- * import { $inject, t } from "alepha";
408
- *
409
- * class App {
410
- * env = $env(t.object({
411
- * REMOTE_URL: t.text({default: "http://localhost:3000"}),
412
- * }));
413
- * remote = $remote({
414
- * url: this.env.REMOTE_URL,
415
- * });
416
- * }
417
- * ```
418
- */
419
- url: string | (() => string);
420
- /**
421
- * The name of the remote service.
422
- *
423
- * @default Member of the class containing the remote service.
424
- */
425
- name?: string;
426
- /**
427
- * If true, all methods of the remote service will be exposed as actions in this context.
428
- * > Note: Proxy will never use the service account, it just... proxies the request.
429
- */
430
- proxy?: boolean | Partial<ProxyDescriptorOptions & {
431
- /**
432
- * If true, the remote service won't be available internally, only through the proxy.
433
- */
434
- noInternal: boolean;
435
- }>;
436
- /**
437
- * For communication between the server and the remote service with a security layer.
438
- * This will be used for internal communication and will not be exposed to the client.
439
- */
440
- serviceAccount?: ServiceAccountDescriptor;
441
- }
442
- declare class RemoteDescriptor extends Descriptor<RemoteDescriptorOptions> {
443
- get name(): string;
444
- }
445
- //#endregion
446
- //#region src/server-links/providers/RemoteDescriptorProvider.d.ts
447
- declare class RemoteDescriptorProvider {
448
- protected readonly env: {
449
- SERVER_API_PREFIX: string;
450
- };
451
- protected readonly alepha: Alepha;
452
- protected readonly proxyProvider: ServerProxyProvider;
453
- protected readonly linkProvider: LinkProvider;
454
- protected readonly remotes: Array<ServerRemote>;
455
- protected readonly log: alepha_logger2.Logger;
456
- getRemotes(): ServerRemote[];
457
- readonly configure: alepha304.HookDescriptor<"configure">;
458
- readonly start: alepha304.HookDescriptor<"start">;
459
- registerRemote(value: RemoteDescriptor): Promise<void>;
460
- protected readonly fetchLinks: alepha_retry0.RetryDescriptorFn<(opts: FetchLinksOptions) => Promise<ApiLinksResponse>>;
461
- }
462
- interface FetchLinksOptions {
463
- /**
464
- * Name of the remote service.
465
- */
466
- service: string;
467
- /**
468
- * URL to fetch links from.
469
- */
470
- url: string;
471
- /**
472
- * Authorization header containing access token.
473
- */
474
- authorization?: string;
475
- }
476
- interface ServerRemote {
477
- /**
478
- * URL of the remote service.
479
- */
480
- url: string;
481
- /**
482
- * Name of the remote service.
483
- */
484
- name: string;
485
- /**
486
- * Expose links as endpoint. It's not only internal.
487
- */
488
- proxy: boolean;
489
- /**
490
- * It's only used inside the application.
491
- */
492
- internal: boolean;
493
- /**
494
- * Links fetcher.
495
- */
496
- links: (args: {
497
- authorization?: string;
498
- }) => Promise<ApiLinksResponse>;
499
- /**
500
- * Fetches schema for the remote service.
501
- */
502
- schema: (args: {
503
- name: string;
504
- authorization?: string;
505
- }) => Promise<any>;
506
- /**
507
- * Force a default access token provider when not provided.
508
- */
509
- serviceAccount?: ServiceAccountDescriptor;
510
- /**
511
- * Prefix for the remote service links.
512
- */
513
- prefix: string;
514
- }
515
- //#endregion
516
- //#region src/server-links/providers/ServerLinksProvider.d.ts
517
- declare class ServerLinksProvider {
518
- protected readonly env: {
519
- SERVER_API_PREFIX: string;
520
- };
521
- protected readonly alepha: Alepha;
522
- protected readonly linkProvider: LinkProvider;
523
- protected readonly remoteProvider: RemoteDescriptorProvider;
524
- protected readonly serverTimingProvider: ServerTimingProvider;
525
- get prefix(): string;
526
- readonly onRoute: alepha304.HookDescriptor<"configure">;
527
- /**
528
- * First API - Get all API links for the user.
529
- *
530
- * This is based on the user's permissions.
531
- */
532
- readonly links: alepha_server6.RouteDescriptor<{
533
- response: alepha304.TObject<{
534
- prefix: alepha304.TOptional<alepha304.TString>;
535
- links: alepha304.TArray<alepha304.TObject<{
536
- name: alepha304.TString;
537
- group: alepha304.TOptional<alepha304.TString>;
538
- path: alepha304.TString;
539
- method: alepha304.TOptional<alepha304.TString>;
540
- requestBodyType: alepha304.TOptional<alepha304.TString>;
541
- service: alepha304.TOptional<alepha304.TString>;
542
- }>>;
543
- }>;
544
- }>;
545
- /**
546
- * Second API - Get schema for a specific API link.
547
- *
548
- * Note: Body/Response schema are not included in `links` API because it's TOO BIG.
549
- * I mean for 150+ links, you got 50ms of serialization time.
550
- */
551
- readonly schema: alepha_server6.RouteDescriptor<{
552
- params: alepha304.TObject<{
553
- name: alepha304.TString;
554
- }>;
555
- response: alepha304.TRecord<string, alepha304.TAny>;
556
- }>;
557
- getSchemaByName(name: string, options?: GetApiLinksOptions): Promise<RequestConfigSchema>;
558
- /**
559
- * Retrieves API links for the user based on their permissions.
560
- * Will check on local links and remote links.
561
- */
562
- getUserApiLinks(options: GetApiLinksOptions): Promise<ApiLinksResponse>;
563
- }
564
- interface GetApiLinksOptions {
565
- user?: UserAccountToken;
566
- authorization?: string;
567
- }
568
- //#endregion
569
- //#region src/server-links/index.d.ts
570
- declare module "alepha" {
571
- interface State {
572
- /**
573
- * API links attached to the server request state.
574
- *
575
- * @see {@link ApiLinksResponse}
576
- * @internal
577
- */
578
- "alepha.server.request.apiLinks"?: ApiLinksResponse;
579
- }
580
- }
581
- /**
582
- * Provides server-side link management and remote capabilities for client-server interactions.
583
- *
584
- * The server-links module enables declarative link definitions using `$remote` and `$client` descriptors,
585
- * facilitating seamless API endpoint management and client-server communication. It integrates with server
586
- * security features to ensure safe and controlled access to resources.
587
- *
588
- * @see {@link $remote}
589
- * @see {@link $client}
590
- * @module alepha.server.links
591
- */
592
- //#endregion
593
- //#region src/server-auth/schemas/authenticationProviderSchema.d.ts
594
- declare const authenticationProviderSchema: alepha304.TObject<{
595
- name: alepha304.TString;
596
- type: alepha304.TUnsafe<"OAUTH2" | "OIDC" | "CREDENTIALS">;
597
- }>;
598
- type AuthenticationProvider = Static<typeof authenticationProviderSchema>;
599
- //#endregion
600
- //#region src/server-auth/schemas/tokensSchema.d.ts
601
- declare const tokensSchema: alepha304.TObject<{
602
- provider: alepha304.TString;
603
- access_token: alepha304.TString;
604
- issued_at: alepha304.TNumber;
605
- expires_in: alepha304.TOptional<alepha304.TNumber>;
606
- refresh_token: alepha304.TOptional<alepha304.TString>;
607
- refresh_token_expires_in: alepha304.TOptional<alepha304.TNumber>;
608
- refresh_expires_in: alepha304.TOptional<alepha304.TNumber>;
609
- id_token: alepha304.TOptional<alepha304.TString>;
610
- scope: alepha304.TOptional<alepha304.TString>;
611
- }>;
612
- type Tokens = Static<typeof tokensSchema>;
613
- //#endregion
614
- //#region src/server-auth/providers/ServerAuthProvider.d.ts
615
- declare class ServerAuthProvider {
616
- protected readonly log: alepha_logger2.Logger;
617
- protected readonly alepha: Alepha;
618
- protected readonly serverCookiesProvider: ServerCookiesProvider;
619
- protected readonly dateTimeProvider: DateTimeProvider;
620
- protected readonly serverLinksProvider: ServerLinksProvider;
621
- protected readonly authorizationCode: AbstractCookieDescriptor<alepha304.TObject<{
622
- provider: alepha304.TString;
623
- codeVerifier: alepha304.TOptional<alepha304.TString>;
624
- redirectUri: alepha304.TOptional<alepha304.TString>;
625
- state: alepha304.TOptional<alepha304.TString>;
626
- nonce: alepha304.TOptional<alepha304.TString>;
627
- }>>;
628
- readonly tokens: AbstractCookieDescriptor<alepha304.TObject<{
629
- provider: alepha304.TString;
630
- access_token: alepha304.TString;
631
- issued_at: alepha304.TNumber;
632
- expires_in: alepha304.TOptional<alepha304.TNumber>;
633
- refresh_token: alepha304.TOptional<alepha304.TString>;
634
- refresh_token_expires_in: alepha304.TOptional<alepha304.TNumber>;
635
- refresh_expires_in: alepha304.TOptional<alepha304.TNumber>;
636
- id_token: alepha304.TOptional<alepha304.TString>;
637
- scope: alepha304.TOptional<alepha304.TString>;
638
- }>>;
639
- get identities(): Array<AuthDescriptor>;
640
- getAuthenticationProviders(filters?: {
641
- realmName?: string;
642
- }): AuthenticationProvider[];
643
- protected readonly configure: alepha304.HookDescriptor<"configure">;
644
- protected getAccessTokens(tokens: Tokens): string | undefined;
645
- /**
646
- * Fill request headers with access token from cookies or fallback to provider's fallback function.
647
- */
648
- protected readonly onRequest: alepha304.HookDescriptor<"server:onRequest">;
649
- /**
650
- * Convert cookies to tokens.
651
- * If the tokens are expired, try to refresh them using the refresh token.
652
- */
653
- protected cookiesToTokens(cookies: Cookies): Promise<Tokens | undefined>;
654
- protected refreshTokens(tokens: Tokens): Promise<Tokens | undefined>;
655
- /**
656
- * Get user information.
657
- */
658
- readonly userinfo: alepha_server6.RouteDescriptor<{
659
- response: alepha304.TObject<{
660
- user: alepha304.TOptional<alepha304.TObject<{
661
- id: alepha304.TString;
662
- name: alepha304.TOptional<alepha304.TString>;
663
- email: alepha304.TOptional<alepha304.TString>;
664
- username: alepha304.TOptional<alepha304.TString>;
665
- picture: alepha304.TOptional<alepha304.TString>;
666
- sessionId: alepha304.TOptional<alepha304.TString>;
667
- organizations: alepha304.TOptional<alepha304.TArray<alepha304.TString>>;
668
- roles: alepha304.TOptional<alepha304.TArray<alepha304.TString>>;
669
- }>>;
670
- api: alepha304.TObject<{
671
- prefix: alepha304.TOptional<alepha304.TString>;
672
- links: alepha304.TArray<alepha304.TObject<{
673
- name: alepha304.TString;
674
- group: alepha304.TOptional<alepha304.TString>;
675
- path: alepha304.TString;
676
- method: alepha304.TOptional<alepha304.TString>;
677
- requestBodyType: alepha304.TOptional<alepha304.TString>;
678
- service: alepha304.TOptional<alepha304.TString>;
679
- }>>;
680
- }>;
681
- }>;
682
- }>;
683
- /**
684
- * Refresh a token for internal providers.
685
- */
686
- readonly refresh: alepha_server6.RouteDescriptor<{
687
- query: alepha304.TObject<{
688
- provider: alepha304.TString;
689
- }>;
690
- body: alepha304.TObject<{
691
- refresh_token: alepha304.TString;
692
- access_token: alepha304.TOptional<alepha304.TString>;
693
- }>;
694
- response: alepha304.TObject<{
695
- provider: alepha304.TString;
696
- access_token: alepha304.TString;
697
- issued_at: alepha304.TNumber;
698
- expires_in: alepha304.TOptional<alepha304.TNumber>;
699
- refresh_token: alepha304.TOptional<alepha304.TString>;
700
- refresh_token_expires_in: alepha304.TOptional<alepha304.TNumber>;
701
- refresh_expires_in: alepha304.TOptional<alepha304.TNumber>;
702
- id_token: alepha304.TOptional<alepha304.TString>;
703
- scope: alepha304.TOptional<alepha304.TString>;
704
- }>;
705
- }>;
706
- /**
707
- * Login for local password-based authentication.
708
- */
709
- readonly token: alepha_server6.RouteDescriptor<{
710
- query: alepha304.TObject<{
711
- provider: alepha304.TString;
712
- }>;
713
- body: alepha304.TObject<{
714
- username: alepha304.TString;
715
- password: alepha304.TString;
716
- }>;
717
- response: alepha304.TObject<{
718
- provider: alepha304.TString;
719
- access_token: alepha304.TString;
720
- issued_at: alepha304.TNumber;
721
- expires_in: alepha304.TOptional<alepha304.TNumber>;
722
- refresh_token: alepha304.TOptional<alepha304.TString>;
723
- refresh_token_expires_in: alepha304.TOptional<alepha304.TNumber>;
724
- refresh_expires_in: alepha304.TOptional<alepha304.TNumber>;
725
- id_token: alepha304.TOptional<alepha304.TString>;
726
- scope: alepha304.TOptional<alepha304.TString>;
727
- user: alepha304.TObject<{
728
- id: alepha304.TString;
729
- name: alepha304.TOptional<alepha304.TString>;
730
- email: alepha304.TOptional<alepha304.TString>;
731
- username: alepha304.TOptional<alepha304.TString>;
732
- picture: alepha304.TOptional<alepha304.TString>;
733
- sessionId: alepha304.TOptional<alepha304.TString>;
734
- organizations: alepha304.TOptional<alepha304.TArray<alepha304.TString>>;
735
- roles: alepha304.TOptional<alepha304.TArray<alepha304.TString>>;
736
- }>;
737
- api: alepha304.TObject<{
738
- prefix: alepha304.TOptional<alepha304.TString>;
739
- links: alepha304.TArray<alepha304.TObject<{
740
- name: alepha304.TString;
741
- group: alepha304.TOptional<alepha304.TString>;
742
- path: alepha304.TString;
743
- method: alepha304.TOptional<alepha304.TString>;
744
- requestBodyType: alepha304.TOptional<alepha304.TString>;
745
- service: alepha304.TOptional<alepha304.TString>;
746
- }>>;
747
- }>;
748
- }>;
749
- }>;
750
- /**
751
- * Oauth2/OIDC login route.
752
- */
753
- readonly login: alepha_server6.RouteDescriptor<{
754
- query: alepha304.TObject<{
755
- provider: alepha304.TString;
756
- redirect_uri: alepha304.TOptional<alepha304.TString>;
757
- }>;
758
- }>;
759
- /**
760
- * Callback for OAuth2/OIDC providers.
761
- * It handles the authorization code flow and retrieves the access token.
762
- */
763
- readonly callback: alepha_server6.RouteDescriptor<alepha_server6.RequestConfigSchema>;
764
- /**
765
- * Logout route for OAuth2/OIDC providers.
766
- */
767
- readonly logout: alepha_server6.RouteDescriptor<{
768
- query: alepha304.TObject<{
769
- post_logout_redirect_uri: alepha304.TOptional<alepha304.TString>;
770
- }>;
771
- }>;
772
- protected provider(opts: string | {
773
- provider: string;
774
- }): AuthDescriptor;
775
- protected setTokens(tokens: Tokens, cookies?: Cookies): void;
776
- }
777
- interface OAuth2Profile {
778
- sub: string;
779
- email?: string;
780
- name?: string;
781
- given_name?: string;
782
- family_name?: string;
783
- middle_name?: string;
784
- nickname?: string;
785
- preferred_username?: string;
786
- profile?: string;
787
- picture?: string;
788
- website?: string;
789
- email_verified?: boolean;
790
- gender?: string;
791
- birthdate?: string;
792
- zoneinfo?: string;
793
- locale?: string;
794
- phone_number?: string;
795
- phone_number_verified?: boolean;
796
- address?: {
797
- formatted?: string;
798
- street_address?: string;
799
- locality?: string;
800
- region?: string;
801
- postal_code?: string;
802
- country?: string;
803
- };
804
- updated_at?: number;
805
- [key: string]: unknown;
806
- }
807
- //#endregion
808
- //#region src/server-auth/descriptors/$auth.d.ts
809
- /**
810
- * Creates an authentication provider descriptor for handling user login flows.
811
- *
812
- * Supports multiple authentication strategies: credentials (username/password), OAuth2,
813
- * and OIDC (OpenID Connect). Handles token management, user profile retrieval, and
814
- * integration with both external identity providers (Auth0, Keycloak) and internal realms.
815
- *
816
- * **Authentication Types**: Credentials, OAuth2 (Google, GitHub), OIDC, External providers
817
- *
818
- * @example
819
- * ```ts
820
- * class AuthProviders {
821
- * // Internal credentials-based auth
822
- * credentials = $auth({
823
- * realm: this.userRealm,
824
- * credentials: {
825
- * account: async ({ username, password }) => {
826
- * return await this.validateUser(username, password);
827
- * }
828
- * }
829
- * });
830
- *
831
- * // External OIDC provider
832
- * keycloak = $auth({
833
- * oidc: {
834
- * issuer: "https://auth.example.com",
835
- * clientId: "my-app",
836
- * clientSecret: "secret",
837
- * redirectUri: "/auth/callback"
838
- * }
839
- * });
840
- * }
841
- * ```
842
- */
843
- declare const $auth: {
844
- (options: AuthDescriptorOptions): AuthDescriptor;
845
- [KIND]: typeof AuthDescriptor;
846
- };
847
- type AuthDescriptorOptions = {
848
- /**
849
- * Name of the identity provider.
850
- * If not provided, it will be derived from the property key.
851
- */
852
- name?: string;
853
- /**
854
- * If true, auth provider will be skipped.
855
- */
856
- disabled?: boolean;
857
- } & (AuthExternal | AuthInternal);
858
- /**
859
- * When you let an external service handle authentication. (e.g. Keycloak, Auth0, etc.)
860
- */
861
- type AuthExternal = {
862
- /**
863
- * Only OIDC is supported for external authentication.
864
- */
865
- oidc: OidcOptions;
866
- /**
867
- * For anonymous access, this will expect a service account access token.
868
- *
869
- * ```ts
870
- * class App {
871
- * anonymous = $serviceAccount(...);
872
- * auth = $auth({
873
- * // ... config ...
874
- * fallback: this.anonymous,
875
- * })
876
- * }
877
- * ```
878
- */
879
- fallback?: () => Async<AccessToken>;
880
- };
881
- /**
882
- * When using your own authentication system, e.g. using a database to store user accounts.
883
- * This is usually used with a custom login form.
884
- *
885
- * This relies on the `realm`, which is used to create/verify the access token.
886
- */
887
- type AuthInternal = {
888
- realm: RealmDescriptor;
889
- } & ({
890
- /**
891
- * The common username/password authentication.
892
- *
893
- * - It uses the OAuth2 Client Credentials flow to obtain an access token.
894
- *
895
- * This is usually used with a custom login form on your website or mobile app.
896
- */
897
- credentials: CredentialsOptions;
898
- } | {
899
- /**
900
- * OAuth2 authentication. Delegates authentication to an OAuth2 provider. (e.g. Google, GitHub, etc.)
901
- *
902
- * - It uses the OAuth2 Authorization Code flow to obtain an access token and user information.
903
- *
904
- * This is usually used with a login button that redirects to the OAuth2 provider.
905
- */
906
- oauth: OAuth2Options;
907
- } | {
908
- /**
909
- * Like OAuth2, but uses OIDC (OpenID Connect) for authentication and user information retrieval.
910
- * OIDC is an identity layer on top of OAuth2, providing user authentication and profile information.
911
- *
912
- * - It uses the OAuth2 Authorization Code flow to obtain an access token and user information.
913
- * - PCKE (Proof Key for Code Exchange) is recommended for security.
914
- *
915
- * This is usually used with a login button that redirects to the OIDC provider.
916
- */
917
- oidc: OidcOptions;
918
- });
919
- type CredentialsOptions = {
920
- account: CredentialsFn;
921
- };
922
- type CredentialsFn = (credentials: Credentials) => Async<UserAccount | undefined>;
923
- interface Credentials {
924
- username: string;
925
- password: string;
926
- }
927
- interface OidcOptions {
928
- /**
929
- * URL of the OIDC issuer.
930
- */
931
- issuer: string;
932
- /**
933
- * Client ID for the OIDC client.
934
- */
935
- clientId: string;
936
- /**
937
- * Client secret for the OIDC client.
938
- * Optional if PKCE (Proof Key for Code Exchange) is used.
939
- */
940
- clientSecret?: string;
941
- /**
942
- * Redirect URI for the OIDC client.
943
- * This is where the user will be redirected after authentication.
944
- */
945
- redirectUri?: string;
946
- /**
947
- * For external auth providers only.
948
- * Take the ID token instead of the access token for validation.
949
- */
950
- useIdToken?: boolean;
951
- /**
952
- * URI to redirect the user after logout.
953
- */
954
- logoutUri?: string;
955
- /**
956
- * Optional scope for the OIDC client.
957
- * @default "openid profile email".
958
- */
959
- scope?: string;
960
- account?: LinkAccountFn;
961
- }
962
- interface LinkAccountOptions {
963
- access_token: string;
964
- user: OAuth2Profile;
965
- id_token?: string;
966
- expires_in?: number;
967
- scope?: string;
968
- }
969
- type LinkAccountFn = (tokens: LinkAccountOptions) => Async<UserAccount>;
970
- interface OAuth2Options {
971
- /**
972
- * URL of the OAuth2 authorization endpoint.
973
- */
974
- clientId: string;
975
- /**
976
- * Client secret for the OAuth2 client.
977
- */
978
- clientSecret: string;
979
- /**
980
- * URL of the OAuth2 authorization endpoint.
981
- */
982
- authorization: string;
983
- /**
984
- * URL of the OAuth2 token endpoint.
985
- */
986
- token: string;
987
- /**
988
- * Function to retrieve user profile information from the OAuth2 tokens.
989
- */
990
- userinfo: (tokens: Tokens) => Async<OAuth2Profile>;
991
- account?: LinkAccountFn;
992
- /**
993
- * URL of the OAuth2 authorization endpoint.
994
- */
995
- redirectUri?: string;
996
- /**
997
- * URL of the OAuth2 authorization endpoint.
998
- */
999
- scope?: string;
1000
- }
1001
- declare class AuthDescriptor extends Descriptor<AuthDescriptorOptions> {
1002
- protected readonly securityProvider: SecurityProvider;
1003
- protected readonly dateTimeProvider: DateTimeProvider;
1004
- oauth?: Configuration;
1005
- get name(): string;
1006
- get jwks_uri(): string;
1007
- get scope(): string | undefined;
1008
- get redirect_uri(): string | undefined;
1009
- /**
1010
- * Refreshes the access token using the refresh token.
1011
- * Can be used on oauth2, oidc or credentials auth providers.
1012
- */
1013
- refresh(refreshToken: string, accessToken?: string): Promise<AccessTokenResponse>;
1014
- /**
1015
- * Extracts user information from the access token.
1016
- * This is used to create a user account from the access token.
1017
- */
1018
- user(tokens: Tokens): Promise<UserAccount>;
1019
- protected getUserFromIdToken(idToken: string): OAuth2Profile;
1020
- prepare(): Promise<void>;
1021
- }
1022
- type AccessToken = string | {
1023
- token: () => Async<string>;
1024
- };
1025
- interface WithLinkFn {
1026
- link?: (name: string) => (opts: LinkAccountOptions) => Async<UserAccount>;
1027
- }
1028
- interface WithLoginFn {
1029
- login?: (provider: string) => (creds: Credentials) => Async<UserAccount | undefined>;
1030
- }
1031
- //#endregion
1032
- //#region src/server-auth/descriptors/$authCredentials.d.ts
1033
- /**
1034
- * Already configured Credentials authentication descriptor.
1035
- *
1036
- * Uses username and password to authenticate users.
1037
- */
1038
- declare const $authCredentials: (realm: RealmDescriptor & WithLoginFn, options?: Partial<CredentialsOptions>) => AuthDescriptor;
1039
- //#endregion
1040
- //#region src/server-auth/descriptors/$authGithub.d.ts
1041
- /**
1042
- * Already configured GitHub authentication descriptor.
1043
- *
1044
- * Uses OAuth2 to authenticate users via their GitHub accounts.
1045
- * Upon successful authentication, it links the GitHub account to a user session.
1046
- *
1047
- * Environment Variables:
1048
- * - `GITHUB_CLIENT_ID`: The client ID obtained from the GitHub Developer Settings.
1049
- * - `GITHUB_CLIENT_SECRET`: The client secret obtained from the GitHub Developer Settings.
1050
- */
1051
- declare const $authGithub: (realm: RealmDescriptor & WithLinkFn, options?: Partial<OidcOptions>) => AuthDescriptor;
1052
- //#endregion
1053
- //#region src/server-auth/descriptors/$authGoogle.d.ts
1054
- /**
1055
- * Already configured Google authentication descriptor.
1056
- *
1057
- * Uses OpenID Connect (OIDC) to authenticate users via their Google accounts.
1058
- * Upon successful authentication, it links the Google account to a user session.
1059
- *
1060
- * Environment Variables:
1061
- * - `GOOGLE_CLIENT_ID`: The client ID obtained from the Google Developer Console.
1062
- * - `GOOGLE_CLIENT_SECRET`: The client secret obtained from the Google Developer Console.
1063
- */
1064
- declare const $authGoogle: (realm: RealmDescriptor & WithLinkFn, options?: Partial<OidcOptions>) => AuthDescriptor;
1065
- //#endregion
1066
- //#region src/server-auth/constants/routes.d.ts
1067
- declare const alephaServerAuthRoutes: {
1068
- login: string;
1069
- callback: string;
1070
- logout: string;
1071
- token: string;
1072
- refresh: string;
1073
- userinfo: string;
1074
- };
1075
- //#endregion
1076
- //#region src/server-auth/schemas/tokenResponseSchema.d.ts
1077
- declare const tokenResponseSchema: alepha304.TObject<{
1078
- provider: alepha304.TString;
1079
- access_token: alepha304.TString;
1080
- issued_at: alepha304.TNumber;
1081
- expires_in: alepha304.TOptional<alepha304.TNumber>;
1082
- refresh_token: alepha304.TOptional<alepha304.TString>;
1083
- refresh_token_expires_in: alepha304.TOptional<alepha304.TNumber>;
1084
- refresh_expires_in: alepha304.TOptional<alepha304.TNumber>;
1085
- id_token: alepha304.TOptional<alepha304.TString>;
1086
- scope: alepha304.TOptional<alepha304.TString>;
1087
- user: alepha304.TObject<{
1088
- id: alepha304.TString;
1089
- name: alepha304.TOptional<alepha304.TString>;
1090
- email: alepha304.TOptional<alepha304.TString>;
1091
- username: alepha304.TOptional<alepha304.TString>;
1092
- picture: alepha304.TOptional<alepha304.TString>;
1093
- sessionId: alepha304.TOptional<alepha304.TString>;
1094
- organizations: alepha304.TOptional<alepha304.TArray<alepha304.TString>>;
1095
- roles: alepha304.TOptional<alepha304.TArray<alepha304.TString>>;
1096
- }>;
1097
- api: alepha304.TObject<{
1098
- prefix: alepha304.TOptional<alepha304.TString>;
1099
- links: alepha304.TArray<alepha304.TObject<{
1100
- name: alepha304.TString;
1101
- group: alepha304.TOptional<alepha304.TString>;
1102
- path: alepha304.TString;
1103
- method: alepha304.TOptional<alepha304.TString>;
1104
- requestBodyType: alepha304.TOptional<alepha304.TString>;
1105
- service: alepha304.TOptional<alepha304.TString>;
1106
- }>>;
1107
- }>;
1108
- }>;
1109
- type TokenResponse = Static<typeof tokenResponseSchema>;
1110
- //#endregion
1111
- //#region src/server-auth/schemas/userinfoResponseSchema.d.ts
1112
- declare const userinfoResponseSchema: alepha304.TObject<{
1113
- user: alepha304.TOptional<alepha304.TObject<{
1114
- id: alepha304.TString;
1115
- name: alepha304.TOptional<alepha304.TString>;
1116
- email: alepha304.TOptional<alepha304.TString>;
1117
- username: alepha304.TOptional<alepha304.TString>;
1118
- picture: alepha304.TOptional<alepha304.TString>;
1119
- sessionId: alepha304.TOptional<alepha304.TString>;
1120
- organizations: alepha304.TOptional<alepha304.TArray<alepha304.TString>>;
1121
- roles: alepha304.TOptional<alepha304.TArray<alepha304.TString>>;
1122
- }>>;
1123
- api: alepha304.TObject<{
1124
- prefix: alepha304.TOptional<alepha304.TString>;
1125
- links: alepha304.TArray<alepha304.TObject<{
1126
- name: alepha304.TString;
1127
- group: alepha304.TOptional<alepha304.TString>;
1128
- path: alepha304.TString;
1129
- method: alepha304.TOptional<alepha304.TString>;
1130
- requestBodyType: alepha304.TOptional<alepha304.TString>;
1131
- service: alepha304.TOptional<alepha304.TString>;
1132
- }>>;
1133
- }>;
1134
- }>;
1135
- type UserinfoResponse = Static<typeof userinfoResponseSchema>;
1136
- //#endregion
1137
- //#region src/server-auth/index.d.ts
1138
- declare module "alepha" {
1139
- interface State {
1140
- /**
1141
- * The authenticated user account attached to the server request state.
1142
- *
1143
- * @internal
1144
- */
1145
- "alepha.server.request.user"?: UserAccount;
1146
- }
1147
- }
1148
- /**
1149
- * Allow authentication services for server applications.
1150
- * It provides login and logout functionalities.
1151
- *
1152
- * There are multiple authentication providers available (e.g., Google, GitHub).
1153
- * You can also delegate authentication to your own OIDC/OAuth2, for example using Keycloak or Auth0.
1154
- *
1155
- * It's cookie-based and SSR friendly.
1156
- *
1157
- * @see {@link $auth}
1158
- * @see {@link ServerAuthProvider}
1159
- * @module alepha.server.auth
1160
- */
1161
- declare const AlephaServerAuth: alepha304.Service<alepha304.Module>;
1162
- //#endregion
1163
- export { $auth, $authCredentials, $authGithub, $authGoogle, AccessToken, AlephaServerAuth, AuthDescriptor, AuthDescriptorOptions, AuthExternal, AuthInternal, AuthenticationProvider, Credentials, CredentialsFn, CredentialsOptions, LinkAccountFn, LinkAccountOptions, OAuth2Options, OAuth2Profile, OidcOptions, ServerAuthProvider, TokenResponse, Tokens, UserinfoResponse, WithLinkFn, WithLoginFn, alephaServerAuthRoutes, authenticationProviderSchema, tokenResponseSchema, tokensSchema, userinfoResponseSchema };
1164
- //# sourceMappingURL=index.d.cts.map