alepha 0.14.4 → 0.15.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 (322) hide show
  1. package/README.md +44 -102
  2. package/dist/api/audits/index.d.ts +331 -443
  3. package/dist/api/audits/index.d.ts.map +1 -1
  4. package/dist/api/audits/index.js +2 -2
  5. package/dist/api/audits/index.js.map +1 -1
  6. package/dist/api/files/index.d.ts +0 -113
  7. package/dist/api/files/index.d.ts.map +1 -1
  8. package/dist/api/files/index.js +2 -3
  9. package/dist/api/files/index.js.map +1 -1
  10. package/dist/api/jobs/index.d.ts +151 -262
  11. package/dist/api/jobs/index.d.ts.map +1 -1
  12. package/dist/api/notifications/index.browser.js +4 -4
  13. package/dist/api/notifications/index.browser.js.map +1 -1
  14. package/dist/api/notifications/index.d.ts +164 -276
  15. package/dist/api/notifications/index.d.ts.map +1 -1
  16. package/dist/api/notifications/index.js +4 -4
  17. package/dist/api/notifications/index.js.map +1 -1
  18. package/dist/api/parameters/index.d.ts +265 -377
  19. package/dist/api/parameters/index.d.ts.map +1 -1
  20. package/dist/api/users/index.browser.js +1 -2
  21. package/dist/api/users/index.browser.js.map +1 -1
  22. package/dist/api/users/index.d.ts +195 -301
  23. package/dist/api/users/index.d.ts.map +1 -1
  24. package/dist/api/users/index.js +203 -184
  25. package/dist/api/users/index.js.map +1 -1
  26. package/dist/api/verifications/index.d.ts.map +1 -1
  27. package/dist/batch/index.d.ts.map +1 -1
  28. package/dist/batch/index.js +1 -2
  29. package/dist/batch/index.js.map +1 -1
  30. package/dist/bucket/index.d.ts.map +1 -1
  31. package/dist/cache/core/index.d.ts.map +1 -1
  32. package/dist/cache/redis/index.d.ts.map +1 -1
  33. package/dist/cache/redis/index.js +2 -2
  34. package/dist/cache/redis/index.js.map +1 -1
  35. package/dist/cli/index.d.ts +5900 -165
  36. package/dist/cli/index.d.ts.map +1 -1
  37. package/dist/cli/index.js +1481 -639
  38. package/dist/cli/index.js.map +1 -1
  39. package/dist/command/index.d.ts +8 -4
  40. package/dist/command/index.d.ts.map +1 -1
  41. package/dist/command/index.js +29 -25
  42. package/dist/command/index.js.map +1 -1
  43. package/dist/core/index.browser.js +563 -54
  44. package/dist/core/index.browser.js.map +1 -1
  45. package/dist/core/index.d.ts +175 -8
  46. package/dist/core/index.d.ts.map +1 -1
  47. package/dist/core/index.js +564 -54
  48. package/dist/core/index.js.map +1 -1
  49. package/dist/core/index.native.js +563 -54
  50. package/dist/core/index.native.js.map +1 -1
  51. package/dist/datetime/index.d.ts.map +1 -1
  52. package/dist/datetime/index.js +4 -4
  53. package/dist/datetime/index.js.map +1 -1
  54. package/dist/email/index.d.ts +89 -42
  55. package/dist/email/index.d.ts.map +1 -1
  56. package/dist/email/index.js +129 -33
  57. package/dist/email/index.js.map +1 -1
  58. package/dist/fake/index.d.ts +7969 -2
  59. package/dist/fake/index.d.ts.map +1 -1
  60. package/dist/fake/index.js +22 -22
  61. package/dist/fake/index.js.map +1 -1
  62. package/dist/file/index.d.ts +134 -1
  63. package/dist/file/index.d.ts.map +1 -1
  64. package/dist/file/index.js +253 -1
  65. package/dist/file/index.js.map +1 -1
  66. package/dist/lock/core/index.d.ts.map +1 -1
  67. package/dist/lock/redis/index.d.ts.map +1 -1
  68. package/dist/logger/index.d.ts +1 -2
  69. package/dist/logger/index.d.ts.map +1 -1
  70. package/dist/logger/index.js +1 -5
  71. package/dist/logger/index.js.map +1 -1
  72. package/dist/mcp/index.d.ts +19 -1
  73. package/dist/mcp/index.d.ts.map +1 -1
  74. package/dist/mcp/index.js +28 -4
  75. package/dist/mcp/index.js.map +1 -1
  76. package/dist/orm/chunk-DH6iiROE.js +38 -0
  77. package/dist/orm/index.browser.js +9 -9
  78. package/dist/orm/index.browser.js.map +1 -1
  79. package/dist/orm/index.bun.js +2821 -0
  80. package/dist/orm/index.bun.js.map +1 -0
  81. package/dist/orm/index.d.ts +318 -169
  82. package/dist/orm/index.d.ts.map +1 -1
  83. package/dist/orm/index.js +2086 -1776
  84. package/dist/orm/index.js.map +1 -1
  85. package/dist/queue/core/index.d.ts +4 -4
  86. package/dist/queue/core/index.d.ts.map +1 -1
  87. package/dist/queue/redis/index.d.ts.map +1 -1
  88. package/dist/redis/index.bun.js +285 -0
  89. package/dist/redis/index.bun.js.map +1 -0
  90. package/dist/redis/index.d.ts +13 -31
  91. package/dist/redis/index.d.ts.map +1 -1
  92. package/dist/redis/index.js +18 -38
  93. package/dist/redis/index.js.map +1 -1
  94. package/dist/retry/index.d.ts.map +1 -1
  95. package/dist/router/index.d.ts.map +1 -1
  96. package/dist/scheduler/index.d.ts +83 -1
  97. package/dist/scheduler/index.d.ts.map +1 -1
  98. package/dist/scheduler/index.js +393 -1
  99. package/dist/scheduler/index.js.map +1 -1
  100. package/dist/security/index.browser.js +5 -1
  101. package/dist/security/index.browser.js.map +1 -1
  102. package/dist/security/index.d.ts +598 -112
  103. package/dist/security/index.d.ts.map +1 -1
  104. package/dist/security/index.js +1808 -97
  105. package/dist/security/index.js.map +1 -1
  106. package/dist/server/auth/index.d.ts +1200 -175
  107. package/dist/server/auth/index.d.ts.map +1 -1
  108. package/dist/server/auth/index.js +1268 -37
  109. package/dist/server/auth/index.js.map +1 -1
  110. package/dist/server/cache/index.d.ts +6 -3
  111. package/dist/server/cache/index.d.ts.map +1 -1
  112. package/dist/server/cache/index.js +1 -1
  113. package/dist/server/cache/index.js.map +1 -1
  114. package/dist/server/compress/index.d.ts.map +1 -1
  115. package/dist/server/cookies/index.d.ts.map +1 -1
  116. package/dist/server/cookies/index.js +3 -3
  117. package/dist/server/cookies/index.js.map +1 -1
  118. package/dist/server/core/index.d.ts +115 -13
  119. package/dist/server/core/index.d.ts.map +1 -1
  120. package/dist/server/core/index.js +321 -139
  121. package/dist/server/core/index.js.map +1 -1
  122. package/dist/server/cors/index.d.ts +0 -1
  123. package/dist/server/cors/index.d.ts.map +1 -1
  124. package/dist/server/health/index.d.ts +0 -1
  125. package/dist/server/health/index.d.ts.map +1 -1
  126. package/dist/server/helmet/index.d.ts.map +1 -1
  127. package/dist/server/links/index.browser.js +9 -1
  128. package/dist/server/links/index.browser.js.map +1 -1
  129. package/dist/server/links/index.d.ts +1 -2
  130. package/dist/server/links/index.d.ts.map +1 -1
  131. package/dist/server/links/index.js +14 -7
  132. package/dist/server/links/index.js.map +1 -1
  133. package/dist/server/metrics/index.d.ts +514 -1
  134. package/dist/server/metrics/index.d.ts.map +1 -1
  135. package/dist/server/metrics/index.js +4462 -4
  136. package/dist/server/metrics/index.js.map +1 -1
  137. package/dist/server/multipart/index.d.ts.map +1 -1
  138. package/dist/server/proxy/index.d.ts +0 -1
  139. package/dist/server/proxy/index.d.ts.map +1 -1
  140. package/dist/server/rate-limit/index.d.ts.map +1 -1
  141. package/dist/server/static/index.d.ts.map +1 -1
  142. package/dist/server/swagger/index.d.ts +1 -2
  143. package/dist/server/swagger/index.d.ts.map +1 -1
  144. package/dist/server/swagger/index.js +1 -2
  145. package/dist/server/swagger/index.js.map +1 -1
  146. package/dist/sms/index.d.ts +3 -1
  147. package/dist/sms/index.d.ts.map +1 -1
  148. package/dist/sms/index.js +10 -10
  149. package/dist/sms/index.js.map +1 -1
  150. package/dist/thread/index.d.ts +0 -1
  151. package/dist/thread/index.d.ts.map +1 -1
  152. package/dist/thread/index.js +2 -2
  153. package/dist/thread/index.js.map +1 -1
  154. package/dist/topic/core/index.d.ts.map +1 -1
  155. package/dist/topic/redis/index.d.ts.map +1 -1
  156. package/dist/vite/index.d.ts +6315 -149
  157. package/dist/vite/index.d.ts.map +1 -1
  158. package/dist/vite/index.js +140 -469
  159. package/dist/vite/index.js.map +1 -1
  160. package/dist/websocket/index.browser.js +9 -9
  161. package/dist/websocket/index.browser.js.map +1 -1
  162. package/dist/websocket/index.d.ts +28 -28
  163. package/dist/websocket/index.d.ts.map +1 -1
  164. package/dist/websocket/index.js +9 -9
  165. package/dist/websocket/index.js.map +1 -1
  166. package/package.json +13 -18
  167. package/src/api/files/controllers/AdminFileStatsController.ts +0 -1
  168. package/src/api/users/atoms/realmAuthSettingsAtom.ts +5 -0
  169. package/src/api/users/controllers/{UserRealmController.ts → RealmController.ts} +11 -11
  170. package/src/api/users/entities/users.ts +1 -1
  171. package/src/api/users/index.ts +8 -8
  172. package/src/api/users/primitives/{$userRealm.ts → $realm.ts} +17 -19
  173. package/src/api/users/providers/{UserRealmProvider.ts → RealmProvider.ts} +26 -30
  174. package/src/api/users/schemas/{userRealmConfigSchema.ts → realmConfigSchema.ts} +2 -2
  175. package/src/api/users/services/CredentialService.ts +7 -7
  176. package/src/api/users/services/IdentityService.ts +4 -4
  177. package/src/api/users/services/RegistrationService.spec.ts +25 -27
  178. package/src/api/users/services/RegistrationService.ts +38 -27
  179. package/src/api/users/services/SessionCrudService.ts +3 -3
  180. package/src/api/users/services/SessionService.spec.ts +3 -3
  181. package/src/api/users/services/SessionService.ts +27 -18
  182. package/src/api/users/services/UserService.ts +7 -7
  183. package/src/batch/providers/BatchProvider.ts +1 -2
  184. package/src/cli/apps/AlephaCli.ts +2 -2
  185. package/src/cli/apps/AlephaPackageBuilderCli.ts +47 -20
  186. package/src/cli/assets/apiHelloControllerTs.ts +19 -0
  187. package/src/cli/assets/apiIndexTs.ts +16 -0
  188. package/src/cli/assets/biomeJson.ts +2 -1
  189. package/src/cli/assets/claudeMd.ts +308 -0
  190. package/src/cli/assets/dummySpecTs.ts +2 -1
  191. package/src/cli/assets/editorconfig.ts +2 -1
  192. package/src/cli/assets/mainBrowserTs.ts +4 -3
  193. package/src/cli/assets/mainCss.ts +24 -0
  194. package/src/cli/assets/mainServerTs.ts +24 -0
  195. package/src/cli/assets/tsconfigJson.ts +2 -1
  196. package/src/cli/assets/webAppRouterTs.ts +16 -0
  197. package/src/cli/assets/webHelloComponentTsx.ts +20 -0
  198. package/src/cli/assets/webIndexTs.ts +16 -0
  199. package/src/cli/atoms/appEntryOptions.ts +13 -0
  200. package/src/cli/atoms/buildOptions.ts +1 -1
  201. package/src/cli/atoms/changelogOptions.ts +1 -1
  202. package/src/cli/commands/build.ts +97 -61
  203. package/src/cli/commands/db.ts +21 -18
  204. package/src/cli/commands/deploy.ts +17 -5
  205. package/src/cli/commands/dev.ts +26 -47
  206. package/src/cli/commands/gen/env.ts +1 -1
  207. package/src/cli/commands/init.ts +79 -25
  208. package/src/cli/commands/lint.ts +9 -3
  209. package/src/cli/commands/test.ts +8 -2
  210. package/src/cli/commands/typecheck.ts +5 -1
  211. package/src/cli/commands/verify.ts +4 -2
  212. package/src/cli/defineConfig.ts +9 -0
  213. package/src/cli/index.ts +2 -1
  214. package/src/cli/providers/AppEntryProvider.ts +131 -0
  215. package/src/cli/providers/ViteBuildProvider.ts +82 -0
  216. package/src/cli/providers/ViteDevServerProvider.ts +350 -0
  217. package/src/cli/providers/ViteTemplateProvider.ts +27 -0
  218. package/src/cli/services/AlephaCliUtils.ts +72 -602
  219. package/src/cli/services/PackageManagerUtils.ts +308 -0
  220. package/src/cli/services/ProjectScaffolder.ts +329 -0
  221. package/src/command/helpers/Runner.ts +15 -3
  222. package/src/core/Alepha.ts +2 -8
  223. package/src/core/__tests__/Alepha-graph.spec.ts +4 -0
  224. package/src/core/index.shared.ts +1 -0
  225. package/src/core/index.ts +2 -0
  226. package/src/core/primitives/$hook.ts +6 -2
  227. package/src/core/primitives/$module.spec.ts +4 -0
  228. package/src/core/primitives/$module.ts +12 -0
  229. package/src/core/providers/AlsProvider.ts +1 -1
  230. package/src/core/providers/CodecManager.spec.ts +12 -6
  231. package/src/core/providers/CodecManager.ts +26 -6
  232. package/src/core/providers/EventManager.ts +169 -13
  233. package/src/core/providers/KeylessJsonSchemaCodec.spec.ts +878 -0
  234. package/src/core/providers/KeylessJsonSchemaCodec.ts +789 -0
  235. package/src/core/providers/SchemaValidator.spec.ts +236 -0
  236. package/src/core/providers/StateManager.spec.ts +27 -16
  237. package/src/email/providers/LocalEmailProvider.spec.ts +111 -87
  238. package/src/email/providers/LocalEmailProvider.ts +52 -15
  239. package/src/email/providers/NodemailerEmailProvider.ts +167 -56
  240. package/src/file/errors/FileError.ts +7 -0
  241. package/src/file/index.ts +9 -1
  242. package/src/file/providers/MemoryFileSystemProvider.ts +393 -0
  243. package/src/logger/providers/PrettyFormatterProvider.ts +0 -9
  244. package/src/mcp/errors/McpError.ts +30 -0
  245. package/src/mcp/index.ts +3 -0
  246. package/src/mcp/transports/SseMcpTransport.ts +16 -6
  247. package/src/orm/index.browser.ts +1 -19
  248. package/src/orm/index.bun.ts +77 -0
  249. package/src/orm/index.shared-server.ts +22 -0
  250. package/src/orm/index.shared.ts +15 -0
  251. package/src/orm/index.ts +19 -39
  252. package/src/orm/providers/DrizzleKitProvider.ts +3 -5
  253. package/src/orm/providers/drivers/BunPostgresProvider.ts +3 -5
  254. package/src/orm/providers/drivers/BunSqliteProvider.ts +1 -1
  255. package/src/orm/providers/drivers/CloudflareD1Provider.ts +4 -0
  256. package/src/orm/providers/drivers/DatabaseProvider.ts +4 -0
  257. package/src/orm/providers/drivers/PglitePostgresProvider.ts +4 -0
  258. package/src/orm/services/Repository.ts +19 -0
  259. package/src/redis/index.bun.ts +35 -0
  260. package/src/redis/providers/BunRedisProvider.ts +12 -43
  261. package/src/redis/providers/BunRedisSubscriberProvider.ts +2 -3
  262. package/src/redis/providers/NodeRedisProvider.ts +16 -34
  263. package/src/{server/security → security}/__tests__/BasicAuth.spec.ts +11 -11
  264. package/src/{server/security → security}/__tests__/ServerSecurityProvider-realm.spec.ts +21 -16
  265. package/src/{server/security/providers → security/__tests__}/ServerSecurityProvider.spec.ts +5 -5
  266. package/src/security/index.browser.ts +5 -0
  267. package/src/security/index.ts +90 -7
  268. package/src/security/primitives/{$realm.spec.ts → $issuer.spec.ts} +11 -11
  269. package/src/security/primitives/{$realm.ts → $issuer.ts} +20 -17
  270. package/src/security/primitives/$role.ts +5 -5
  271. package/src/security/primitives/$serviceAccount.spec.ts +5 -5
  272. package/src/security/primitives/$serviceAccount.ts +3 -3
  273. package/src/{server/security → security}/providers/ServerSecurityProvider.ts +5 -7
  274. package/src/server/auth/primitives/$auth.ts +10 -10
  275. package/src/server/auth/primitives/$authCredentials.ts +3 -3
  276. package/src/server/auth/primitives/$authGithub.ts +3 -3
  277. package/src/server/auth/primitives/$authGoogle.ts +3 -3
  278. package/src/server/auth/providers/ServerAuthProvider.ts +13 -13
  279. package/src/server/cache/providers/ServerCacheProvider.ts +1 -1
  280. package/src/server/cookies/providers/ServerCookiesProvider.ts +3 -3
  281. package/src/server/core/index.ts +1 -1
  282. package/src/server/core/providers/BunHttpServerProvider.ts +1 -1
  283. package/src/server/core/providers/NodeHttpServerProvider.spec.ts +125 -0
  284. package/src/server/core/providers/NodeHttpServerProvider.ts +92 -24
  285. package/src/server/core/providers/ServerBodyParserProvider.ts +19 -23
  286. package/src/server/core/providers/ServerLoggerProvider.ts +23 -19
  287. package/src/server/core/providers/ServerProvider.ts +144 -24
  288. package/src/server/core/providers/ServerRouterProvider.ts +259 -115
  289. package/src/server/core/providers/ServerTimingProvider.ts +2 -2
  290. package/src/server/links/atoms/apiLinksAtom.ts +7 -0
  291. package/src/server/links/index.browser.ts +2 -0
  292. package/src/server/links/index.ts +3 -1
  293. package/src/server/links/providers/LinkProvider.ts +1 -1
  294. package/src/server/swagger/index.ts +1 -1
  295. package/src/sms/providers/LocalSmsProvider.spec.ts +153 -111
  296. package/src/sms/providers/LocalSmsProvider.ts +8 -7
  297. package/src/vite/index.ts +3 -2
  298. package/src/vite/tasks/buildClient.ts +0 -1
  299. package/src/vite/tasks/buildServer.ts +80 -22
  300. package/src/vite/tasks/copyAssets.ts +5 -4
  301. package/src/vite/tasks/generateCloudflare.ts +7 -0
  302. package/src/vite/tasks/generateSitemap.ts +64 -23
  303. package/src/vite/tasks/index.ts +0 -2
  304. package/src/vite/tasks/prerenderPages.ts +49 -24
  305. package/dist/server/security/index.browser.js +0 -13
  306. package/dist/server/security/index.browser.js.map +0 -1
  307. package/dist/server/security/index.d.ts +0 -173
  308. package/dist/server/security/index.d.ts.map +0 -1
  309. package/dist/server/security/index.js +0 -311
  310. package/dist/server/security/index.js.map +0 -1
  311. package/src/cli/assets/appRouterTs.ts +0 -9
  312. package/src/cli/assets/indexHtml.ts +0 -15
  313. package/src/cli/assets/mainTs.ts +0 -13
  314. package/src/cli/commands/format.ts +0 -17
  315. package/src/server/security/index.browser.ts +0 -10
  316. package/src/server/security/index.ts +0 -94
  317. package/src/vite/helpers/boot.ts +0 -106
  318. package/src/vite/plugins/viteAlephaDev.ts +0 -177
  319. package/src/vite/tasks/devServer.ts +0 -69
  320. package/src/vite/tasks/runAlepha.ts +0 -270
  321. /package/src/{server/security → security}/primitives/$basicAuth.ts +0 -0
  322. /package/src/{server/security → security}/providers/ServerBasicAuthProvider.ts +0 -0
@@ -1,24 +1,43 @@
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
- import { CryptoKey, FlattenedJWSInput, JSONWebKeySet, JWSHeaderParameters, JWTHeaderParameters, JWTPayload, JWTVerifyResult, KeyObject } from "jose";
6
- import { UnauthorizedError } from "alepha/server";
7
- import { JWTVerifyOptions } from "jose/jwt/verify";
8
6
 
9
7
  //#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>>;
8
+ declare const userAccountInfoSchema: alepha3.TObject<{
9
+ id: alepha3.TString;
10
+ name: alepha3.TOptional<alepha3.TString>;
11
+ email: alepha3.TOptional<alepha3.TString>;
12
+ username: alepha3.TOptional<alepha3.TString>;
13
+ picture: alepha3.TOptional<alepha3.TString>;
14
+ sessionId: alepha3.TOptional<alepha3.TString>;
15
+ organizations: alepha3.TOptional<alepha3.TArray<alepha3.TString>>;
16
+ roles: alepha3.TOptional<alepha3.TArray<alepha3.TString>>;
19
17
  }>;
20
18
  type UserAccount = Static<typeof userAccountInfoSchema>;
21
19
  //#endregion
20
+ //#region ../../src/security/interfaces/UserAccountToken.d.ts
21
+ /**
22
+ * Add contextual metadata to a user account info.
23
+ * E.g. UserAccountToken is a UserAccountInfo during a request.
24
+ */
25
+ interface UserAccountToken extends UserAccount {
26
+ /**
27
+ * Access token for the user.
28
+ */
29
+ token?: string;
30
+ /**
31
+ * Realm name of the user.
32
+ */
33
+ realm?: string;
34
+ /**
35
+ * Is user dedicated to his own resources for this scope ?
36
+ * Mostly, Admin is false and Customer is true.
37
+ */
38
+ ownership?: string | boolean;
39
+ }
40
+ //#endregion
22
41
  //#region ../../src/security/errors/InvalidCredentialsError.d.ts
23
42
  /**
24
43
  * Error thrown when the provided credentials are invalid.
@@ -42,56 +61,417 @@ declare class SecurityError extends Error {
42
61
  readonly status = 403;
43
62
  }
44
63
  //#endregion
45
- //#region ../../src/security/interfaces/UserAccountToken.d.ts
64
+ //#region ../../src/security/providers/ServerBasicAuthProvider.d.ts
65
+ interface BasicAuthOptions {
66
+ username: string;
67
+ password: string;
68
+ }
69
+ interface BasicAuthPrimitiveConfig extends BasicAuthOptions {
70
+ /** Name identifier for this basic auth (default: property key) */
71
+ name?: string;
72
+ /** Path patterns to match (supports wildcards like /devtools/*) */
73
+ paths?: string[];
74
+ }
75
+ declare class ServerBasicAuthProvider {
76
+ protected readonly alepha: Alepha;
77
+ protected readonly log: alepha_logger2.Logger;
78
+ protected readonly routerProvider: ServerRouterProvider;
79
+ protected readonly realm = "Secure Area";
80
+ /**
81
+ * Registered basic auth primitives with their configurations
82
+ */
83
+ readonly registeredAuths: BasicAuthPrimitiveConfig[];
84
+ /**
85
+ * Register a basic auth configuration (called by primitives)
86
+ */
87
+ registerAuth(config: BasicAuthPrimitiveConfig): void;
88
+ readonly onStart: alepha3.HookPrimitive<"start">;
89
+ /**
90
+ * Hook into server:onRequest to check basic auth
91
+ */
92
+ readonly onRequest: alepha3.HookPrimitive<"server:onRequest">;
93
+ /**
94
+ * Hook into action:onRequest to check basic auth for actions
95
+ */
96
+ readonly onActionRequest: alepha3.HookPrimitive<"action:onRequest">;
97
+ /**
98
+ * Check basic authentication
99
+ */
100
+ checkAuth(request: ServerRequest, options: BasicAuthOptions): void;
101
+ /**
102
+ * Performs a timing-safe comparison of credentials to prevent timing attacks.
103
+ * Always compares both username and password to avoid leaking which one is wrong.
104
+ */
105
+ protected timingSafeCredentialCheck(inputUsername: string, inputPassword: string, expectedUsername: string, expectedPassword: string): boolean;
106
+ /**
107
+ * Compares two buffers in constant time, handling different lengths safely.
108
+ * Returns 1 if equal, 0 if not equal.
109
+ */
110
+ protected safeCompare(input: Buffer, expected: Buffer): number;
111
+ /**
112
+ * Send WWW-Authenticate header
113
+ */
114
+ protected sendAuthRequired(request: ServerRequest): void;
115
+ }
116
+ declare const isBasicAuth: (value: unknown) => value is {
117
+ basic: BasicAuthOptions;
118
+ };
119
+ //#endregion
120
+ //#region ../../src/security/primitives/$basicAuth.d.ts
46
121
  /**
47
- * Add contextual metadata to a user account info.
48
- * E.g. UserAccountToken is a UserAccountInfo during a request.
122
+ * Declares HTTP Basic Authentication for server routes.
123
+ * This primitive provides methods to protect routes with username/password authentication.
49
124
  */
50
- interface UserAccountToken extends UserAccount {
125
+ declare const $basicAuth: {
126
+ (options: BasicAuthPrimitiveConfig): AbstractBasicAuthPrimitive;
127
+ [KIND]: typeof BasicAuthPrimitive;
128
+ };
129
+ interface AbstractBasicAuthPrimitive {
130
+ readonly name: string;
131
+ readonly options: BasicAuthPrimitiveConfig;
132
+ check(request: ServerRequest, options?: BasicAuthOptions): void;
133
+ }
134
+ declare class BasicAuthPrimitive extends Primitive<BasicAuthPrimitiveConfig> implements AbstractBasicAuthPrimitive {
135
+ protected readonly serverBasicAuthProvider: ServerBasicAuthProvider;
136
+ get name(): string;
137
+ protected onInit(): void;
51
138
  /**
52
- * Access token for the user.
139
+ * Checks basic auth for the given request using this primitive's configuration.
53
140
  */
54
- token?: string;
141
+ check(request: ServerRequest, options?: BasicAuthOptions): void;
142
+ }
143
+ //#endregion
144
+ //#region ../../../../node_modules/jose/dist/types/types.d.ts
145
+ /** Generic JSON Web Key Parameters. */
146
+ interface JWKParameters {
147
+ /** JWK "kty" (Key Type) Parameter */
148
+ kty?: string;
55
149
  /**
56
- * Realm name of the user.
150
+ * JWK "alg" (Algorithm) Parameter
151
+ *
152
+ * @see {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}
57
153
  */
58
- realm?: string;
154
+ alg?: string;
155
+ /** JWK "key_ops" (Key Operations) Parameter */
156
+ key_ops?: string[];
157
+ /** JWK "ext" (Extractable) Parameter */
158
+ ext?: boolean;
159
+ /** JWK "use" (Public Key Use) Parameter */
160
+ use?: string;
161
+ /** JWK "x5c" (X.509 Certificate Chain) Parameter */
162
+ x5c?: string[];
163
+ /** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter */
164
+ x5t?: string;
165
+ /** JWK "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter */
166
+ 'x5t#S256'?: string;
167
+ /** JWK "x5u" (X.509 URL) Parameter */
168
+ x5u?: string;
169
+ /** JWK "kid" (Key ID) Parameter */
170
+ kid?: string;
171
+ }
172
+ /**
173
+ * JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC", "OKP", "AKP", and
174
+ * "oct" key types are supported.
175
+ *
176
+ * @see {@link JWK_AKP_Public}
177
+ * @see {@link JWK_AKP_Private}
178
+ * @see {@link JWK_OKP_Public}
179
+ * @see {@link JWK_OKP_Private}
180
+ * @see {@link JWK_EC_Public}
181
+ * @see {@link JWK_EC_Private}
182
+ * @see {@link JWK_RSA_Public}
183
+ * @see {@link JWK_RSA_Private}
184
+ * @see {@link JWK_oct}
185
+ */
186
+ interface JWK extends JWKParameters {
59
187
  /**
60
- * Is user dedicated to his own resources for this scope ?
61
- * Mostly, Admin is false and Customer is true.
188
+ * - EC JWK "crv" (Curve) Parameter
189
+ * - OKP JWK "crv" (The Subtype of Key Pair) Parameter
62
190
  */
63
- ownership?: string | boolean;
191
+ crv?: string;
192
+ /**
193
+ * - Private RSA JWK "d" (Private Exponent) Parameter
194
+ * - Private EC JWK "d" (ECC Private Key) Parameter
195
+ * - Private OKP JWK "d" (The Private Key) Parameter
196
+ */
197
+ d?: string;
198
+ /** Private RSA JWK "dp" (First Factor CRT Exponent) Parameter */
199
+ dp?: string;
200
+ /** Private RSA JWK "dq" (Second Factor CRT Exponent) Parameter */
201
+ dq?: string;
202
+ /** RSA JWK "e" (Exponent) Parameter */
203
+ e?: string;
204
+ /** Oct JWK "k" (Key Value) Parameter */
205
+ k?: string;
206
+ /** RSA JWK "n" (Modulus) Parameter */
207
+ n?: string;
208
+ /** Private RSA JWK "p" (First Prime Factor) Parameter */
209
+ p?: string;
210
+ /** Private RSA JWK "q" (Second Prime Factor) Parameter */
211
+ q?: string;
212
+ /** Private RSA JWK "qi" (First CRT Coefficient) Parameter */
213
+ qi?: string;
214
+ /**
215
+ * - EC JWK "x" (X Coordinate) Parameter
216
+ * - OKP JWK "x" (The public key) Parameter
217
+ */
218
+ x?: string;
219
+ /** EC JWK "y" (Y Coordinate) Parameter */
220
+ y?: string;
221
+ /** AKP JWK "pub" (Public Key) Parameter */
222
+ pub?: string;
223
+ /** AKP JWK "priv" (Private key) Parameter */
224
+ priv?: string;
64
225
  }
65
- //#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>;
226
+ /**
227
+ * Flattened JWS definition for verify function inputs, allows payload as {@link !Uint8Array} for
228
+ * detached signature validation.
229
+ */
230
+ interface FlattenedJWSInput {
231
+ /**
232
+ * The "header" member MUST be present and contain the value JWS Unprotected Header when the JWS
233
+ * Unprotected Header value is non- empty; otherwise, it MUST be absent. This value is represented
234
+ * as an unencoded JSON object, rather than as a string. These Header Parameter values are not
235
+ * integrity protected.
236
+ */
237
+ header?: JWSHeaderParameters;
238
+ /**
239
+ * The "payload" member MUST be present and contain the value BASE64URL(JWS Payload). When RFC7797
240
+ * "b64": false is used the value passed may also be a {@link !Uint8Array}.
241
+ */
242
+ payload: string | Uint8Array;
243
+ /**
244
+ * The "protected" member MUST be present and contain the value BASE64URL(UTF8(JWS Protected
245
+ * Header)) when the JWS Protected Header value is non-empty; otherwise, it MUST be absent. These
246
+ * Header Parameter values are integrity protected.
247
+ */
248
+ protected?: string;
249
+ /** The "signature" member MUST be present and contain the value BASE64URL(JWS Signature). */
250
+ signature: string;
251
+ }
252
+ /** Header Parameters common to JWE and JWS */
253
+ interface JoseHeaderParameters {
254
+ /** "kid" (Key ID) Header Parameter */
255
+ kid?: string;
256
+ /** "x5t" (X.509 Certificate SHA-1 Thumbprint) Header Parameter */
257
+ x5t?: string;
258
+ /** "x5c" (X.509 Certificate Chain) Header Parameter */
259
+ x5c?: string[];
260
+ /** "x5u" (X.509 URL) Header Parameter */
261
+ x5u?: string;
262
+ /** "jku" (JWK Set URL) Header Parameter */
263
+ jku?: string;
264
+ /** "jwk" (JSON Web Key) Header Parameter */
265
+ jwk?: Pick<JWK, 'kty' | 'crv' | 'x' | 'y' | 'e' | 'n' | 'alg' | 'pub'>;
266
+ /** "typ" (Type) Header Parameter */
267
+ typ?: string;
268
+ /** "cty" (Content Type) Header Parameter */
269
+ cty?: string;
270
+ }
271
+ /** Recognized JWS Header Parameters, any other Header Members may also be present. */
272
+ interface JWSHeaderParameters extends JoseHeaderParameters {
273
+ /**
274
+ * JWS "alg" (Algorithm) Header Parameter
275
+ *
276
+ * @see {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}
277
+ */
278
+ alg?: string;
279
+ /**
280
+ * This JWS Extension Header Parameter modifies the JWS Payload representation and the JWS Signing
281
+ * Input computation as per {@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}.
282
+ */
283
+ b64?: boolean;
284
+ /** JWS "crit" (Critical) Header Parameter */
285
+ crit?: string[];
286
+ /** Any other JWS Header member. */
287
+ [propName: string]: unknown;
288
+ }
289
+ /** Shared Interface with a "crit" property for all sign, verify, encrypt and decrypt operations. */
290
+ interface CritOption {
291
+ /**
292
+ * An object with keys representing recognized "crit" (Critical) Header Parameter names. The value
293
+ * for those is either `true` or `false`. `true` when the Header Parameter MUST be integrity
294
+ * protected, `false` when it's irrelevant.
295
+ *
296
+ * This makes the "Extension Header Parameter "..." is not recognized" error go away.
297
+ *
298
+ * Use this when a given JWS/JWT/JWE profile requires the use of proprietary non-registered "crit"
299
+ * (Critical) Header Parameters. This will only make sure the Header Parameter is syntactically
300
+ * correct when provided and that it is optionally integrity protected. It will not process the
301
+ * Header Parameter in any way or reject the operation if it is missing. You MUST still verify the
302
+ * Header Parameter was present and process it according to the profile's validation steps after
303
+ * the operation succeeds.
304
+ *
305
+ * The JWS extension Header Parameter `b64` is always recognized and processed properly. No other
306
+ * registered Header Parameters that need this kind of default built-in treatment are currently
307
+ * available.
308
+ */
309
+ crit?: {
310
+ [propName: string]: boolean;
311
+ };
312
+ }
313
+ /** JWT Claims Set verification options. */
314
+ interface JWTClaimVerificationOptions {
315
+ /**
316
+ * Expected JWT "aud" (Audience) Claim value(s).
317
+ *
318
+ * This option makes the JWT "aud" (Audience) Claim presence required.
319
+ */
320
+ audience?: string | string[];
321
+ /**
322
+ * Clock skew tolerance
323
+ *
324
+ * - In seconds when number (e.g. 5)
325
+ * - Resolved into a number of seconds when a string (e.g. "5 seconds", "10 minutes", "2 hours").
326
+ *
327
+ * Used when validating the JWT "nbf" (Not Before) and "exp" (Expiration Time) claims, and when
328
+ * validating the "iat" (Issued At) claim if the {@link maxTokenAge `maxTokenAge` option} is set.
329
+ */
330
+ clockTolerance?: string | number;
331
+ /**
332
+ * Expected JWT "iss" (Issuer) Claim value(s).
333
+ *
334
+ * This option makes the JWT "iss" (Issuer) Claim presence required.
335
+ */
336
+ issuer?: string | string[];
337
+ /**
338
+ * Maximum time elapsed (in seconds) from the JWT "iat" (Issued At) Claim value.
339
+ *
340
+ * - In seconds when number (e.g. 5)
341
+ * - Resolved into a number of seconds when a string (e.g. "5 seconds", "10 minutes", "2 hours").
342
+ *
343
+ * This option makes the JWT "iat" (Issued At) Claim presence required.
344
+ */
345
+ maxTokenAge?: string | number;
346
+ /**
347
+ * Expected JWT "sub" (Subject) Claim value.
348
+ *
349
+ * This option makes the JWT "sub" (Subject) Claim presence required.
350
+ */
351
+ subject?: string;
352
+ /**
353
+ * Expected JWT "typ" (Type) Header Parameter value.
354
+ *
355
+ * This option makes the JWT "typ" (Type) Header Parameter presence required.
356
+ */
357
+ typ?: string;
358
+ /** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
359
+ currentDate?: Date;
360
+ /**
361
+ * Array of required Claim Names that must be present in the JWT Claims Set. Default is that: if
362
+ * the {@link issuer `issuer` option} is set, then JWT "iss" (Issuer) Claim must be present; if the
363
+ * {@link audience `audience` option} is set, then JWT "aud" (Audience) Claim must be present; if
364
+ * the {@link subject `subject` option} is set, then JWT "sub" (Subject) Claim must be present; if
365
+ * the {@link maxTokenAge `maxTokenAge` option} is set, then JWT "iat" (Issued At) Claim must be
366
+ * present.
367
+ */
368
+ requiredClaims?: string[];
369
+ }
370
+ /** JWS Verification options. */
371
+ interface VerifyOptions extends CritOption {
372
+ /**
373
+ * A list of accepted JWS "alg" (Algorithm) Header Parameter values. By default all "alg"
374
+ * (Algorithm) values applicable for the used key/secret are allowed.
375
+ *
376
+ * > [!NOTE]\
377
+ * > Unsecured JWTs (`{ "alg": "none" }`) are never accepted by this API.
378
+ */
379
+ algorithms?: string[];
380
+ }
381
+ /** Recognized JWT Claims Set members, any other members may also be present. */
382
+ interface JWTPayload {
383
+ /**
384
+ * JWT Issuer
385
+ *
386
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.1 RFC7519#section-4.1.1}
387
+ */
388
+ iss?: string;
389
+ /**
390
+ * JWT Subject
391
+ *
392
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.2 RFC7519#section-4.1.2}
393
+ */
394
+ sub?: string;
395
+ /**
396
+ * JWT Audience
397
+ *
398
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.3 RFC7519#section-4.1.3}
399
+ */
400
+ aud?: string | string[];
401
+ /**
402
+ * JWT ID
403
+ *
404
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.7 RFC7519#section-4.1.7}
405
+ */
406
+ jti?: string;
407
+ /**
408
+ * JWT Not Before
409
+ *
410
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.5 RFC7519#section-4.1.5}
411
+ */
412
+ nbf?: number;
413
+ /**
414
+ * JWT Expiration Time
415
+ *
416
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4 RFC7519#section-4.1.4}
417
+ */
418
+ exp?: number;
419
+ /**
420
+ * JWT Issued At
421
+ *
422
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6 RFC7519#section-4.1.6}
423
+ */
424
+ iat?: number;
425
+ /** Any other JWT Claim Set member. */
426
+ [propName: string]: unknown;
427
+ }
428
+ /** Signed JSON Web Token (JWT) verification result */
429
+ interface JWTVerifyResult<PayloadType = JWTPayload> {
430
+ /** JWT Claims Set. */
431
+ payload: PayloadType & JWTPayload;
432
+ /** JWS Protected Header. */
433
+ protectedHeader: JWTHeaderParameters;
434
+ }
435
+ /** Recognized Compact JWS Header Parameters, any other Header Members may also be present. */
436
+ interface CompactJWSHeaderParameters extends JWSHeaderParameters {
437
+ alg: string;
438
+ }
439
+ /** Recognized Signed JWT Header Parameters, any other Header Members may also be present. */
440
+ interface JWTHeaderParameters extends CompactJWSHeaderParameters {
441
+ b64?: true;
442
+ }
443
+ /** JSON Web Key Set */
444
+ interface JSONWebKeySet {
445
+ keys: JWK[];
446
+ }
447
+ /**
448
+ * {@link !KeyObject} is a representation of a key/secret available in the Node.js runtime. You may
449
+ * use the Node.js runtime APIs {@link !createPublicKey}, {@link !createPrivateKey}, and
450
+ * {@link !createSecretKey} to obtain a {@link !KeyObject} from your existing key material.
451
+ */
452
+ interface KeyObject {
453
+ type: string;
454
+ }
455
+ /**
456
+ * {@link !CryptoKey} is a representation of a key/secret available in all supported runtimes. In
457
+ * addition to the {@link key/import Key Import Functions} you may use the
458
+ * {@link !SubtleCrypto.importKey} API to obtain a {@link !CryptoKey} from your existing key
459
+ * material.
460
+ */
461
+ type CryptoKey = Extract<Awaited<ReturnType<typeof crypto.subtle.generateKey>>, {
462
+ type: string;
73
463
  }>;
74
- type Permission = Static<typeof permissionSchema>;
75
464
  //#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>;
465
+ //#region ../../../../node_modules/jose/dist/types/jwt/verify.d.ts
466
+ /** Combination of JWS Verification options and JWT Claims Set verification options. */
467
+ interface JWTVerifyOptions extends VerifyOptions, JWTClaimVerificationOptions {}
88
468
  //#endregion
89
469
  //#region ../../src/security/providers/JwtProvider.d.ts
90
470
  /**
91
471
  * Provides utilities for working with JSON Web Tokens (JWT).
92
472
  */
93
473
  declare class JwtProvider {
94
- protected readonly log: alepha_logger0.Logger;
474
+ protected readonly log: alepha_logger2.Logger;
95
475
  protected readonly keystore: KeyLoaderHolder[];
96
476
  protected readonly dateTimeProvider: DateTimeProvider;
97
477
  protected readonly encoder: TextEncoder;
@@ -152,10 +532,33 @@ interface JwtParseResult {
152
532
  result: JWTVerifyResult<ExtendedJWTPayload>;
153
533
  }
154
534
  //#endregion
535
+ //#region ../../src/security/schemas/permissionSchema.d.ts
536
+ declare const permissionSchema: alepha3.TObject<{
537
+ name: alepha3.TString;
538
+ group: alepha3.TOptional<alepha3.TString>;
539
+ description: alepha3.TOptional<alepha3.TString>;
540
+ method: alepha3.TOptional<alepha3.TString>;
541
+ path: alepha3.TOptional<alepha3.TString>;
542
+ }>;
543
+ type Permission = Static<typeof permissionSchema>;
544
+ //#endregion
545
+ //#region ../../src/security/schemas/roleSchema.d.ts
546
+ declare const roleSchema: alepha3.TObject<{
547
+ name: alepha3.TString;
548
+ description: alepha3.TOptional<alepha3.TString>;
549
+ default: alepha3.TOptional<alepha3.TBoolean>;
550
+ permissions: alepha3.TArray<alepha3.TObject<{
551
+ name: alepha3.TString;
552
+ ownership: alepha3.TOptional<alepha3.TBoolean>;
553
+ exclude: alepha3.TOptional<alepha3.TArray<alepha3.TString>>;
554
+ }>>;
555
+ }>;
556
+ type Role = Static<typeof roleSchema>;
557
+ //#endregion
155
558
  //#region ../../src/security/providers/SecurityProvider.d.ts
156
559
  declare const DEFAULT_APP_SECRET = "05759934015388327323179852515731";
157
- declare const envSchema: alepha1.TObject<{
158
- APP_SECRET: alepha1.TString;
560
+ declare const envSchema: alepha3.TObject<{
561
+ APP_SECRET: alepha3.TString;
159
562
  }>;
160
563
  declare module "alepha" {
161
564
  interface Env extends Partial<Static<typeof envSchema>> {}
@@ -164,7 +567,7 @@ declare class SecurityProvider {
164
567
  protected readonly UNKNOWN_USER_NAME = "Anonymous User";
165
568
  protected readonly PERMISSION_REGEXP: RegExp;
166
569
  protected readonly PERMISSION_REGEXP_WILDCARD: RegExp;
167
- protected readonly log: alepha_logger0.Logger;
570
+ protected readonly log: alepha_logger2.Logger;
168
571
  protected readonly jwt: JwtProvider;
169
572
  protected readonly env: {
170
573
  APP_SECRET: string;
@@ -179,7 +582,7 @@ declare class SecurityProvider {
179
582
  * The realms configured for the security provider.
180
583
  */
181
584
  protected readonly realms: Realm[];
182
- protected start: alepha1.HookPrimitive<"start">;
585
+ protected start: alepha3.HookPrimitive<"start">;
183
586
  /**
184
587
  * Adds a role to one or more realms.
185
588
  *
@@ -314,72 +717,41 @@ interface SecurityCheckResult {
314
717
  ownership: string | boolean | undefined;
315
718
  }
316
719
  //#endregion
317
- //#region ../../src/security/primitives/$permission.d.ts
720
+ //#region ../../src/security/primitives/$issuer.d.ts
318
721
  /**
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
352
- /**
353
- * Create a new realm.
722
+ * Create a new issuer.
723
+ *
724
+ * An issuer is responsible for creating and verifying JWT tokens.
725
+ * It can be internal (with a secret) or external (with a JWKS).
354
726
  */
355
- declare const $realm: {
356
- (options: RealmPrimitiveOptions): RealmPrimitive;
357
- [KIND]: typeof RealmPrimitive;
727
+ declare const $issuer: {
728
+ (options: IssuerPrimitiveOptions): IssuerPrimitive;
729
+ [KIND]: typeof IssuerPrimitive;
358
730
  };
359
- type RealmPrimitiveOptions = {
731
+ type IssuerPrimitiveOptions = {
360
732
  /**
361
- * Define the realm name.
733
+ * Define the issuer name.
362
734
  * If not provided, it will use the property key.
363
735
  */
364
736
  name?: string;
365
737
  /**
366
- * Short description about the realm.
738
+ * Short description about the issuer.
367
739
  */
368
740
  description?: string;
369
741
  /**
370
- * All roles available in the realm. Role is a string (role name) or a Role object (embedded role).
742
+ * All roles available in the issuer. Role is a string (role name) or a Role object (embedded role).
371
743
  */
372
744
  roles?: Array<string | Role>;
373
745
  /**
374
- * Realm settings.
746
+ * Issuer settings.
375
747
  */
376
- settings?: RealmSettings;
748
+ settings?: IssuerSettings;
377
749
  /**
378
750
  * Parse the JWT payload to create a user account info.
379
751
  */
380
752
  profile?: (jwtPayload: Record<string, any>) => UserAccount;
381
- } & (RealmInternal | RealmExternal);
382
- interface RealmSettings {
753
+ } & (IssuerInternal | IssuerExternal);
754
+ interface IssuerSettings {
383
755
  accessToken?: {
384
756
  /**
385
757
  * Lifetime of the access token.
@@ -407,33 +779,33 @@ interface RealmSettings {
407
779
  }>;
408
780
  onDeleteSession?: (refreshToken: string) => Promise<void>;
409
781
  }
410
- type RealmInternal = {
782
+ type IssuerInternal = {
411
783
  /**
412
784
  * Internal secret to sign JWT tokens and verify them.
413
785
  */
414
786
  secret: string;
415
787
  };
416
- interface RealmExternal {
788
+ interface IssuerExternal {
417
789
  /**
418
790
  * URL to the JWKS (JSON Web Key Set) to verify JWT tokens from external providers.
419
791
  */
420
792
  jwks: (() => string) | JSONWebKeySet;
421
793
  }
422
- declare class RealmPrimitive extends Primitive<RealmPrimitiveOptions> {
794
+ declare class IssuerPrimitive extends Primitive<IssuerPrimitiveOptions> {
423
795
  protected readonly securityProvider: SecurityProvider;
424
796
  protected readonly dateTimeProvider: DateTimeProvider;
425
797
  protected readonly jwt: JwtProvider;
426
- protected readonly log: alepha_logger0.Logger;
798
+ protected readonly log: alepha_logger2.Logger;
427
799
  get name(): string;
428
800
  get accessTokenExpiration(): Duration;
429
801
  get refreshTokenExpiration(): Duration;
430
802
  protected onInit(): void;
431
803
  /**
432
- * Get all roles in the realm.
804
+ * Get all roles in the issuer.
433
805
  */
434
806
  getRoles(): Role[];
435
807
  /**
436
- * Set all roles in the realm.
808
+ * Set all roles in the issuer.
437
809
  */
438
810
  setRoles(roles: Role[]): Promise<void>;
439
811
  /**
@@ -469,6 +841,40 @@ interface AccessTokenResponse {
469
841
  scope?: string;
470
842
  }
471
843
  //#endregion
844
+ //#region ../../src/security/primitives/$permission.d.ts
845
+ /**
846
+ * Create a new permission.
847
+ */
848
+ declare const $permission: {
849
+ (options?: PermissionPrimitiveOptions): PermissionPrimitive;
850
+ [KIND]: typeof PermissionPrimitive;
851
+ };
852
+ interface PermissionPrimitiveOptions {
853
+ /**
854
+ * Name of the permission. Use Property name is not provided.
855
+ */
856
+ name?: string;
857
+ /**
858
+ * Group of the permission. Use Class name is not provided.
859
+ */
860
+ group?: string;
861
+ /**
862
+ * Describe the permission.
863
+ */
864
+ description?: string;
865
+ }
866
+ declare class PermissionPrimitive extends Primitive<PermissionPrimitiveOptions> {
867
+ protected readonly securityProvider: SecurityProvider;
868
+ get name(): string;
869
+ get group(): string;
870
+ toString(): string;
871
+ protected onInit(): void;
872
+ /**
873
+ * Check if the user has the permission.
874
+ */
875
+ can(user?: UserAccount): boolean;
876
+ }
877
+ //#endregion
472
878
  //#region ../../src/security/primitives/$role.d.ts
473
879
  /**
474
880
  * Create a new role.
@@ -486,7 +892,7 @@ interface RolePrimitiveOptions {
486
892
  * Describe the role.
487
893
  */
488
894
  description?: string;
489
- realm?: string | RealmPrimitive;
895
+ issuer?: string | IssuerPrimitive;
490
896
  permissions?: Array<string | {
491
897
  name: string;
492
898
  ownership?: boolean;
@@ -498,9 +904,9 @@ declare class RolePrimitive extends Primitive<RolePrimitiveOptions> {
498
904
  get name(): string;
499
905
  protected onInit(): void;
500
906
  /**
501
- * Get the realm of the role.
907
+ * Get the issuer of the role.
502
908
  */
503
- get realm(): string | RealmPrimitive | undefined;
909
+ get issuer(): string | IssuerPrimitive | undefined;
504
910
  can(permission: string | PermissionPrimitive): boolean;
505
911
  check(permission: string | PermissionPrimitive): SecurityCheckResult;
506
912
  }
@@ -540,7 +946,7 @@ type ServiceAccountPrimitiveOptions = {
540
946
  } & ({
541
947
  oauth2: Oauth2ServiceAccountPrimitiveOptions;
542
948
  } | {
543
- realm: RealmPrimitive;
949
+ issuer: IssuerPrimitive;
544
950
  user: UserAccount;
545
951
  });
546
952
  interface Oauth2ServiceAccountPrimitiveOptions {
@@ -571,6 +977,38 @@ declare class CryptoProvider {
571
977
  randomUUID(): string;
572
978
  }
573
979
  //#endregion
980
+ //#region ../../src/security/providers/ServerSecurityProvider.d.ts
981
+ declare class ServerSecurityProvider {
982
+ protected readonly log: alepha_logger2.Logger;
983
+ protected readonly securityProvider: SecurityProvider;
984
+ protected readonly jwtProvider: JwtProvider;
985
+ protected readonly alepha: Alepha;
986
+ protected readonly onConfigure: alepha3.HookPrimitive<"configure">;
987
+ protected readonly onActionRequest: alepha3.HookPrimitive<"action:onRequest">;
988
+ protected readonly onRequest: alepha3.HookPrimitive<"server:onRequest">;
989
+ protected check(user: UserAccountToken, secure: ServerRouteSecure): void;
990
+ /**
991
+ * Get the user account token for a local action call.
992
+ * There are three possible sources for the user:
993
+ * - `options.user`: the user passed in the options
994
+ * - `"system"`: the system user from the state (you MUST set state `server.security.system.user`)
995
+ * - `"context"`: the user from the request context (you MUST be in an HTTP request context)
996
+ *
997
+ * Priority order: `options.user` > `"system"` > `"context"`.
998
+ *
999
+ * In testing environment, if no user is provided, a test user is created based on the SecurityProvider's roles.
1000
+ */
1001
+ protected createUserFromLocalFunctionContext(options: {
1002
+ user?: UserAccountToken | "system" | "context";
1003
+ }, permission?: Permission): UserAccountToken;
1004
+ protected createTestUser(): UserAccountToken;
1005
+ protected readonly onClientRequest: alepha3.HookPrimitive<"client:onRequest">;
1006
+ }
1007
+ type ServerRouteSecure = {
1008
+ realm?: string;
1009
+ basic?: BasicAuthOptions;
1010
+ };
1011
+ //#endregion
574
1012
  //#region ../../src/security/index.d.ts
575
1013
  declare module "alepha" {
576
1014
  interface Hooks {
@@ -579,20 +1017,68 @@ declare module "alepha" {
579
1017
  user: UserAccount;
580
1018
  };
581
1019
  }
1020
+ interface State {
1021
+ /**
1022
+ * Real (or fake) user account, used for internal actions.
1023
+ *
1024
+ * If you define this, you assume that all actions are executed by this user by default.
1025
+ * > To force a different user, you need to pass it explicitly in the options.
1026
+ */
1027
+ "alepha.server.security.system.user"?: UserAccountToken;
1028
+ /**
1029
+ * The authenticated user account attached to the server request state.
1030
+ *
1031
+ * @internal
1032
+ */
1033
+ "alepha.server.request.user"?: UserAccount;
1034
+ }
1035
+ }
1036
+ declare module "alepha/server" {
1037
+ interface ServerRequest<TConfig> {
1038
+ user?: UserAccountToken;
1039
+ }
1040
+ interface ServerActionRequest<TConfig> {
1041
+ user: UserAccountToken;
1042
+ }
1043
+ interface ServerRoute {
1044
+ /**
1045
+ * If true, the route will be protected by the security provider.
1046
+ * All actions are secure by default, but you can disable it for specific actions.
1047
+ */
1048
+ secure?: boolean | ServerRouteSecure;
1049
+ }
1050
+ interface ClientRequestOptions extends FetchOptions {
1051
+ /**
1052
+ * Forward user from the previous request.
1053
+ * If "system", use system user. @see {ServerSecurityProvider.localSystemUser}
1054
+ * If "context", use the user from the current context (e.g. request).
1055
+ *
1056
+ * @default "system" if provided, else "context" if available.
1057
+ */
1058
+ user?: UserAccountToken | "system" | "context";
1059
+ }
582
1060
  }
583
1061
  /**
584
1062
  * Provides comprehensive authentication and authorization capabilities with JWT tokens, role-based access control, and user management.
585
1063
  *
586
- * The security module enables building secure applications using primitives like `$realm`, `$role`, and `$permission`
1064
+ * The security module enables building secure applications using primitives like `$issuer`, `$role`, and `$permission`
587
1065
  * on class properties. It offers JWT-based authentication, fine-grained permissions, service accounts, and seamless
588
1066
  * integration with various authentication providers and user management systems.
589
1067
  *
590
- * @see {@link $realm}
1068
+ * When used with `AlephaServer`, this module automatically registers `ServerSecurityProvider` and `ServerBasicAuthProvider`
1069
+ * to protect HTTP routes and actions with JWT and Basic Auth.
1070
+ *
1071
+ * @see {@link $issuer}
591
1072
  * @see {@link $role}
592
1073
  * @see {@link $permission}
1074
+ * @see {@link $basicAuth}
593
1075
  * @module alepha.security
594
1076
  */
595
- declare const AlephaSecurity: alepha1.Service<alepha1.Module>;
1077
+ declare const AlephaSecurity: alepha3.Service<alepha3.Module>;
1078
+ /**
1079
+ * @deprecated Use `AlephaSecurity` instead. Server security providers are automatically registered when `AlephaServer` is available.
1080
+ */
1081
+ declare const AlephaServerSecurity: alepha3.Service<alepha3.Module>;
596
1082
  //#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 };
1083
+ 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
1084
  //# sourceMappingURL=index.d.ts.map