alepha 0.14.4 → 0.15.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 (277) hide show
  1. package/README.md +1 -4
  2. package/dist/api/audits/index.d.ts +619 -731
  3. package/dist/api/audits/index.d.ts.map +1 -1
  4. package/dist/api/files/index.d.ts +185 -298
  5. package/dist/api/files/index.d.ts.map +1 -1
  6. package/dist/api/files/index.js +0 -1
  7. package/dist/api/files/index.js.map +1 -1
  8. package/dist/api/jobs/index.d.ts +245 -356
  9. package/dist/api/jobs/index.d.ts.map +1 -1
  10. package/dist/api/notifications/index.d.ts +238 -350
  11. package/dist/api/notifications/index.d.ts.map +1 -1
  12. package/dist/api/parameters/index.d.ts +499 -611
  13. package/dist/api/parameters/index.d.ts.map +1 -1
  14. package/dist/api/users/index.browser.js +1 -2
  15. package/dist/api/users/index.browser.js.map +1 -1
  16. package/dist/api/users/index.d.ts +1697 -1804
  17. package/dist/api/users/index.d.ts.map +1 -1
  18. package/dist/api/users/index.js +178 -151
  19. package/dist/api/users/index.js.map +1 -1
  20. package/dist/api/verifications/index.d.ts +132 -132
  21. package/dist/api/verifications/index.d.ts.map +1 -1
  22. package/dist/batch/index.d.ts +122 -122
  23. package/dist/batch/index.d.ts.map +1 -1
  24. package/dist/batch/index.js +1 -2
  25. package/dist/batch/index.js.map +1 -1
  26. package/dist/bucket/index.d.ts +163 -163
  27. package/dist/bucket/index.d.ts.map +1 -1
  28. package/dist/cache/core/index.d.ts +46 -46
  29. package/dist/cache/core/index.d.ts.map +1 -1
  30. package/dist/cache/redis/index.d.ts.map +1 -1
  31. package/dist/cli/index.d.ts +302 -299
  32. package/dist/cli/index.d.ts.map +1 -1
  33. package/dist/cli/index.js +966 -564
  34. package/dist/cli/index.js.map +1 -1
  35. package/dist/command/index.d.ts +303 -299
  36. package/dist/command/index.d.ts.map +1 -1
  37. package/dist/command/index.js +11 -7
  38. package/dist/command/index.js.map +1 -1
  39. package/dist/core/index.browser.js +419 -99
  40. package/dist/core/index.browser.js.map +1 -1
  41. package/dist/core/index.d.ts +718 -625
  42. package/dist/core/index.d.ts.map +1 -1
  43. package/dist/core/index.js +420 -99
  44. package/dist/core/index.js.map +1 -1
  45. package/dist/core/index.native.js +419 -99
  46. package/dist/core/index.native.js.map +1 -1
  47. package/dist/datetime/index.d.ts +44 -44
  48. package/dist/datetime/index.d.ts.map +1 -1
  49. package/dist/datetime/index.js +4 -4
  50. package/dist/datetime/index.js.map +1 -1
  51. package/dist/email/index.d.ts +97 -50
  52. package/dist/email/index.d.ts.map +1 -1
  53. package/dist/email/index.js +129 -33
  54. package/dist/email/index.js.map +1 -1
  55. package/dist/fake/index.d.ts +7981 -14
  56. package/dist/fake/index.d.ts.map +1 -1
  57. package/dist/file/index.d.ts +523 -390
  58. package/dist/file/index.d.ts.map +1 -1
  59. package/dist/file/index.js +253 -1
  60. package/dist/file/index.js.map +1 -1
  61. package/dist/lock/core/index.d.ts +208 -208
  62. package/dist/lock/core/index.d.ts.map +1 -1
  63. package/dist/lock/redis/index.d.ts.map +1 -1
  64. package/dist/logger/index.d.ts +25 -26
  65. package/dist/logger/index.d.ts.map +1 -1
  66. package/dist/mcp/index.d.ts +197 -197
  67. package/dist/mcp/index.d.ts.map +1 -1
  68. package/dist/orm/chunk-DtkW-qnP.js +38 -0
  69. package/dist/orm/index.browser.js.map +1 -1
  70. package/dist/orm/index.bun.js +2814 -0
  71. package/dist/orm/index.bun.js.map +1 -0
  72. package/dist/orm/index.d.ts +1205 -1057
  73. package/dist/orm/index.d.ts.map +1 -1
  74. package/dist/orm/index.js +2056 -1753
  75. package/dist/orm/index.js.map +1 -1
  76. package/dist/queue/core/index.d.ts +248 -248
  77. package/dist/queue/core/index.d.ts.map +1 -1
  78. package/dist/queue/redis/index.d.ts.map +1 -1
  79. package/dist/redis/index.bun.js +285 -0
  80. package/dist/redis/index.bun.js.map +1 -0
  81. package/dist/redis/index.d.ts +118 -136
  82. package/dist/redis/index.d.ts.map +1 -1
  83. package/dist/redis/index.js +18 -38
  84. package/dist/redis/index.js.map +1 -1
  85. package/dist/retry/index.d.ts +69 -69
  86. package/dist/retry/index.d.ts.map +1 -1
  87. package/dist/router/index.d.ts +6 -6
  88. package/dist/router/index.d.ts.map +1 -1
  89. package/dist/scheduler/index.d.ts +25 -25
  90. package/dist/scheduler/index.d.ts.map +1 -1
  91. package/dist/security/index.browser.js +5 -1
  92. package/dist/security/index.browser.js.map +1 -1
  93. package/dist/security/index.d.ts +417 -254
  94. package/dist/security/index.d.ts.map +1 -1
  95. package/dist/security/index.js +386 -86
  96. package/dist/security/index.js.map +1 -1
  97. package/dist/server/auth/index.d.ts +277 -277
  98. package/dist/server/auth/index.d.ts.map +1 -1
  99. package/dist/server/auth/index.js +20 -20
  100. package/dist/server/auth/index.js.map +1 -1
  101. package/dist/server/cache/index.d.ts +60 -57
  102. package/dist/server/cache/index.d.ts.map +1 -1
  103. package/dist/server/cache/index.js +1 -1
  104. package/dist/server/cache/index.js.map +1 -1
  105. package/dist/server/compress/index.d.ts +3 -3
  106. package/dist/server/compress/index.d.ts.map +1 -1
  107. package/dist/server/cookies/index.d.ts +6 -6
  108. package/dist/server/cookies/index.d.ts.map +1 -1
  109. package/dist/server/cookies/index.js +3 -3
  110. package/dist/server/cookies/index.js.map +1 -1
  111. package/dist/server/core/index.d.ts +242 -150
  112. package/dist/server/core/index.d.ts.map +1 -1
  113. package/dist/server/core/index.js +288 -122
  114. package/dist/server/core/index.js.map +1 -1
  115. package/dist/server/cors/index.d.ts +11 -12
  116. package/dist/server/cors/index.d.ts.map +1 -1
  117. package/dist/server/health/index.d.ts +0 -1
  118. package/dist/server/health/index.d.ts.map +1 -1
  119. package/dist/server/helmet/index.d.ts +2 -2
  120. package/dist/server/helmet/index.d.ts.map +1 -1
  121. package/dist/server/links/index.browser.js.map +1 -1
  122. package/dist/server/links/index.d.ts +84 -85
  123. package/dist/server/links/index.d.ts.map +1 -1
  124. package/dist/server/links/index.js +1 -2
  125. package/dist/server/links/index.js.map +1 -1
  126. package/dist/server/metrics/index.d.ts.map +1 -1
  127. package/dist/server/multipart/index.d.ts +6 -6
  128. package/dist/server/multipart/index.d.ts.map +1 -1
  129. package/dist/server/proxy/index.d.ts +102 -103
  130. package/dist/server/proxy/index.d.ts.map +1 -1
  131. package/dist/server/rate-limit/index.d.ts +16 -16
  132. package/dist/server/rate-limit/index.d.ts.map +1 -1
  133. package/dist/server/static/index.d.ts +44 -44
  134. package/dist/server/static/index.d.ts.map +1 -1
  135. package/dist/server/swagger/index.d.ts +48 -49
  136. package/dist/server/swagger/index.d.ts.map +1 -1
  137. package/dist/server/swagger/index.js +1 -2
  138. package/dist/server/swagger/index.js.map +1 -1
  139. package/dist/sms/index.d.ts +13 -11
  140. package/dist/sms/index.d.ts.map +1 -1
  141. package/dist/sms/index.js +7 -7
  142. package/dist/sms/index.js.map +1 -1
  143. package/dist/thread/index.d.ts +71 -72
  144. package/dist/thread/index.d.ts.map +1 -1
  145. package/dist/topic/core/index.d.ts +318 -318
  146. package/dist/topic/core/index.d.ts.map +1 -1
  147. package/dist/topic/redis/index.d.ts +6 -6
  148. package/dist/topic/redis/index.d.ts.map +1 -1
  149. package/dist/vite/index.d.ts +5720 -159
  150. package/dist/vite/index.d.ts.map +1 -1
  151. package/dist/vite/index.js +41 -18
  152. package/dist/vite/index.js.map +1 -1
  153. package/dist/websocket/index.browser.js +6 -6
  154. package/dist/websocket/index.browser.js.map +1 -1
  155. package/dist/websocket/index.d.ts +247 -247
  156. package/dist/websocket/index.d.ts.map +1 -1
  157. package/dist/websocket/index.js +6 -6
  158. package/dist/websocket/index.js.map +1 -1
  159. package/package.json +9 -14
  160. package/src/api/files/controllers/AdminFileStatsController.ts +0 -1
  161. package/src/api/users/atoms/realmAuthSettingsAtom.ts +5 -0
  162. package/src/api/users/controllers/{UserRealmController.ts → RealmController.ts} +11 -11
  163. package/src/api/users/entities/users.ts +1 -1
  164. package/src/api/users/index.ts +8 -8
  165. package/src/api/users/primitives/{$userRealm.ts → $realm.ts} +17 -19
  166. package/src/api/users/providers/{UserRealmProvider.ts → RealmProvider.ts} +26 -30
  167. package/src/api/users/schemas/{userRealmConfigSchema.ts → realmConfigSchema.ts} +2 -2
  168. package/src/api/users/services/CredentialService.ts +7 -7
  169. package/src/api/users/services/IdentityService.ts +4 -4
  170. package/src/api/users/services/RegistrationService.spec.ts +25 -27
  171. package/src/api/users/services/RegistrationService.ts +38 -27
  172. package/src/api/users/services/SessionCrudService.ts +3 -3
  173. package/src/api/users/services/SessionService.spec.ts +3 -3
  174. package/src/api/users/services/SessionService.ts +28 -9
  175. package/src/api/users/services/UserService.ts +7 -7
  176. package/src/batch/providers/BatchProvider.ts +1 -2
  177. package/src/cli/apps/AlephaPackageBuilderCli.ts +38 -19
  178. package/src/cli/assets/apiHelloControllerTs.ts +18 -0
  179. package/src/cli/assets/apiIndexTs.ts +16 -0
  180. package/src/cli/assets/claudeMd.ts +303 -0
  181. package/src/cli/assets/mainBrowserTs.ts +2 -2
  182. package/src/cli/assets/mainServerTs.ts +24 -0
  183. package/src/cli/assets/webAppRouterTs.ts +15 -0
  184. package/src/cli/assets/webHelloComponentTsx.ts +16 -0
  185. package/src/cli/assets/webIndexTs.ts +16 -0
  186. package/src/cli/commands/build.ts +41 -21
  187. package/src/cli/commands/db.ts +21 -18
  188. package/src/cli/commands/deploy.ts +17 -5
  189. package/src/cli/commands/dev.ts +13 -17
  190. package/src/cli/commands/format.ts +8 -2
  191. package/src/cli/commands/init.ts +74 -29
  192. package/src/cli/commands/lint.ts +8 -2
  193. package/src/cli/commands/test.ts +8 -2
  194. package/src/cli/commands/typecheck.ts +5 -1
  195. package/src/cli/commands/verify.ts +4 -2
  196. package/src/cli/services/AlephaCliUtils.ts +39 -600
  197. package/src/cli/services/PackageManagerUtils.ts +301 -0
  198. package/src/cli/services/ProjectScaffolder.ts +306 -0
  199. package/src/command/helpers/Runner.ts +15 -3
  200. package/src/core/__tests__/Alepha-graph.spec.ts +4 -0
  201. package/src/core/index.shared.ts +1 -0
  202. package/src/core/index.ts +2 -0
  203. package/src/core/primitives/$hook.ts +6 -2
  204. package/src/core/primitives/$module.spec.ts +4 -0
  205. package/src/core/providers/AlsProvider.ts +1 -1
  206. package/src/core/providers/CodecManager.spec.ts +12 -6
  207. package/src/core/providers/CodecManager.ts +26 -6
  208. package/src/core/providers/EventManager.ts +169 -13
  209. package/src/core/providers/KeylessJsonSchemaCodec.spec.ts +621 -0
  210. package/src/core/providers/KeylessJsonSchemaCodec.ts +407 -0
  211. package/src/core/providers/StateManager.spec.ts +27 -16
  212. package/src/email/providers/LocalEmailProvider.spec.ts +111 -87
  213. package/src/email/providers/LocalEmailProvider.ts +52 -15
  214. package/src/email/providers/NodemailerEmailProvider.ts +167 -56
  215. package/src/file/errors/FileError.ts +7 -0
  216. package/src/file/index.ts +9 -1
  217. package/src/file/providers/MemoryFileSystemProvider.ts +393 -0
  218. package/src/orm/index.browser.ts +1 -19
  219. package/src/orm/index.bun.ts +77 -0
  220. package/src/orm/index.shared-server.ts +22 -0
  221. package/src/orm/index.shared.ts +15 -0
  222. package/src/orm/index.ts +19 -39
  223. package/src/orm/providers/drivers/BunPostgresProvider.ts +3 -5
  224. package/src/orm/providers/drivers/BunSqliteProvider.ts +1 -1
  225. package/src/orm/providers/drivers/CloudflareD1Provider.ts +4 -0
  226. package/src/orm/providers/drivers/DatabaseProvider.ts +4 -0
  227. package/src/orm/providers/drivers/PglitePostgresProvider.ts +4 -0
  228. package/src/orm/services/Repository.ts +8 -0
  229. package/src/redis/index.bun.ts +35 -0
  230. package/src/redis/providers/BunRedisProvider.ts +12 -43
  231. package/src/redis/providers/BunRedisSubscriberProvider.ts +2 -3
  232. package/src/redis/providers/NodeRedisProvider.ts +16 -34
  233. package/src/{server/security → security}/__tests__/BasicAuth.spec.ts +11 -11
  234. package/src/{server/security → security}/__tests__/ServerSecurityProvider-realm.spec.ts +21 -16
  235. package/src/{server/security/providers → security/__tests__}/ServerSecurityProvider.spec.ts +5 -5
  236. package/src/security/index.browser.ts +5 -0
  237. package/src/security/index.ts +90 -7
  238. package/src/security/primitives/{$realm.spec.ts → $issuer.spec.ts} +11 -11
  239. package/src/security/primitives/{$realm.ts → $issuer.ts} +20 -17
  240. package/src/security/primitives/$role.ts +5 -5
  241. package/src/security/primitives/$serviceAccount.spec.ts +5 -5
  242. package/src/security/primitives/$serviceAccount.ts +3 -3
  243. package/src/{server/security → security}/providers/ServerSecurityProvider.ts +5 -7
  244. package/src/server/auth/primitives/$auth.ts +10 -10
  245. package/src/server/auth/primitives/$authCredentials.ts +3 -3
  246. package/src/server/auth/primitives/$authGithub.ts +3 -3
  247. package/src/server/auth/primitives/$authGoogle.ts +3 -3
  248. package/src/server/auth/providers/ServerAuthProvider.ts +13 -13
  249. package/src/server/cache/providers/ServerCacheProvider.ts +1 -1
  250. package/src/server/cookies/providers/ServerCookiesProvider.ts +3 -3
  251. package/src/server/core/providers/NodeHttpServerProvider.ts +25 -6
  252. package/src/server/core/providers/ServerBodyParserProvider.ts +19 -23
  253. package/src/server/core/providers/ServerLoggerProvider.ts +23 -19
  254. package/src/server/core/providers/ServerProvider.ts +144 -21
  255. package/src/server/core/providers/ServerRouterProvider.ts +259 -115
  256. package/src/server/core/providers/ServerTimingProvider.ts +2 -2
  257. package/src/server/links/index.ts +1 -1
  258. package/src/server/links/providers/LinkProvider.ts +1 -1
  259. package/src/server/swagger/index.ts +1 -1
  260. package/src/sms/providers/LocalSmsProvider.spec.ts +153 -111
  261. package/src/sms/providers/LocalSmsProvider.ts +8 -7
  262. package/src/vite/helpers/boot.ts +28 -17
  263. package/src/vite/tasks/buildServer.ts +12 -1
  264. package/src/vite/tasks/devServer.ts +3 -1
  265. package/src/vite/tasks/generateCloudflare.ts +7 -0
  266. package/dist/server/security/index.browser.js +0 -13
  267. package/dist/server/security/index.browser.js.map +0 -1
  268. package/dist/server/security/index.d.ts +0 -173
  269. package/dist/server/security/index.d.ts.map +0 -1
  270. package/dist/server/security/index.js +0 -311
  271. package/dist/server/security/index.js.map +0 -1
  272. package/src/cli/assets/appRouterTs.ts +0 -9
  273. package/src/cli/assets/mainTs.ts +0 -13
  274. package/src/server/security/index.browser.ts +0 -10
  275. package/src/server/security/index.ts +0 -94
  276. /package/src/{server/security → security}/primitives/$basicAuth.ts +0 -0
  277. /package/src/{server/security → security}/providers/ServerBasicAuthProvider.ts +0 -0
@@ -1,24 +1,45 @@
1
- import * as alepha1 from "alepha";
1
+ import * as alepha3 from "alepha";
2
2
  import { Alepha, KIND, Primitive, Static } from "alepha";
3
- import * as alepha_logger0 from "alepha/logger";
3
+ import { FetchOptions, ServerRequest, ServerRouterProvider, UnauthorizedError } from "alepha/server";
4
+ import * as alepha_logger2 from "alepha/logger";
4
5
  import { DateTimeProvider, Duration, DurationLike } from "alepha/datetime";
5
6
  import { CryptoKey, FlattenedJWSInput, JSONWebKeySet, JWSHeaderParameters, JWTHeaderParameters, JWTPayload, JWTVerifyResult, KeyObject } from "jose";
6
- import { UnauthorizedError } from "alepha/server";
7
7
  import { JWTVerifyOptions } from "jose/jwt/verify";
8
8
 
9
9
  //#region ../../src/security/schemas/userAccountInfoSchema.d.ts
10
- declare const userAccountInfoSchema: alepha1.TObject<{
11
- id: alepha1.TString;
12
- name: alepha1.TOptional<alepha1.TString>;
13
- email: alepha1.TOptional<alepha1.TString>;
14
- username: alepha1.TOptional<alepha1.TString>;
15
- picture: alepha1.TOptional<alepha1.TString>;
16
- sessionId: alepha1.TOptional<alepha1.TString>;
17
- organizations: alepha1.TOptional<alepha1.TArray<alepha1.TString>>;
18
- roles: alepha1.TOptional<alepha1.TArray<alepha1.TString>>;
10
+ declare const userAccountInfoSchema: alepha3.TObject<{
11
+ id: alepha3.TString;
12
+ name: alepha3.TOptional<alepha3.TString>;
13
+ email: alepha3.TOptional<alepha3.TString>;
14
+ username: alepha3.TOptional<alepha3.TString>;
15
+ picture: alepha3.TOptional<alepha3.TString>;
16
+ sessionId: alepha3.TOptional<alepha3.TString>;
17
+ organizations: alepha3.TOptional<alepha3.TArray<alepha3.TString>>;
18
+ roles: alepha3.TOptional<alepha3.TArray<alepha3.TString>>;
19
19
  }>;
20
20
  type UserAccount = Static<typeof userAccountInfoSchema>;
21
21
  //#endregion
22
+ //#region ../../src/security/interfaces/UserAccountToken.d.ts
23
+ /**
24
+ * Add contextual metadata to a user account info.
25
+ * E.g. UserAccountToken is a UserAccountInfo during a request.
26
+ */
27
+ interface UserAccountToken extends UserAccount {
28
+ /**
29
+ * Access token for the user.
30
+ */
31
+ token?: string;
32
+ /**
33
+ * Realm name of the user.
34
+ */
35
+ realm?: string;
36
+ /**
37
+ * Is user dedicated to his own resources for this scope ?
38
+ * Mostly, Admin is false and Customer is true.
39
+ */
40
+ ownership?: string | boolean;
41
+ }
42
+ //#endregion
22
43
  //#region ../../src/security/errors/InvalidCredentialsError.d.ts
23
44
  /**
24
45
  * Error thrown when the provided credentials are invalid.
@@ -42,90 +63,126 @@ declare class SecurityError extends Error {
42
63
  readonly status = 403;
43
64
  }
44
65
  //#endregion
45
- //#region ../../src/security/interfaces/UserAccountToken.d.ts
66
+ //#region ../../src/security/providers/ServerBasicAuthProvider.d.ts
67
+ interface BasicAuthOptions {
68
+ username: string;
69
+ password: string;
70
+ }
71
+ interface BasicAuthPrimitiveConfig extends BasicAuthOptions {
72
+ /** Name identifier for this basic auth (default: property key) */
73
+ name?: string;
74
+ /** Path patterns to match (supports wildcards like /devtools/*) */
75
+ paths?: string[];
76
+ }
77
+ declare class ServerBasicAuthProvider {
78
+ protected readonly alepha: Alepha;
79
+ protected readonly log: alepha_logger2.Logger;
80
+ protected readonly routerProvider: ServerRouterProvider;
81
+ protected readonly realm = "Secure Area";
82
+ /**
83
+ * Registered basic auth primitives with their configurations
84
+ */
85
+ readonly registeredAuths: BasicAuthPrimitiveConfig[];
86
+ /**
87
+ * Register a basic auth configuration (called by primitives)
88
+ */
89
+ registerAuth(config: BasicAuthPrimitiveConfig): void;
90
+ readonly onStart: alepha3.HookPrimitive<"start">;
91
+ /**
92
+ * Hook into server:onRequest to check basic auth
93
+ */
94
+ readonly onRequest: alepha3.HookPrimitive<"server:onRequest">;
95
+ /**
96
+ * Hook into action:onRequest to check basic auth for actions
97
+ */
98
+ readonly onActionRequest: alepha3.HookPrimitive<"action:onRequest">;
99
+ /**
100
+ * Check basic authentication
101
+ */
102
+ checkAuth(request: ServerRequest, options: BasicAuthOptions): void;
103
+ /**
104
+ * Performs a timing-safe comparison of credentials to prevent timing attacks.
105
+ * Always compares both username and password to avoid leaking which one is wrong.
106
+ */
107
+ protected timingSafeCredentialCheck(inputUsername: string, inputPassword: string, expectedUsername: string, expectedPassword: string): boolean;
108
+ /**
109
+ * Compares two buffers in constant time, handling different lengths safely.
110
+ * Returns 1 if equal, 0 if not equal.
111
+ */
112
+ protected safeCompare(input: Buffer, expected: Buffer): number;
113
+ /**
114
+ * Send WWW-Authenticate header
115
+ */
116
+ protected sendAuthRequired(request: ServerRequest): void;
117
+ }
118
+ declare const isBasicAuth: (value: unknown) => value is {
119
+ basic: BasicAuthOptions;
120
+ };
121
+ //#endregion
122
+ //#region ../../src/security/primitives/$basicAuth.d.ts
46
123
  /**
47
- * Add contextual metadata to a user account info.
48
- * E.g. UserAccountToken is a UserAccountInfo during a request.
124
+ * Declares HTTP Basic Authentication for server routes.
125
+ * This primitive provides methods to protect routes with username/password authentication.
49
126
  */
50
- interface UserAccountToken extends UserAccount {
51
- /**
52
- * Access token for the user.
53
- */
54
- token?: string;
55
- /**
56
- * Realm name of the user.
57
- */
58
- realm?: string;
127
+ declare const $basicAuth: {
128
+ (options: BasicAuthPrimitiveConfig): AbstractBasicAuthPrimitive;
129
+ [KIND]: typeof BasicAuthPrimitive;
130
+ };
131
+ interface AbstractBasicAuthPrimitive {
132
+ readonly name: string;
133
+ readonly options: BasicAuthPrimitiveConfig;
134
+ check(request: ServerRequest, options?: BasicAuthOptions): void;
135
+ }
136
+ declare class BasicAuthPrimitive extends Primitive<BasicAuthPrimitiveConfig> implements AbstractBasicAuthPrimitive {
137
+ protected readonly serverBasicAuthProvider: ServerBasicAuthProvider;
138
+ get name(): string;
139
+ protected onInit(): void;
59
140
  /**
60
- * Is user dedicated to his own resources for this scope ?
61
- * Mostly, Admin is false and Customer is true.
62
- */
63
- ownership?: string | boolean;
141
+ * Checks basic auth for the given request using this primitive's configuration.
142
+ */
143
+ check(request: ServerRequest, options?: BasicAuthOptions): void;
64
144
  }
65
145
  //#endregion
66
- //#region ../../src/security/schemas/permissionSchema.d.ts
67
- declare const permissionSchema: alepha1.TObject<{
68
- name: alepha1.TString;
69
- group: alepha1.TOptional<alepha1.TString>;
70
- description: alepha1.TOptional<alepha1.TString>;
71
- method: alepha1.TOptional<alepha1.TString>;
72
- path: alepha1.TOptional<alepha1.TString>;
73
- }>;
74
- type Permission = Static<typeof permissionSchema>;
75
- //#endregion
76
- //#region ../../src/security/schemas/roleSchema.d.ts
77
- declare const roleSchema: alepha1.TObject<{
78
- name: alepha1.TString;
79
- description: alepha1.TOptional<alepha1.TString>;
80
- default: alepha1.TOptional<alepha1.TBoolean>;
81
- permissions: alepha1.TArray<alepha1.TObject<{
82
- name: alepha1.TString;
83
- ownership: alepha1.TOptional<alepha1.TBoolean>;
84
- exclude: alepha1.TOptional<alepha1.TArray<alepha1.TString>>;
85
- }>>;
86
- }>;
87
- type Role = Static<typeof roleSchema>;
88
- //#endregion
89
146
  //#region ../../src/security/providers/JwtProvider.d.ts
90
147
  /**
91
148
  * Provides utilities for working with JSON Web Tokens (JWT).
92
149
  */
93
150
  declare class JwtProvider {
94
- protected readonly log: alepha_logger0.Logger;
151
+ protected readonly log: alepha_logger2.Logger;
95
152
  protected readonly keystore: KeyLoaderHolder[];
96
153
  protected readonly dateTimeProvider: DateTimeProvider;
97
154
  protected readonly encoder: TextEncoder;
98
155
  /**
99
- * Adds a key loader to the embedded keystore.
100
- *
101
- * @param name
102
- * @param secretKeyOrJwks
103
- */
156
+ * Adds a key loader to the embedded keystore.
157
+ *
158
+ * @param name
159
+ * @param secretKeyOrJwks
160
+ */
104
161
  setKeyLoader(name: string, secretKeyOrJwks: string | JSONWebKeySet): void;
105
162
  /**
106
- * Retrieves the payload from a JSON Web Token (JWT).
107
- *
108
- * @param token - The JWT to extract the payload from.
109
- *
110
- * @return A Promise that resolves with the payload object from the token.
111
- */
163
+ * Retrieves the payload from a JSON Web Token (JWT).
164
+ *
165
+ * @param token - The JWT to extract the payload from.
166
+ *
167
+ * @return A Promise that resolves with the payload object from the token.
168
+ */
112
169
  parse(token: string, keyName?: string, options?: JWTVerifyOptions): Promise<JwtParseResult>;
113
170
  /**
114
- * Creates a JWT token with the provided payload and secret key.
115
- *
116
- * @param payload - The payload to be encoded in the token.
117
- * It should include the `realm_access` property which contains an array of roles.
118
- * @param keyName - The name of the key to use when signing the token.
119
- *
120
- * @returns The signed JWT token.
121
- */
171
+ * Creates a JWT token with the provided payload and secret key.
172
+ *
173
+ * @param payload - The payload to be encoded in the token.
174
+ * It should include the `realm_access` property which contains an array of roles.
175
+ * @param keyName - The name of the key to use when signing the token.
176
+ *
177
+ * @returns The signed JWT token.
178
+ */
122
179
  create(payload: ExtendedJWTPayload, keyName?: string, signOptions?: JwtSignOptions): Promise<string>;
123
180
  /**
124
- * Determines if the provided key is a secret key.
125
- *
126
- * @param key
127
- * @protected
128
- */
181
+ * Determines if the provided key is a secret key.
182
+ *
183
+ * @param key
184
+ * @protected
185
+ */
129
186
  protected isSecretKey(key: string): boolean;
130
187
  }
131
188
  type KeyLoader = (protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput) => Promise<CryptoKey | KeyObject>;
@@ -152,10 +209,33 @@ interface JwtParseResult {
152
209
  result: JWTVerifyResult<ExtendedJWTPayload>;
153
210
  }
154
211
  //#endregion
212
+ //#region ../../src/security/schemas/permissionSchema.d.ts
213
+ declare const permissionSchema: alepha3.TObject<{
214
+ name: alepha3.TString;
215
+ group: alepha3.TOptional<alepha3.TString>;
216
+ description: alepha3.TOptional<alepha3.TString>;
217
+ method: alepha3.TOptional<alepha3.TString>;
218
+ path: alepha3.TOptional<alepha3.TString>;
219
+ }>;
220
+ type Permission = Static<typeof permissionSchema>;
221
+ //#endregion
222
+ //#region ../../src/security/schemas/roleSchema.d.ts
223
+ declare const roleSchema: alepha3.TObject<{
224
+ name: alepha3.TString;
225
+ description: alepha3.TOptional<alepha3.TString>;
226
+ default: alepha3.TOptional<alepha3.TBoolean>;
227
+ permissions: alepha3.TArray<alepha3.TObject<{
228
+ name: alepha3.TString;
229
+ ownership: alepha3.TOptional<alepha3.TBoolean>;
230
+ exclude: alepha3.TOptional<alepha3.TArray<alepha3.TString>>;
231
+ }>>;
232
+ }>;
233
+ type Role = Static<typeof roleSchema>;
234
+ //#endregion
155
235
  //#region ../../src/security/providers/SecurityProvider.d.ts
156
236
  declare const DEFAULT_APP_SECRET = "05759934015388327323179852515731";
157
- declare const envSchema: alepha1.TObject<{
158
- APP_SECRET: alepha1.TString;
237
+ declare const envSchema: alepha3.TObject<{
238
+ APP_SECRET: alepha3.TString;
159
239
  }>;
160
240
  declare module "alepha" {
161
241
  interface Env extends Partial<Static<typeof envSchema>> {}
@@ -164,7 +244,7 @@ declare class SecurityProvider {
164
244
  protected readonly UNKNOWN_USER_NAME = "Anonymous User";
165
245
  protected readonly PERMISSION_REGEXP: RegExp;
166
246
  protected readonly PERMISSION_REGEXP_WILDCARD: RegExp;
167
- protected readonly log: alepha_logger0.Logger;
247
+ protected readonly log: alepha_logger2.Logger;
168
248
  protected readonly jwt: JwtProvider;
169
249
  protected readonly env: {
170
250
  APP_SECRET: string;
@@ -172,122 +252,122 @@ declare class SecurityProvider {
172
252
  protected readonly alepha: Alepha;
173
253
  get secretKey(): string;
174
254
  /**
175
- * The permissions configured for the security provider.
176
- */
255
+ * The permissions configured for the security provider.
256
+ */
177
257
  protected readonly permissions: Permission[];
178
258
  /**
179
- * The realms configured for the security provider.
180
- */
259
+ * The realms configured for the security provider.
260
+ */
181
261
  protected readonly realms: Realm[];
182
- protected start: alepha1.HookPrimitive<"start">;
262
+ protected start: alepha3.HookPrimitive<"start">;
183
263
  /**
184
- * Adds a role to one or more realms.
185
- *
186
- * @param role
187
- * @param realms
188
- */
264
+ * Adds a role to one or more realms.
265
+ *
266
+ * @param role
267
+ * @param realms
268
+ */
189
269
  createRole(role: Role, ...realms: string[]): Role;
190
270
  /**
191
- * Adds a permission to the security provider.
192
- *
193
- * @param raw - The permission to add.
194
- */
271
+ * Adds a permission to the security provider.
272
+ *
273
+ * @param raw - The permission to add.
274
+ */
195
275
  createPermission(raw: Permission | string): Permission;
196
276
  createRealm(realm: Realm): void;
197
277
  /**
198
- * Updates the roles for a realm then synchronizes the user account provider if available.
199
- *
200
- * Only available when the app is started.
201
- *
202
- * @param realm - The realm to update the roles for.
203
- * @param roles - The roles to update.
204
- */
278
+ * Updates the roles for a realm then synchronizes the user account provider if available.
279
+ *
280
+ * Only available when the app is started.
281
+ *
282
+ * @param realm - The realm to update the roles for.
283
+ * @param roles - The roles to update.
284
+ */
205
285
  updateRealm(realm: string, roles: Role[]): Promise<void>;
206
286
  /**
207
- * Creates a user account from the provided payload.
208
- *
209
- * @param payload - The payload to create the user account from.
210
- * @param [realmName] - The realm containing the roles. Default is all.
211
- *
212
- * @returns The user info created from the payload.
213
- */
287
+ * Creates a user account from the provided payload.
288
+ *
289
+ * @param payload - The payload to create the user account from.
290
+ * @param [realmName] - The realm containing the roles. Default is all.
291
+ *
292
+ * @returns The user info created from the payload.
293
+ */
214
294
  createUserFromPayload(payload: JWTPayload, realmName?: string): UserAccount;
215
295
  /**
216
- * Checks if the user has the specified permission.
217
- *
218
- * Bonus: we check also if the user has "ownership" flag.
219
- *
220
- * @param permissionLike - The permission to check for.
221
- * @param roleEntries - The roles to check for the permission.
222
- */
296
+ * Checks if the user has the specified permission.
297
+ *
298
+ * Bonus: we check also if the user has "ownership" flag.
299
+ *
300
+ * @param permissionLike - The permission to check for.
301
+ * @param roleEntries - The roles to check for the permission.
302
+ */
223
303
  checkPermission(permissionLike: string | Permission, ...roleEntries: string[]): SecurityCheckResult;
224
304
  /**
225
- * Creates a user account from the provided payload.
226
- */
305
+ * Creates a user account from the provided payload.
306
+ */
227
307
  createUserFromToken(headerOrToken?: string, options?: {
228
308
  permission?: Permission | string;
229
309
  realm?: string;
230
310
  verify?: JWTVerifyOptions;
231
311
  }): Promise<UserAccountToken>;
232
312
  /**
233
- * Checks if a user has a specific role.
234
- *
235
- * @param roleName - The role to check for.
236
- * @param permission - The permission to check for.
237
- * @returns True if the user has the role, false otherwise.
238
- */
313
+ * Checks if a user has a specific role.
314
+ *
315
+ * @param roleName - The role to check for.
316
+ * @param permission - The permission to check for.
317
+ * @returns True if the user has the role, false otherwise.
318
+ */
239
319
  can(roleName: string, permission: string | Permission): boolean;
240
320
  /**
241
- * Checks if a user has ownership of a specific permission.
242
- */
321
+ * Checks if a user has ownership of a specific permission.
322
+ */
243
323
  ownership(roleName: string, permission: string | Permission): string | boolean | undefined;
244
324
  /**
245
- * Converts a permission object to a string.
246
- *
247
- * @param permission
248
- */
325
+ * Converts a permission object to a string.
326
+ *
327
+ * @param permission
328
+ */
249
329
  permissionToString(permission: Permission | string): string;
250
330
  getRealms(): Realm[];
251
331
  /**
252
- * Retrieves the user account from the provided user ID.
253
- *
254
- * @param realm
255
- */
332
+ * Retrieves the user account from the provided user ID.
333
+ *
334
+ * @param realm
335
+ */
256
336
  getRoles(realm?: string): Role[];
257
337
  /**
258
- * Returns all permissions.
259
- *
260
- * @param user - Filter permissions by user.
261
- *
262
- * @return An array containing all permissions.
263
- */
338
+ * Returns all permissions.
339
+ *
340
+ * @param user - Filter permissions by user.
341
+ *
342
+ * @return An array containing all permissions.
343
+ */
264
344
  getPermissions(user?: {
265
345
  roles?: Array<Role | string>;
266
346
  realm?: string;
267
347
  }): Permission[];
268
348
  /**
269
- * Retrieves the user ID from the provided payload object.
270
- *
271
- * @param payload - The payload object from which to extract the user ID.
272
- * @return The user ID as a string.
273
- */
349
+ * Retrieves the user ID from the provided payload object.
350
+ *
351
+ * @param payload - The payload object from which to extract the user ID.
352
+ * @return The user ID as a string.
353
+ */
274
354
  getIdFromPayload(payload: Record<string, any>): string;
275
355
  getSessionIdFromPayload(payload: Record<string, any>): string | undefined;
276
356
  /**
277
- * Retrieves the roles from the provided payload object.
278
- * @param payload - The payload object from which to extract the roles.
279
- * @return An array of role strings.
280
- */
357
+ * Retrieves the roles from the provided payload object.
358
+ * @param payload - The payload object from which to extract the roles.
359
+ * @return An array of role strings.
360
+ */
281
361
  getRolesFromPayload(payload: Record<string, any>): string[];
282
362
  getPictureFromPayload(payload: Record<string, any>): string | undefined;
283
363
  getUsernameFromPayload(payload: Record<string, any>): string | undefined;
284
364
  getEmailFromPayload(payload: Record<string, any>): string | undefined;
285
365
  /**
286
- * Returns the name from the given payload.
287
- *
288
- * @param payload - The payload object.
289
- * @returns The name extracted from the payload, or an empty string if the payload is falsy or no name is found.
290
- */
366
+ * Returns the name from the given payload.
367
+ *
368
+ * @param payload - The payload object.
369
+ * @returns The name extracted from the payload, or an empty string if the payload is falsy or no name is found.
370
+ */
291
371
  getNameFromPayload(payload: Record<string, any>): string;
292
372
  getOrganizationsFromPayload(payload: Record<string, any>): string[] | undefined;
293
373
  }
@@ -298,15 +378,15 @@ interface Realm {
298
378
  name: string;
299
379
  roles: Role[];
300
380
  /**
301
- * The secret key for the realm.
302
- *
303
- * Can be also a JWKS URL.
304
- */
381
+ * The secret key for the realm.
382
+ *
383
+ * Can be also a JWKS URL.
384
+ */
305
385
  secret?: string | JSONWebKeySet | (() => string);
306
386
  /**
307
- * Create the user account info based on the raw JWT payload.
308
- * By default, SecurityProvider has his own implementation, but this method allow to override it.
309
- */
387
+ * Create the user account info based on the raw JWT payload.
388
+ * By default, SecurityProvider has his own implementation, but this method allow to override it.
389
+ */
310
390
  profile?: (raw: Record<string, any>) => UserAccount;
311
391
  }
312
392
  interface SecurityCheckResult {
@@ -314,84 +394,53 @@ interface SecurityCheckResult {
314
394
  ownership: string | boolean | undefined;
315
395
  }
316
396
  //#endregion
317
- //#region ../../src/security/primitives/$permission.d.ts
318
- /**
319
- * Create a new permission.
320
- */
321
- declare const $permission: {
322
- (options?: PermissionPrimitiveOptions): PermissionPrimitive;
323
- [KIND]: typeof PermissionPrimitive;
324
- };
325
- interface PermissionPrimitiveOptions {
326
- /**
327
- * Name of the permission. Use Property name is not provided.
328
- */
329
- name?: string;
330
- /**
331
- * Group of the permission. Use Class name is not provided.
332
- */
333
- group?: string;
334
- /**
335
- * Describe the permission.
336
- */
337
- description?: string;
338
- }
339
- declare class PermissionPrimitive extends Primitive<PermissionPrimitiveOptions> {
340
- protected readonly securityProvider: SecurityProvider;
341
- get name(): string;
342
- get group(): string;
343
- toString(): string;
344
- protected onInit(): void;
345
- /**
346
- * Check if the user has the permission.
347
- */
348
- can(user?: UserAccount): boolean;
349
- }
350
- //#endregion
351
- //#region ../../src/security/primitives/$realm.d.ts
397
+ //#region ../../src/security/primitives/$issuer.d.ts
352
398
  /**
353
- * Create a new realm.
399
+ * Create a new issuer.
400
+ *
401
+ * An issuer is responsible for creating and verifying JWT tokens.
402
+ * It can be internal (with a secret) or external (with a JWKS).
354
403
  */
355
- declare const $realm: {
356
- (options: RealmPrimitiveOptions): RealmPrimitive;
357
- [KIND]: typeof RealmPrimitive;
404
+ declare const $issuer: {
405
+ (options: IssuerPrimitiveOptions): IssuerPrimitive;
406
+ [KIND]: typeof IssuerPrimitive;
358
407
  };
359
- type RealmPrimitiveOptions = {
408
+ type IssuerPrimitiveOptions = {
360
409
  /**
361
- * Define the realm name.
362
- * If not provided, it will use the property key.
363
- */
410
+ * Define the issuer name.
411
+ * If not provided, it will use the property key.
412
+ */
364
413
  name?: string;
365
414
  /**
366
- * Short description about the realm.
367
- */
415
+ * Short description about the issuer.
416
+ */
368
417
  description?: string;
369
418
  /**
370
- * All roles available in the realm. Role is a string (role name) or a Role object (embedded role).
371
- */
419
+ * All roles available in the issuer. Role is a string (role name) or a Role object (embedded role).
420
+ */
372
421
  roles?: Array<string | Role>;
373
422
  /**
374
- * Realm settings.
375
- */
376
- settings?: RealmSettings;
423
+ * Issuer settings.
424
+ */
425
+ settings?: IssuerSettings;
377
426
  /**
378
- * Parse the JWT payload to create a user account info.
379
- */
427
+ * Parse the JWT payload to create a user account info.
428
+ */
380
429
  profile?: (jwtPayload: Record<string, any>) => UserAccount;
381
- } & (RealmInternal | RealmExternal);
382
- interface RealmSettings {
430
+ } & (IssuerInternal | IssuerExternal);
431
+ interface IssuerSettings {
383
432
  accessToken?: {
384
433
  /**
385
- * Lifetime of the access token.
386
- * @default 15 minutes
387
- */
434
+ * Lifetime of the access token.
435
+ * @default 15 minutes
436
+ */
388
437
  expiration?: DurationLike;
389
438
  };
390
439
  refreshToken?: {
391
440
  /**
392
- * Lifetime of the refresh token.
393
- * @default 30 days
394
- */
441
+ * Lifetime of the refresh token.
442
+ * @default 30 days
443
+ */
395
444
  expiration?: DurationLike;
396
445
  };
397
446
  onCreateSession?: (user: UserAccount, config: {
@@ -407,43 +456,43 @@ interface RealmSettings {
407
456
  }>;
408
457
  onDeleteSession?: (refreshToken: string) => Promise<void>;
409
458
  }
410
- type RealmInternal = {
459
+ type IssuerInternal = {
411
460
  /**
412
- * Internal secret to sign JWT tokens and verify them.
413
- */
461
+ * Internal secret to sign JWT tokens and verify them.
462
+ */
414
463
  secret: string;
415
464
  };
416
- interface RealmExternal {
465
+ interface IssuerExternal {
417
466
  /**
418
- * URL to the JWKS (JSON Web Key Set) to verify JWT tokens from external providers.
419
- */
467
+ * URL to the JWKS (JSON Web Key Set) to verify JWT tokens from external providers.
468
+ */
420
469
  jwks: (() => string) | JSONWebKeySet;
421
470
  }
422
- declare class RealmPrimitive extends Primitive<RealmPrimitiveOptions> {
471
+ declare class IssuerPrimitive extends Primitive<IssuerPrimitiveOptions> {
423
472
  protected readonly securityProvider: SecurityProvider;
424
473
  protected readonly dateTimeProvider: DateTimeProvider;
425
474
  protected readonly jwt: JwtProvider;
426
- protected readonly log: alepha_logger0.Logger;
475
+ protected readonly log: alepha_logger2.Logger;
427
476
  get name(): string;
428
477
  get accessTokenExpiration(): Duration;
429
478
  get refreshTokenExpiration(): Duration;
430
479
  protected onInit(): void;
431
480
  /**
432
- * Get all roles in the realm.
433
- */
481
+ * Get all roles in the issuer.
482
+ */
434
483
  getRoles(): Role[];
435
484
  /**
436
- * Set all roles in the realm.
437
- */
485
+ * Set all roles in the issuer.
486
+ */
438
487
  setRoles(roles: Role[]): Promise<void>;
439
488
  /**
440
- * Get a role by name, throws an error if not found.
441
- */
489
+ * Get a role by name, throws an error if not found.
490
+ */
442
491
  getRoleByName(name: string): Role;
443
492
  parseToken(token: string): Promise<JWTPayload>;
444
493
  /**
445
- * Create a token for the subject.
446
- */
494
+ * Create a token for the subject.
495
+ */
447
496
  createToken(user: UserAccount, refreshToken?: {
448
497
  sid?: string;
449
498
  refresh_token?: string;
@@ -469,6 +518,40 @@ interface AccessTokenResponse {
469
518
  scope?: string;
470
519
  }
471
520
  //#endregion
521
+ //#region ../../src/security/primitives/$permission.d.ts
522
+ /**
523
+ * Create a new permission.
524
+ */
525
+ declare const $permission: {
526
+ (options?: PermissionPrimitiveOptions): PermissionPrimitive;
527
+ [KIND]: typeof PermissionPrimitive;
528
+ };
529
+ interface PermissionPrimitiveOptions {
530
+ /**
531
+ * Name of the permission. Use Property name is not provided.
532
+ */
533
+ name?: string;
534
+ /**
535
+ * Group of the permission. Use Class name is not provided.
536
+ */
537
+ group?: string;
538
+ /**
539
+ * Describe the permission.
540
+ */
541
+ description?: string;
542
+ }
543
+ declare class PermissionPrimitive extends Primitive<PermissionPrimitiveOptions> {
544
+ protected readonly securityProvider: SecurityProvider;
545
+ get name(): string;
546
+ get group(): string;
547
+ toString(): string;
548
+ protected onInit(): void;
549
+ /**
550
+ * Check if the user has the permission.
551
+ */
552
+ can(user?: UserAccount): boolean;
553
+ }
554
+ //#endregion
472
555
  //#region ../../src/security/primitives/$role.d.ts
473
556
  /**
474
557
  * Create a new role.
@@ -479,14 +562,14 @@ declare const $role: {
479
562
  };
480
563
  interface RolePrimitiveOptions {
481
564
  /**
482
- * Name of the role.
483
- */
565
+ * Name of the role.
566
+ */
484
567
  name?: string;
485
568
  /**
486
- * Describe the role.
487
- */
569
+ * Describe the role.
570
+ */
488
571
  description?: string;
489
- realm?: string | RealmPrimitive;
572
+ issuer?: string | IssuerPrimitive;
490
573
  permissions?: Array<string | {
491
574
  name: string;
492
575
  ownership?: boolean;
@@ -498,9 +581,9 @@ declare class RolePrimitive extends Primitive<RolePrimitiveOptions> {
498
581
  get name(): string;
499
582
  protected onInit(): void;
500
583
  /**
501
- * Get the realm of the role.
502
- */
503
- get realm(): string | RealmPrimitive | undefined;
584
+ * Get the issuer of the role.
585
+ */
586
+ get issuer(): string | IssuerPrimitive | undefined;
504
587
  can(permission: string | PermissionPrimitive): boolean;
505
588
  check(permission: string | PermissionPrimitive): SecurityCheckResult;
506
589
  }
@@ -540,21 +623,21 @@ type ServiceAccountPrimitiveOptions = {
540
623
  } & ({
541
624
  oauth2: Oauth2ServiceAccountPrimitiveOptions;
542
625
  } | {
543
- realm: RealmPrimitive;
626
+ issuer: IssuerPrimitive;
544
627
  user: UserAccount;
545
628
  });
546
629
  interface Oauth2ServiceAccountPrimitiveOptions {
547
630
  /**
548
- * Get Token URL.
549
- */
631
+ * Get Token URL.
632
+ */
550
633
  url: string;
551
634
  /**
552
- * Client ID.
553
- */
635
+ * Client ID.
636
+ */
554
637
  clientId: string;
555
638
  /**
556
- * Client Secret.
557
- */
639
+ * Client Secret.
640
+ */
558
641
  clientSecret: string;
559
642
  }
560
643
  interface ServiceAccountPrimitive {
@@ -571,6 +654,38 @@ declare class CryptoProvider {
571
654
  randomUUID(): string;
572
655
  }
573
656
  //#endregion
657
+ //#region ../../src/security/providers/ServerSecurityProvider.d.ts
658
+ declare class ServerSecurityProvider {
659
+ protected readonly log: alepha_logger2.Logger;
660
+ protected readonly securityProvider: SecurityProvider;
661
+ protected readonly jwtProvider: JwtProvider;
662
+ protected readonly alepha: Alepha;
663
+ protected readonly onConfigure: alepha3.HookPrimitive<"configure">;
664
+ protected readonly onActionRequest: alepha3.HookPrimitive<"action:onRequest">;
665
+ protected readonly onRequest: alepha3.HookPrimitive<"server:onRequest">;
666
+ protected check(user: UserAccountToken, secure: ServerRouteSecure): void;
667
+ /**
668
+ * Get the user account token for a local action call.
669
+ * There are three possible sources for the user:
670
+ * - `options.user`: the user passed in the options
671
+ * - `"system"`: the system user from the state (you MUST set state `server.security.system.user`)
672
+ * - `"context"`: the user from the request context (you MUST be in an HTTP request context)
673
+ *
674
+ * Priority order: `options.user` > `"system"` > `"context"`.
675
+ *
676
+ * In testing environment, if no user is provided, a test user is created based on the SecurityProvider's roles.
677
+ */
678
+ protected createUserFromLocalFunctionContext(options: {
679
+ user?: UserAccountToken | "system" | "context";
680
+ }, permission?: Permission): UserAccountToken;
681
+ protected createTestUser(): UserAccountToken;
682
+ protected readonly onClientRequest: alepha3.HookPrimitive<"client:onRequest">;
683
+ }
684
+ type ServerRouteSecure = {
685
+ realm?: string;
686
+ basic?: BasicAuthOptions;
687
+ };
688
+ //#endregion
574
689
  //#region ../../src/security/index.d.ts
575
690
  declare module "alepha" {
576
691
  interface Hooks {
@@ -579,20 +694,68 @@ declare module "alepha" {
579
694
  user: UserAccount;
580
695
  };
581
696
  }
697
+ interface State {
698
+ /**
699
+ * Real (or fake) user account, used for internal actions.
700
+ *
701
+ * If you define this, you assume that all actions are executed by this user by default.
702
+ * > To force a different user, you need to pass it explicitly in the options.
703
+ */
704
+ "alepha.server.security.system.user"?: UserAccountToken;
705
+ /**
706
+ * The authenticated user account attached to the server request state.
707
+ *
708
+ * @internal
709
+ */
710
+ "alepha.server.request.user"?: UserAccount;
711
+ }
712
+ }
713
+ declare module "alepha/server" {
714
+ interface ServerRequest<TConfig> {
715
+ user?: UserAccountToken;
716
+ }
717
+ interface ServerActionRequest<TConfig> {
718
+ user: UserAccountToken;
719
+ }
720
+ interface ServerRoute {
721
+ /**
722
+ * If true, the route will be protected by the security provider.
723
+ * All actions are secure by default, but you can disable it for specific actions.
724
+ */
725
+ secure?: boolean | ServerRouteSecure;
726
+ }
727
+ interface ClientRequestOptions extends FetchOptions {
728
+ /**
729
+ * Forward user from the previous request.
730
+ * If "system", use system user. @see {ServerSecurityProvider.localSystemUser}
731
+ * If "context", use the user from the current context (e.g. request).
732
+ *
733
+ * @default "system" if provided, else "context" if available.
734
+ */
735
+ user?: UserAccountToken | "system" | "context";
736
+ }
582
737
  }
583
738
  /**
584
739
  * Provides comprehensive authentication and authorization capabilities with JWT tokens, role-based access control, and user management.
585
740
  *
586
- * The security module enables building secure applications using primitives like `$realm`, `$role`, and `$permission`
741
+ * The security module enables building secure applications using primitives like `$issuer`, `$role`, and `$permission`
587
742
  * on class properties. It offers JWT-based authentication, fine-grained permissions, service accounts, and seamless
588
743
  * integration with various authentication providers and user management systems.
589
744
  *
590
- * @see {@link $realm}
745
+ * When used with `AlephaServer`, this module automatically registers `ServerSecurityProvider` and `ServerBasicAuthProvider`
746
+ * to protect HTTP routes and actions with JWT and Basic Auth.
747
+ *
748
+ * @see {@link $issuer}
591
749
  * @see {@link $role}
592
750
  * @see {@link $permission}
751
+ * @see {@link $basicAuth}
593
752
  * @module alepha.security
594
753
  */
595
- declare const AlephaSecurity: alepha1.Service<alepha1.Module>;
754
+ declare const AlephaSecurity: alepha3.Service<alepha3.Module>;
755
+ /**
756
+ * @deprecated Use `AlephaSecurity` instead. Server security providers are automatically registered when `AlephaServer` is available.
757
+ */
758
+ declare const AlephaServerSecurity: alepha3.Service<alepha3.Module>;
596
759
  //#endregion
597
- export { $permission, $realm, $role, $serviceAccount, AccessTokenResponse, AlephaSecurity, CreateTokenOptions, CryptoProvider, DEFAULT_APP_SECRET, ExtendedJWTPayload, InvalidCredentialsError, InvalidPermissionError, JwtParseResult, JwtProvider, JwtSignOptions, KeyLoader, KeyLoaderHolder, Oauth2ServiceAccountPrimitiveOptions, Permission, PermissionPrimitive, PermissionPrimitiveOptions, Realm, RealmExternal, RealmInternal, RealmPrimitive, RealmPrimitiveOptions, RealmSettings, Role, RolePrimitive, RolePrimitiveOptions, SecurityCheckResult, SecurityError, SecurityProvider, ServiceAccountPrimitive, ServiceAccountPrimitiveOptions, ServiceAccountStore, UserAccount, UserAccountToken, permissionSchema, roleSchema, userAccountInfoSchema };
760
+ export { $basicAuth, $issuer, $permission, $role, $serviceAccount, AbstractBasicAuthPrimitive, AccessTokenResponse, AlephaSecurity, AlephaServerSecurity, BasicAuthOptions, BasicAuthPrimitive, BasicAuthPrimitiveConfig, CreateTokenOptions, CryptoProvider, DEFAULT_APP_SECRET, ExtendedJWTPayload, InvalidCredentialsError, InvalidPermissionError, IssuerExternal, IssuerInternal, IssuerPrimitive, IssuerPrimitiveOptions, IssuerSettings, JwtParseResult, JwtProvider, JwtSignOptions, KeyLoader, KeyLoaderHolder, Oauth2ServiceAccountPrimitiveOptions, Permission, PermissionPrimitive, PermissionPrimitiveOptions, Realm, Role, RolePrimitive, RolePrimitiveOptions, SecurityCheckResult, SecurityError, SecurityProvider, ServerBasicAuthProvider, ServerRouteSecure, ServerSecurityProvider, ServiceAccountPrimitive, ServiceAccountPrimitiveOptions, ServiceAccountStore, UserAccount, UserAccountToken, isBasicAuth, permissionSchema, roleSchema, userAccountInfoSchema };
598
761
  //# sourceMappingURL=index.d.ts.map