@fabrika/iam 0.0.1 → 0.9.0-dev.26

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 (312) hide show
  1. package/fabrika.config.ts +267 -0
  2. package/migrations/0001_init.sql +316 -0
  3. package/migrations/0002_oauth.sql +38 -0
  4. package/migrations/0003_contract_apps.sql +11 -0
  5. package/migrations/0004_membership.sql +93 -0
  6. package/migrations/0005_workloads.sql +23 -0
  7. package/migrations/0006_membership_transport_keys.sql +16 -0
  8. package/migrations/0007_member_directory.sql +7 -0
  9. package/migrations/0008_durable_audit.sql +28 -0
  10. package/migrations/0009_member_lookups.sql +7 -0
  11. package/migrations/0010_workload_issues.sql +6 -0
  12. package/migrations/0011_app_presentation.sql +15 -0
  13. package/migrations/0012_external_principals.sql +10 -0
  14. package/migrations/0013_app_mail_templates.sql +14 -0
  15. package/migrations/0014_invitation_wording.sql +8 -0
  16. package/migrations/0015_app_schema_revisions.sql +15 -0
  17. package/migrations/0016_principal_grant_revision.sql +9 -0
  18. package/migrations/0017_app_sign_ins.sql +12 -0
  19. package/migrations/0018_app_members.sql +13 -0
  20. package/migrations/0019_app_mail_html.sql +7 -0
  21. package/migrations/0020_public_workloads.sql +34 -0
  22. package/migrations/0021_installation_brand.sql +19 -0
  23. package/migrations/0022_password_policy.sql +12 -0
  24. package/migrations/0023_terminals.sql +155 -0
  25. package/migrations/0024_app_terminals.sql +10 -0
  26. package/migrations/0025_terminal_completion.sql +10 -0
  27. package/migrations/0026_terminal_generation.sql +12 -0
  28. package/migrations/0027_application_exact_actions.sql +28 -0
  29. package/migrations/0028_oauth_client_assertions.sql +10 -0
  30. package/migrations/0029_role_via.sql +6 -0
  31. package/migrations/0030_membership_role_via.sql +12 -0
  32. package/migrations/0031_person_locale.sql +11 -0
  33. package/migrations-postgres/0001_init.sql +331 -0
  34. package/migrations-postgres/0002_oauth.sql +36 -0
  35. package/migrations-postgres/0003_contract_apps.sql +8 -0
  36. package/migrations-postgres/0004_membership.sql +92 -0
  37. package/migrations-postgres/0005_workloads.sql +18 -0
  38. package/migrations-postgres/0006_membership_transport_keys.sql +12 -0
  39. package/migrations-postgres/0007_member_directory.sql +7 -0
  40. package/migrations-postgres/0008_durable_audit.sql +8 -0
  41. package/migrations-postgres/0009_member_lookups.sql +7 -0
  42. package/migrations-postgres/0010_workload_issues.sql +6 -0
  43. package/migrations-postgres/0011_app_presentation.sql +15 -0
  44. package/migrations-postgres/0012_external_principals.sql +10 -0
  45. package/migrations-postgres/0013_app_mail_templates.sql +14 -0
  46. package/migrations-postgres/0014_invitation_wording.sql +8 -0
  47. package/migrations-postgres/0015_app_schema_revisions.sql +15 -0
  48. package/migrations-postgres/0016_principal_grant_revision.sql +9 -0
  49. package/migrations-postgres/0017_app_sign_ins.sql +12 -0
  50. package/migrations-postgres/0018_app_members.sql +13 -0
  51. package/migrations-postgres/0019_app_mail_html.sql +7 -0
  52. package/migrations-postgres/0020_public_workloads.sql +9 -0
  53. package/migrations-postgres/0021_installation_brand.sql +19 -0
  54. package/migrations-postgres/0022_password_policy.sql +12 -0
  55. package/migrations-postgres/0023_terminals.sql +70 -0
  56. package/migrations-postgres/0024_app_terminals.sql +10 -0
  57. package/migrations-postgres/0025_terminal_completion.sql +10 -0
  58. package/migrations-postgres/0026_terminal_generation.sql +12 -0
  59. package/migrations-postgres/0027_application_exact_actions.sql +28 -0
  60. package/migrations-postgres/0028_oauth_client_assertions.sql +9 -0
  61. package/migrations-postgres/0029_role_via.sql +4 -0
  62. package/migrations-postgres/0030_membership_role_via.sql +7 -0
  63. package/migrations-postgres/0031_person_locale.sql +11 -0
  64. package/package.json +69 -8
  65. package/src/admin/access.ts +47 -0
  66. package/src/admin/api-keys.ts +280 -0
  67. package/src/admin/app-people.ts +209 -0
  68. package/src/admin/app-schema.ts +308 -0
  69. package/src/admin/audit.ts +81 -0
  70. package/src/admin/brand.ts +54 -0
  71. package/src/admin/connections.ts +48 -0
  72. package/src/admin/context.ts +70 -0
  73. package/src/admin/grant-support.ts +192 -0
  74. package/src/admin/grants.ts +189 -0
  75. package/src/admin/handlers.ts +102 -0
  76. package/src/admin/http.ts +24 -0
  77. package/src/admin/membership-keys.ts +38 -0
  78. package/src/admin/pagination.ts +28 -0
  79. package/src/admin/password-policy.ts +48 -0
  80. package/src/admin/passwords.ts +78 -0
  81. package/src/admin/policies.ts +136 -0
  82. package/src/admin/principals.ts +226 -0
  83. package/src/admin/router.ts +291 -0
  84. package/src/admin/rpc.ts +387 -0
  85. package/src/admin/sessions.ts +115 -0
  86. package/src/admin/share-links.ts +127 -0
  87. package/src/admin/terminals.ts +115 -0
  88. package/src/admin/user-admin.ts +76 -0
  89. package/src/admin/workloads.ts +85 -0
  90. package/src/app-presentation.ts +178 -0
  91. package/src/app.ts +158 -0
  92. package/src/auth/cookies.ts +64 -0
  93. package/src/auth/failure.ts +25 -0
  94. package/src/auth/handoff.ts +136 -0
  95. package/src/auth/http.ts +88 -0
  96. package/src/auth/invitations.ts +220 -0
  97. package/src/auth/known-device.ts +44 -0
  98. package/src/auth/login.ts +162 -0
  99. package/src/auth/oidc-flight.ts +91 -0
  100. package/src/auth/oidc.ts +148 -0
  101. package/src/auth/password.ts +416 -0
  102. package/src/auth/routes.ts +108 -0
  103. package/src/auth/sessions.ts +249 -0
  104. package/src/auth/terminals.ts +284 -0
  105. package/src/auth.ts +193 -0
  106. package/src/binding-identity.ts +25 -0
  107. package/src/bounded-body.ts +35 -0
  108. package/src/catalog/cs.ts +147 -0
  109. package/src/catalog/en.ts +148 -0
  110. package/src/catalog/index.ts +122 -0
  111. package/src/catalog/uk.ts +164 -0
  112. package/src/client-address.ts +39 -0
  113. package/src/common-passwords.ts +37 -0
  114. package/src/contract-rules.ts +80 -0
  115. package/src/cron.ts +54 -0
  116. package/src/db.ts +128 -0
  117. package/src/delegation.ts +100 -0
  118. package/src/device-http.ts +39 -0
  119. package/src/device.ts +269 -0
  120. package/src/email-identity.ts +2 -0
  121. package/src/env.ts +132 -0
  122. package/src/handoff.ts +175 -0
  123. package/src/html.ts +4 -0
  124. package/src/human-admission.ts +40 -0
  125. package/src/identification.ts +185 -0
  126. package/src/index.ts +292 -0
  127. package/src/installation-brand.ts +82 -0
  128. package/src/issue.ts +265 -0
  129. package/src/json.ts +30 -0
  130. package/src/log.ts +26 -0
  131. package/src/membership-http.ts +135 -0
  132. package/src/membership.ts +1210 -0
  133. package/src/messages.ts +44 -0
  134. package/src/narrow-permissions.ts +26 -0
  135. package/src/node/browser-identity.ts +69 -0
  136. package/src/node/migrate.ts +52 -0
  137. package/src/node/prune.ts +34 -0
  138. package/src/node/runtime.ts +221 -0
  139. package/src/node/server.ts +104 -0
  140. package/src/oauth-client-auth.ts +93 -0
  141. package/src/oauth-client.ts +145 -0
  142. package/src/oauth-config.ts +72 -0
  143. package/src/oauth-http.ts +262 -0
  144. package/src/oauth.ts +272 -0
  145. package/src/oidc.ts +260 -0
  146. package/src/origin.ts +29 -0
  147. package/src/password-crypto.ts +148 -0
  148. package/src/password-db.ts +419 -0
  149. package/src/password-minimum.ts +44 -0
  150. package/src/password-pages.ts +397 -0
  151. package/src/password-policy.ts +79 -0
  152. package/src/password-service.ts +67 -0
  153. package/src/person-locale.ts +103 -0
  154. package/src/proxy-proof.ts +36 -0
  155. package/src/relay-mail.ts +64 -0
  156. package/src/repositories/app-schema.ts +550 -0
  157. package/src/repositories/audit.ts +405 -0
  158. package/src/repositories/brand.ts +66 -0
  159. package/src/repositories/credentials.ts +331 -0
  160. package/src/repositories/device.ts +137 -0
  161. package/src/repositories/grants.ts +404 -0
  162. package/src/repositories/handoff.ts +103 -0
  163. package/src/repositories/membership-transport.ts +49 -0
  164. package/src/repositories/membership.ts +875 -0
  165. package/src/repositories/oauth.ts +122 -0
  166. package/src/repositories/password-policy.ts +44 -0
  167. package/src/repositories/principals.ts +358 -0
  168. package/src/repositories/sessions.ts +339 -0
  169. package/src/repositories/sql.ts +23 -0
  170. package/src/repositories/terminals.ts +346 -0
  171. package/src/repositories/workloads.ts +134 -0
  172. package/src/request-id.ts +46 -0
  173. package/src/resolve.ts +396 -0
  174. package/src/retention.ts +34 -0
  175. package/src/roles.ts +54 -0
  176. package/src/rpc-http.ts +333 -0
  177. package/src/rpc-inputs.ts +110 -0
  178. package/src/rpc.ts +440 -0
  179. package/src/secret.ts +45 -0
  180. package/src/service.ts +59 -0
  181. package/src/services.ts +199 -0
  182. package/src/signing.ts +260 -0
  183. package/src/stored-chain.ts +23 -0
  184. package/src/stored-permissions.ts +34 -0
  185. package/src/terminals.ts +15 -0
  186. package/src/tokens.ts +506 -0
  187. package/src/workload-token.ts +130 -0
  188. package/types/fabrika.config.d.ts +11 -0
  189. package/types/src/admin/access.d.ts +19 -0
  190. package/types/src/admin/api-keys.d.ts +26 -0
  191. package/types/src/admin/app-people.d.ts +8 -0
  192. package/types/src/admin/app-schema.d.ts +32 -0
  193. package/types/src/admin/audit.d.ts +10 -0
  194. package/types/src/admin/brand.d.ts +10 -0
  195. package/types/src/admin/connections.d.ts +5 -0
  196. package/types/src/admin/context.d.ts +46 -0
  197. package/types/src/admin/grant-support.d.ts +59 -0
  198. package/types/src/admin/grants.d.ts +8 -0
  199. package/types/src/admin/handlers.d.ts +82 -0
  200. package/types/src/admin/http.d.ts +9 -0
  201. package/types/src/admin/membership-keys.d.ts +8 -0
  202. package/types/src/admin/pagination.d.ts +5 -0
  203. package/types/src/admin/password-policy.d.ts +9 -0
  204. package/types/src/admin/passwords.d.ts +5 -0
  205. package/types/src/admin/policies.d.ts +15 -0
  206. package/types/src/admin/principals.d.ts +15 -0
  207. package/types/src/admin/router.d.ts +75 -0
  208. package/types/src/admin/rpc.d.ts +6 -0
  209. package/types/src/admin/sessions.d.ts +14 -0
  210. package/types/src/admin/share-links.d.ts +21 -0
  211. package/types/src/admin/terminals.d.ts +13 -0
  212. package/types/src/admin/user-admin.d.ts +30 -0
  213. package/types/src/admin/workloads.d.ts +5 -0
  214. package/types/src/app-presentation.d.ts +86 -0
  215. package/types/src/app.d.ts +62 -0
  216. package/types/src/auth/cookies.d.ts +29 -0
  217. package/types/src/auth/failure.d.ts +47 -0
  218. package/types/src/auth/handoff.d.ts +66 -0
  219. package/types/src/auth/http.d.ts +29 -0
  220. package/types/src/auth/invitations.d.ts +18 -0
  221. package/types/src/auth/known-device.d.ts +12 -0
  222. package/types/src/auth/login.d.ts +10 -0
  223. package/types/src/auth/oidc-flight.d.ts +39 -0
  224. package/types/src/auth/oidc.d.ts +7 -0
  225. package/types/src/auth/password.d.ts +7 -0
  226. package/types/src/auth/routes.d.ts +15 -0
  227. package/types/src/auth/sessions.d.ts +60 -0
  228. package/types/src/auth/terminals.d.ts +47 -0
  229. package/types/src/auth.d.ts +70 -0
  230. package/types/src/binding-identity.d.ts +12 -0
  231. package/types/src/bounded-body.d.ts +12 -0
  232. package/types/src/catalog/cs.d.ts +2 -0
  233. package/types/src/catalog/en.d.ts +2 -0
  234. package/types/src/catalog/index.d.ts +112 -0
  235. package/types/src/catalog/uk.d.ts +2 -0
  236. package/types/src/client-address.d.ts +31 -0
  237. package/types/src/common-passwords.d.ts +2 -0
  238. package/types/src/contract-rules.d.ts +25 -0
  239. package/types/src/cron.d.ts +15 -0
  240. package/types/src/db.d.ts +58 -0
  241. package/types/src/delegation.d.ts +38 -0
  242. package/types/src/device-http.d.ts +2 -0
  243. package/types/src/device.d.ts +11 -0
  244. package/types/src/email-identity.d.ts +1 -0
  245. package/types/src/env.d.ts +127 -0
  246. package/types/src/handoff.d.ts +57 -0
  247. package/types/src/html.d.ts +2 -0
  248. package/types/src/human-admission.d.ts +22 -0
  249. package/types/src/identification.d.ts +30 -0
  250. package/types/src/index.d.ts +62 -0
  251. package/types/src/installation-brand.d.ts +22 -0
  252. package/types/src/issue.d.ts +62 -0
  253. package/types/src/json.d.ts +15 -0
  254. package/types/src/log.d.ts +15 -0
  255. package/types/src/membership-http.d.ts +8 -0
  256. package/types/src/membership.d.ts +156 -0
  257. package/types/src/messages.d.ts +20 -0
  258. package/types/src/narrow-permissions.d.ts +7 -0
  259. package/types/src/node/browser-identity.d.ts +1 -0
  260. package/types/src/node/migrate.d.ts +4 -0
  261. package/types/src/node/prune.d.ts +1 -0
  262. package/types/src/node/runtime.d.ts +51 -0
  263. package/types/src/node/server.d.ts +5 -0
  264. package/types/src/oauth-client-auth.d.ts +26 -0
  265. package/types/src/oauth-client.d.ts +17 -0
  266. package/types/src/oauth-config.d.ts +16 -0
  267. package/types/src/oauth-http.d.ts +7 -0
  268. package/types/src/oauth.d.ts +51 -0
  269. package/types/src/oidc.d.ts +81 -0
  270. package/types/src/origin.d.ts +9 -0
  271. package/types/src/password-crypto.d.ts +37 -0
  272. package/types/src/password-db.d.ts +134 -0
  273. package/types/src/password-minimum.d.ts +23 -0
  274. package/types/src/password-pages.d.ts +143 -0
  275. package/types/src/password-policy.d.ts +19 -0
  276. package/types/src/password-service.d.ts +24 -0
  277. package/types/src/person-locale.d.ts +50 -0
  278. package/types/src/proxy-proof.d.ts +21 -0
  279. package/types/src/relay-mail.d.ts +25 -0
  280. package/types/src/repositories/app-schema.d.ts +244 -0
  281. package/types/src/repositories/audit.d.ts +187 -0
  282. package/types/src/repositories/brand.d.ts +41 -0
  283. package/types/src/repositories/credentials.d.ts +148 -0
  284. package/types/src/repositories/device.d.ts +50 -0
  285. package/types/src/repositories/grants.d.ts +177 -0
  286. package/types/src/repositories/handoff.d.ts +52 -0
  287. package/types/src/repositories/membership-transport.d.ts +31 -0
  288. package/types/src/repositories/membership.d.ts +273 -0
  289. package/types/src/repositories/oauth.d.ts +55 -0
  290. package/types/src/repositories/password-policy.d.ts +25 -0
  291. package/types/src/repositories/principals.d.ts +159 -0
  292. package/types/src/repositories/sessions.d.ts +150 -0
  293. package/types/src/repositories/sql.d.ts +13 -0
  294. package/types/src/repositories/terminals.d.ts +144 -0
  295. package/types/src/repositories/workloads.d.ts +61 -0
  296. package/types/src/request-id.d.ts +25 -0
  297. package/types/src/resolve.d.ts +118 -0
  298. package/types/src/retention.d.ts +18 -0
  299. package/types/src/roles.d.ts +34 -0
  300. package/types/src/rpc-http.d.ts +53 -0
  301. package/types/src/rpc-inputs.d.ts +707 -0
  302. package/types/src/rpc.d.ts +4 -0
  303. package/types/src/secret.d.ts +21 -0
  304. package/types/src/service.d.ts +19 -0
  305. package/types/src/services.d.ts +72 -0
  306. package/types/src/signing.d.ts +72 -0
  307. package/types/src/stored-chain.d.ts +6 -0
  308. package/types/src/stored-permissions.d.ts +12 -0
  309. package/types/src/terminals.d.ts +7 -0
  310. package/types/src/tokens.d.ts +113 -0
  311. package/types/src/workload-token.d.ts +7 -0
  312. package/README.md +0 -3
@@ -0,0 +1,12 @@
1
+ export type BoundedBody = {
2
+ ok: true;
3
+ text: string;
4
+ } | {
5
+ ok: false;
6
+ reason: 'too_large' | 'unreadable';
7
+ };
8
+ /**
9
+ * A public route's request body as text, never more than `maxBytes` of it: a declared `Content-Length` over the cap is
10
+ * refused before reading, and a stream is cancelled at the first chunk past it. An absent body is the empty text.
11
+ */
12
+ export declare function readBoundedText(request: Request, maxBytes: number): Promise<BoundedBody>;
@@ -0,0 +1,2 @@
1
+ import type { Catalog } from './index';
2
+ export declare const cs: Catalog;
@@ -0,0 +1,2 @@
1
+ import type { Catalog } from './index';
2
+ export declare const en: Catalog;
@@ -0,0 +1,112 @@
1
+ import type { IamMailCatalog, Locale } from '@fabrika/auth-core';
2
+ import type { AuthFailure } from '../auth/failure';
3
+ import type { PasswordProblem } from '../password-policy';
4
+ export interface PageText {
5
+ /** The words before fabrika's mark and name in the footer of every page: "Runs on [mark] fabrika". */
6
+ readonly runsOn: string;
7
+ readonly showPassword: string;
8
+ readonly hidePassword: string;
9
+ readonly email: string;
10
+ readonly signIn: {
11
+ /** The page title and heading; `appName` is the application the login hands off to, if it declares one. */
12
+ readonly title: (appName: string | null) => string;
13
+ readonly password: string;
14
+ readonly submit: string;
15
+ readonly forgot: string;
16
+ readonly singleSignOn: string;
17
+ readonly invalidCredentials: string;
18
+ };
19
+ /** A handoff a browser already signed in here may continue, or end to sign in with another account. */
20
+ readonly chooseAccount: {
21
+ readonly title: (appName: string | null) => string;
22
+ /** Followed by the account's label. */
23
+ readonly signedInAs: string;
24
+ readonly continueAs: (label: string) => string;
25
+ readonly another: string;
26
+ /** Another account ends this login, and every app session made from it. */
27
+ readonly anotherNote: string;
28
+ };
29
+ readonly forgot: {
30
+ readonly title: string;
31
+ readonly intro: (appName: string | null) => string;
32
+ readonly submit: string;
33
+ readonly sentTitle: string;
34
+ readonly sentText: string;
35
+ readonly back: string;
36
+ };
37
+ readonly setPassword: {
38
+ readonly title: (purpose: 'enrollment' | 'reset') => string;
39
+ readonly rule: (min: number, max: number) => string;
40
+ /** The password belongs to the person's account on the installation, not to the application. */
41
+ readonly shared: (appName: string | null) => string;
42
+ readonly newPassword: string;
43
+ readonly problem: (problem: PasswordProblem, min: number, max: number) => string;
44
+ };
45
+ readonly failure: {
46
+ readonly title: string;
47
+ readonly text: (failure: AuthFailure) => string;
48
+ };
49
+ readonly invalidLink: {
50
+ readonly title: string;
51
+ readonly text: string;
52
+ readonly requestNew: string;
53
+ };
54
+ readonly logout: {
55
+ readonly title: string;
56
+ readonly text: string;
57
+ readonly submit: string;
58
+ };
59
+ /** Enrolling this browser as a shared terminal (ADR-0067): the administrator's form, and the page that ends it. */
60
+ readonly terminal: {
61
+ readonly enrolTitle: string;
62
+ /** Enrolling signs the administrator out of this browser. */
63
+ readonly enrolText: string;
64
+ readonly label: string;
65
+ readonly labelProblem: (max: number) => string;
66
+ readonly submit: string;
67
+ readonly enrolledTitle: string;
68
+ readonly enrolledText: (label: string) => string;
69
+ };
70
+ readonly invitation: {
71
+ readonly title: string;
72
+ readonly text: string;
73
+ readonly submit: string;
74
+ /** The set-password form of an invitation that creates its principal; `address` is the invited mailbox. */
75
+ readonly createTitle: string;
76
+ readonly createText: (address: string) => string;
77
+ readonly createSubmit: string;
78
+ /** A browser signed in here as someone else opened an invitation that creates a new account for `address`. */
79
+ readonly otherAccountTitle: string;
80
+ readonly otherAccountText: (address: string) => string;
81
+ readonly signOut: string;
82
+ readonly signInFirstTitle: string;
83
+ readonly signInFirstText: string;
84
+ readonly signIn: string;
85
+ /**
86
+ * No principal holds `address`, this invitation creates none, and no sign-in here would create one: the person
87
+ * cannot accept on their own. The invitation stays open.
88
+ */
89
+ readonly noAccountTitle: string;
90
+ readonly noAccountText: (address: string) => string;
91
+ readonly unavailableTitle: string;
92
+ readonly accountCannotAccept: string;
93
+ readonly wrongAddressTitle: string;
94
+ readonly wrongAddressText: string;
95
+ readonly inviterCannotGrant: string;
96
+ /** An external principal and a role not declared external (ADR-0051). */
97
+ readonly roleNotEligible: string;
98
+ readonly acceptedTitle: string;
99
+ readonly acceptedText: (values: {
100
+ readonly role: string;
101
+ readonly scope: string;
102
+ readonly appName: string;
103
+ }) => string;
104
+ readonly invalidTitle: string;
105
+ readonly invalidText: string;
106
+ };
107
+ }
108
+ /** IAM's words: its pages here, and its e-mails as `@fabrika/auth-core` words them (`iamMailCatalog`). */
109
+ export interface Catalog extends IamMailCatalog {
110
+ readonly pages: PageText;
111
+ }
112
+ export declare function catalogFor(locale: Locale): Catalog;
@@ -0,0 +1,2 @@
1
+ import type { Catalog } from './index';
2
+ export declare const uk: Catalog;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The client coordinate a per-client abuse limit is keyed on — and, more importantly, the rule about
3
+ * where it may come from.
4
+ *
5
+ * IAM cannot derive it. Behind a balancer its socket peer IS the balancer, and a forwarding header the
6
+ * caller can write is worse than no limiter because it looks like protection — backlog 21 and 49
7
+ * refused to build on one twice before this shipped
8
+ * ([sprint](../../../docs/archive/sprint-2026-08-05-auth-track-closeout.md)). So IAM does not
9
+ * choose a header: the COMPOSITION ROOT names the one header its own ingress guarantees, and shared
10
+ * code reads that one and nothing else. Naming none is a supported configuration — it means this
11
+ * installation cannot see its clients, and the account and deployment-wide buckets carry the load
12
+ * alone, exactly as they did before.
13
+ *
14
+ * The two roots and what they name:
15
+ *
16
+ * - `src/index.ts` (Cloudflare) — `CF-Connecting-IP`. IAM's Worker holds its own Custom Domain, so
17
+ * it is reached through Cloudflare's edge, which writes that header and replaces a caller's.
18
+ * - `src/node/server.ts` (Bun/Zerops) — none. The Caddy proxy in front of it writes `CLIENT_ADDRESS_HEADER`, but
19
+ * behind the Zerops balancer that value is the balancer for every client
20
+ * ([platform facts](../../../docs/reference/zerops-platform.md#public-access)), so one bucket would hold the
21
+ * whole installation. Without the proxy's secret a request still keys on `UNPROVEN_CLIENT_ADDRESS`
22
+ * (`src/proxy-proof.ts`).
23
+ *
24
+ * A composition names a header only when its ingress overwrites it with the client's own address. That is the whole
25
+ * invariant.
26
+ */
27
+ /**
28
+ * Read the coordinate, or `null` when this composition cannot see one or the value is no IP address. An IPv6 client
29
+ * counts by its /64, and only the first value counts (`clientAddressKey`).
30
+ */
31
+ export declare function readClientAddress(request: Request, header: string | undefined): string | null;
@@ -0,0 +1,2 @@
1
+ /** Every entry, lowercased. */
2
+ export declare const COMMON_PASSWORD_LIST: ReadonlySet<string>;
@@ -0,0 +1,25 @@
1
+ import type { AppSchemaRepository } from './repositories/app-schema';
2
+ import type { PrincipalRow } from './repositories/principals';
3
+ type ContractSchema = Pick<AppSchemaRepository, 'isContractApp' | 'getRole'>;
4
+ /** Why these action patterns may not be written for `app`, or null. */
5
+ export declare function contractPatternsProblem(appSchema: ContractSchema, app: string, patterns: readonly string[]): Promise<string | null>;
6
+ /**
7
+ * Why this grant may not be written at `app`, or null. A membership role is granted only in a value of its
8
+ * own scope dimension, never globally. For a contract application a grant also carries no wildcard,
9
+ * inline or through its role, the built-in `admin` included. A cross-app grant (`app` null) is not
10
+ * checked: it never reaches an application token.
11
+ */
12
+ export declare function contractGrantProblem(appSchema: ContractSchema, app: string | null, grant: {
13
+ roleKey: string | null;
14
+ permissions: readonly string[] | null;
15
+ scopeType: string | null;
16
+ }): Promise<string | null>;
17
+ /**
18
+ * Why `principal` may not hold this grant, or null (ADR-0051). An external principal holds only a role of one
19
+ * application that the role's schema declares external: no inline permissions, no cross-app grant, no built-in role and
20
+ * no custom policy. The write carries the same condition (`eligibleGrantSql`); this check names the reason first.
21
+ */
22
+ export declare function externalGrantProblem(appSchema: Pick<AppSchemaRepository, 'getRole'>, principal: Pick<PrincipalRow, 'affiliation'>, app: string | null, grant: {
23
+ roleKey: string | null;
24
+ }): Promise<string | null>;
25
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { Env, RequestContext } from './env';
2
+ /**
3
+ * Retention for the transient tables. `auth_log` and `audit_events` follow the operator's setting
4
+ * (`Config.retention`, `src/retention.ts`): `auth_log` defaults to 30 days, and `audit_events` are kept unless the
5
+ * operator set a retention.
6
+ */
7
+ export declare const PASSWORD_TRANSIENT_RETENTION_SECONDS: number;
8
+ export declare const INVITATION_RETENTION_SECONDS: number;
9
+ /**
10
+ * Prune old auth-log rows, audit rows past an operator's retention, password action tokens, login throttles, spent handoff codes and delegation
11
+ * grants, old invitations, dead sessions and ended terminal identifications. Registered through `waitUntil` because a Worker scheduled
12
+ * handler that returns before its writes settle is cut off; in a process the supervised promise means a
13
+ * failure is logged rather than fatal.
14
+ */
15
+ export declare function runIamMaintenance(env: Env, ctx: RequestContext, now?: number): void;
@@ -0,0 +1,58 @@
1
+ import type { SqlDatabase } from '@fabrika/platform';
2
+ import { PasswordRepository } from './password-db';
3
+ import { AppSchemaRepository } from './repositories/app-schema';
4
+ import { AuditRepository, type SqlDialect } from './repositories/audit';
5
+ import { InstallationBrandRepository } from './repositories/brand';
6
+ import { CredentialRepository } from './repositories/credentials';
7
+ import { DeviceAuthorizationRepository } from './repositories/device';
8
+ import { GrantRepository } from './repositories/grants';
9
+ import { HandoffRepository } from './repositories/handoff';
10
+ import { MembershipRepository } from './repositories/membership';
11
+ import { MembershipTransportKeyRepository } from './repositories/membership-transport';
12
+ import { OAuthRepository } from './repositories/oauth';
13
+ import { PasswordPolicyRepository } from './repositories/password-policy';
14
+ import { PrincipalRepository } from './repositories/principals';
15
+ import { SessionRepository } from './repositories/sessions';
16
+ import { TerminalRepository } from './repositories/terminals';
17
+ import { WorkloadRepository } from './repositories/workloads';
18
+ export { type AppActionRow, type AppMembersRow, AppSchemaRepository, type AppScopeRow, type DelegatedEndpointRow, type LinkMountRow, type RoleRow, } from './repositories/app-schema';
19
+ export { type AuditedChange, type AuditEventInput, type AuditEventRow, auditEventStatement, auditLabelOf, AuditRepository, AuditWriter, type AuthLogInput, type AuthLogKind, type AuthLogRow, authLogStatement, type SqlChange, type SqlDialect, } from './repositories/audit';
20
+ export { type InstallationBrandImages, InstallationBrandRepository, type InstallationBrandRow } from './repositories/brand';
21
+ export { type CredentialGrantRow, CredentialRepository, type CredentialRow } from './repositories/credentials';
22
+ export { DeviceAuthorizationRepository, type DeviceAuthorizationRow, type DeviceReceiptRow } from './repositories/device';
23
+ export { type DelegatedAuthority, ExternalGrantError, GrantRepository, type GrantRow } from './repositories/grants';
24
+ export { type AuthCodeRow, HandoffRepository } from './repositories/handoff';
25
+ export { type DelegationGrantRow, type InvitationAcceptance, type InvitationRow, type InviterCheck, type MemberGrantRow, MembershipRepository, type MembershipRepositoryOptions, type NewPrincipalAcceptance, type NewPrincipalEvents, } from './repositories/membership';
26
+ export { MembershipTransportKeyRepository, type MembershipTransportKeyRow } from './repositories/membership-transport';
27
+ export { type OAuthCodeRow, type OAuthGrantRow, type OAuthRefreshTokenRow, OAuthRepository } from './repositories/oauth';
28
+ export { PasswordPolicyRepository, type PasswordPolicyRow } from './repositories/password-policy';
29
+ export { PrincipalRepository, type PrincipalRow, type PrincipalStatus, principalStatus } from './repositories/principals';
30
+ export { type AuthenticationMethod, SessionRepository, type SessionRow, type SessionTerminal, sessionTerminal } from './repositories/sessions';
31
+ export { DEFAULT_TERMINAL_SESSION_TTL_SECONDS, MAX_TERMINAL_SESSION_TTL_SECONDS, type TerminalAsserter, type TerminalIdentificationRow, type TerminalProfile, TerminalRepository, type TerminalRow, } from './repositories/terminals';
32
+ export { type AppWorkloadRow, type WorkloadPrincipalRow, WorkloadRepository } from './repositories/workloads';
33
+ /** IAM persistence capabilities selected together by a runtime composition root. */
34
+ export interface IamRepositories {
35
+ device: DeviceAuthorizationRepository;
36
+ principals: PrincipalRepository;
37
+ grants: GrantRepository;
38
+ appSchema: AppSchemaRepository;
39
+ credentials: CredentialRepository;
40
+ sessions: SessionRepository;
41
+ passwords: PasswordRepository;
42
+ handoff: HandoffRepository;
43
+ membership: MembershipRepository;
44
+ oauth: OAuthRepository;
45
+ audit: AuditRepository;
46
+ workloads: WorkloadRepository;
47
+ terminals: TerminalRepository;
48
+ membershipTransport: MembershipTransportKeyRepository;
49
+ brand: InstallationBrandRepository;
50
+ passwordPolicy: PasswordPolicyRepository;
51
+ }
52
+ /**
53
+ * The portable repository bundle. A composition root may replace one complete capability. `dialect` picks how a
54
+ * guarded change writes its record (`AuditWriter`); everything else is the same SQL on both engines.
55
+ */
56
+ export declare function createIamRepositories(db: SqlDatabase, replacements?: Partial<IamRepositories>, dialect?: SqlDialect): IamRepositories;
57
+ /** The bundle on Postgres: the same statements, recorded through one statement each, and the acceptance's row lock. */
58
+ export declare function createPostgresIamRepositories(db: SqlDatabase): IamRepositories;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * S8 of the authorization model, shared by issue and mint: a credential one principal delegates to another (a share
3
+ * link, an anonymous key, a service or device key) carries no more than its issuer still holds, and no longer.
4
+ */
5
+ import { type PermissionEntry, type Scope } from '@fabrika/auth-core';
6
+ import type { Services } from './services';
7
+ /** An action the issuer must still hold on at least one of `on` (`null` is application-wide). */
8
+ export interface DelegatedAction {
9
+ action: string;
10
+ on: readonly (Scope | null)[];
11
+ }
12
+ /**
13
+ * S8 at every mint of an anonymous credential: its issuer exists, is enabled and still holds each delegated action, and
14
+ * the token ends when the first of them loses its support. A job issuer holds its current declaration, app-wide, and
15
+ * only for the mount it is declared to issue; the provisioning administrator is the installation's named exception. A credential without an issuer, or whose issuer lost any of it, mints
16
+ * nothing (`issuer_unauthorized`, reported as `invalid_key`).
17
+ */
18
+ export declare function issuerAuthority(services: Services, issuerId: string | null, app: string, mount: string | null, required: readonly DelegatedAction[]): Promise<{
19
+ ok: true;
20
+ expiresAt: number | null;
21
+ } | {
22
+ ok: false;
23
+ reason: 'issuer_unauthorized';
24
+ }>;
25
+ /**
26
+ * A principal-bound key whose issuer is another principal (a service or device key): what the issuer still covers of
27
+ * `permissions` at `app`, and until when. The named exceptions keep the whole set: the provisioning administrator, and
28
+ * an issuer that still holds `iam.admin` (the installation administrator, until its own grant of it ends). A missing
29
+ * or disabled issuer refuses the key.
30
+ */
31
+ export declare function issuerCoverage(services: Services, issuerId: string, app: string, permissions: PermissionEntry[]): Promise<{
32
+ ok: true;
33
+ permissions: PermissionEntry[];
34
+ expiresAt: number | null;
35
+ } | {
36
+ ok: false;
37
+ reason: 'issuer_unauthorized';
38
+ }>;
@@ -0,0 +1,2 @@
1
+ import type { Services } from './services';
2
+ export declare function handleDeviceAuthorization(request: Request, services: Services, clientAddress: string | null, requestId: string): Promise<Response>;
@@ -0,0 +1,11 @@
1
+ import { type ApproveDeviceAuthorizationResult, type CancelDeviceAuthorizationResult, type DenyDeviceAuthorizationResult, type ExchangeDeviceAuthorizationResult, type InspectDeviceAuthorizationResult, type ListOwnDeviceAuthorizationsResult, type PollDeviceAuthorizationResult, type StartDeviceAuthorizationResult } from '@fabrika/auth-core';
2
+ import type { Env } from './env';
3
+ import type { Services } from './services';
4
+ export declare function startDeviceAuthorization(services: Services, raw: unknown, clientAddress: string | null): Promise<StartDeviceAuthorizationResult>;
5
+ export declare function pollDeviceAuthorization(services: Services, raw: unknown): Promise<PollDeviceAuthorizationResult>;
6
+ export declare function cancelDeviceAuthorization(services: Services, raw: unknown): Promise<CancelDeviceAuthorizationResult>;
7
+ export declare function inspectDeviceAuthorization(services: Services, env: Env, raw: unknown): Promise<InspectDeviceAuthorizationResult>;
8
+ export declare function approveDeviceAuthorization(services: Services, env: Env, raw: unknown): Promise<ApproveDeviceAuthorizationResult>;
9
+ export declare function denyDeviceAuthorization(services: Services, env: Env, raw: unknown): Promise<DenyDeviceAuthorizationResult>;
10
+ export declare function listOwnDeviceAuthorizations(services: Services, env: Env, raw: unknown): Promise<ListOwnDeviceAuthorizationsResult>;
11
+ export declare function exchangeDeviceAuthorization(services: Services, raw: unknown, requestId: string): Promise<ExchangeDeviceAuthorizationResult>;
@@ -0,0 +1 @@
1
+ export { normalizeEmailIdentity } from '@fabrika/auth-core';
@@ -0,0 +1,127 @@
1
+ import type { EmailEnvironment, EmailProviderRegistry, EmailSender } from '@fabrika/email';
2
+ import type { SqlDatabase, WaitUntil } from '@fabrika/platform';
3
+ import type { IamRepositories } from './db';
4
+ import type { Pbkdf2Cost } from './password-crypto';
5
+ /**
6
+ * The IAM service's runtime surface: its two capability handles plus vars/secrets. Single source of
7
+ * truth — every other file imports from here, never re-declares the shape. JSON-typed vars
8
+ * (`HUMAN_EMAIL_DOMAINS`, `HUMAN_EMAILS`, `IAM_BOOTSTRAP_ADMINS`) are parsed once in `buildServices`.
9
+ *
10
+ * `DB` is a runtime port, not a Cloudflare binding, which lets one `Env` serve both entrypoints:
11
+ * on Workers a real `D1Database` satisfies it structurally, and the Bun entrypoint fills it with
12
+ * `PostgresDatabase`. Everything else here is a plain string, so it comes equally from `wrangler`
13
+ * vars or from `process.env`.
14
+ */
15
+ export interface Env {
16
+ /** Both policy tables and append-only audit tables (one database). D1 on Workers, Postgres on Bun. */
17
+ DB: SqlDatabase;
18
+ /** Persistence capabilities selected by this runtime's composition root. */
19
+ REPOSITORIES: IamRepositories;
20
+ /**
21
+ * JSON array of email domains admitted as a HUMAN at login (e.g. `["example.com","contember.com"]`).
22
+ * A `*` entry means admit anyone. IAM owns this centrally — the login-admission allowlist for
23
+ * self-provisioning a new identity. Consumed by `/auth/callback`.
24
+ */
25
+ HUMAN_EMAIL_DOMAINS: string;
26
+ /** JSON array of specific emails admitted as a HUMAN, in ADDITION to the domains (a `*` = admit-all). */
27
+ HUMAN_EMAILS: string;
28
+ /** JSON array of bootstrap-admin emails (normally empty). Always admitted; resolution-time only. */
29
+ IAM_BOOTSTRAP_ADMINS: string;
30
+ /**
31
+ * Comma-separated app ids whose proxy-injected access token may administer `/admin/*` — the
32
+ * console gateway, and nothing else. Deploy var `FABRIKA_IAM_ADMIN_AUDIENCES`. Unset means the
33
+ * console's own app id; an explicitly empty value means no JWT may administer at all.
34
+ *
35
+ * A REGISTRY because every application in the installation receives the administrator's token in
36
+ * cleartext, so without a named audience any of them could replay it here.
37
+ */
38
+ ADMIN_AUDIENCES?: string;
39
+ /**
40
+ * JSON: the OAuth 2.1 authorization server for MCP clients (`src/oauth-config.ts`). Absent or empty
41
+ * means OAuth is off and its routes 404. Deploy var `FABRIKA_IAM_OAUTH_CONFIG`. Malformed fails the boot.
42
+ */
43
+ OAUTH_CONFIG?: string;
44
+ /**
45
+ * Days the maintenance cron keeps `auth_log` rows; unset means 30. Deploy var
46
+ * `FABRIKA_IAM_AUTH_LOG_RETENTION_DAYS`. A value that is not a whole number of days fails the boot.
47
+ */
48
+ AUTH_LOG_RETENTION_DAYS?: string;
49
+ /**
50
+ * Days the maintenance cron keeps `audit_events` rows; unset keeps them all. Deploy var
51
+ * `FABRIKA_IAM_AUDIT_RETENTION_DAYS`. A value that is not a whole number of days fails the boot.
52
+ */
53
+ AUDIT_RETENTION_DAYS?: string;
54
+ /** `local` / `stage` / `prod`. */
55
+ ENVIRONMENT: string;
56
+ /** Explicit local-only human login bypass. Ignored unless `ENVIRONMENT=local`. */
57
+ LOCAL_DEV_LOGIN?: string;
58
+ /** Independent authentication-method switches. Absent preserves the legacy OIDC-only mode. */
59
+ OIDC_ENABLED?: string;
60
+ PASSWORD_ENABLED?: string;
61
+ /** The installation's `FABRIKA_EMAIL_*` variables. An absent or `none` provider disables delivery. */
62
+ EMAIL_CONFIG?: EmailEnvironment;
63
+ /** The providers `FABRIKA_EMAIL_PROVIDER` may name. Absent is an empty registry, which admits only `none`. */
64
+ EMAIL_PROVIDERS?: EmailProviderRegistry;
65
+ /**
66
+ * A sender the composition root supplies in place of a configured provider: the local stack's mail capture. A port,
67
+ * not a variable, and refused by `buildServices` outside `ENVIRONMENT=local` or beside a configured provider.
68
+ */
69
+ EMAIL_SENDER?: EmailSender;
70
+ /**
71
+ * The platform mail relay's sender: both compositions build it from `FABRIKA_CONTROL_URL` and the secret IAM's relay
72
+ * key derives from. `buildServices` sends through it while a provider is configured, and with that provider only when
73
+ * the relay refuses a message for good (`relayWithFallback`). Control then delivers through its own transport.
74
+ */
75
+ PLATFORM_EMAIL_SENDER?: EmailSender;
76
+ /**
77
+ * The PBKDF2 cost this runtime can derive: a port the composition root sets, not a variable. Absent is the Bun cost,
78
+ * which production Workers refuse, so every Worker composition must pass `WORKERS_PBKDF2_COST`.
79
+ */
80
+ PASSWORD_COST?: Pbkdf2Cost;
81
+ /**
82
+ * IAM's OWN origin, e.g. `https://iam.example.com` — the `iss` of every minted
83
+ * token AND the base for the OIDC redirect URI. Derived from `FABRIKA_IAM_HOSTNAME` at
84
+ * deploy time; a localhost value locally.
85
+ */
86
+ ISSUER: string;
87
+ /**
88
+ * **Secret.** JSON array of ES256 (EC P-256) PRIVATE JWKs. Index 0 is the active signer; all are
89
+ * published in the JWKS so a rotation key verifies before it signs. Empty locally → an ephemeral
90
+ * key is generated per isolate (dev only). Never placed in `vars` — provisioned as a Worker secret
91
+ * (`wrangler secret put` remote / `.dev.vars` local).
92
+ */
93
+ FABRIKA_IAM_SIGNING_KEYS: string;
94
+ /**
95
+ * **Secret.** A single operator-generated provisioning `px_` key, or empty to disable (the default).
96
+ * Held ONLY here — never in the DB. A bearer whose hash matches it resolves a synthetic global-admin
97
+ * in `resolveCaller` (the machine analog of `IAM_BOOTSTRAP_ADMINS`): it lets a control plane bootstrap
98
+ * itself — reconcile app schemas / issue the first admin key — before any DB-backed admin credential
99
+ * exists. Provisioned as a Worker secret (`wrangler secret put` remote / `.dev.vars` local), never in
100
+ * `vars`. Rotate by changing the env value.
101
+ */
102
+ FABRIKA_IAM_PROVISIONING_KEY: string;
103
+ /**
104
+ * OIDC provider issuer URL (e.g. `https://accounts.google.com`, an Auth0/Okta/Keycloak/Entra
105
+ * tenant). IAM discovers the endpoints from `${OIDC_ISSUER}/.well-known/openid-configuration`
106
+ * — so ANY OIDC provider works via config, no per-provider code.
107
+ */
108
+ OIDC_ISSUER?: string;
109
+ /** OIDC client id (public). The SSO upstream — IAM federates here for human login. */
110
+ OIDC_CLIENT_ID?: string;
111
+ /** **Secret.** OIDC client secret (the code-exchange credential). */
112
+ OIDC_CLIENT_SECRET?: string;
113
+ /** Space-separated OIDC scopes; empty → `openid email profile`. */
114
+ OIDC_SCOPES?: string;
115
+ /** `'false'` to accept logins whose `email_verified` claim is absent (an IdP that omits it); else verified is required. */
116
+ OIDC_REQUIRE_VERIFIED_EMAIL?: string;
117
+ }
118
+ /**
119
+ * The slice of a request's runtime context the service actually uses: keeping work alive past the
120
+ * response. Deliberately NOT `ExecutionContext` — that type only exists on Workers, and a handler
121
+ * typed against it could not be called from a Bun process without inventing the rest of it. A real
122
+ * `ExecutionContext` satisfies this structurally, so the Worker entrypoint passes `this.ctx`
123
+ * unchanged; the Bun entrypoint passes `createBackgroundTasks()` from `@fabrika/platform-node`.
124
+ */
125
+ export interface RequestContext {
126
+ readonly waitUntil: WaitUntil;
127
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Cross-host session handoff ([ADR-0022](../../../docs/decisions/0022-the-proxy-is-the-only-enforcement-point.md)).
3
+ *
4
+ * IAM authenticates on ITS host and the app lives on another, where no cookie of IAM's can be read.
5
+ * So IAM issues a single-use code bound to `(session, app, return URL)`, the browser carries it to
6
+ * the app's own host, and the proxy there redeems it for an app-bound child session it CAN set.
7
+ *
8
+ * Two rules carry the security of the whole exchange:
9
+ *
10
+ * 1. **A return URL is validated against the app's registered origins, never trusted.** Whoever
11
+ * can ask for a code decides where the browser goes next, so an unregistered origin is refused
12
+ * outright — not quietly rewritten to the issuer, which would hide a misconfiguration behind a
13
+ * redirect loop.
14
+ * 2. **The child session is bound to one app.** The cookie is host-only, so another app cannot
15
+ * read it; the binding is the second lock, so a value that leaks anyway cannot buy a token for
16
+ * anything else (`mintToken` enforces it).
17
+ */
18
+ import { type ExchangeAuthCodeInput, type ExchangeAuthCodeResult } from '@fabrika/auth-core';
19
+ import { type SessionTerminal } from './db';
20
+ import { normalizeOrigin } from './origin';
21
+ import type { Services } from './services';
22
+ /** An issued code and when it dies. The plaintext is returned once and never stored. */
23
+ export interface IssuedAuthCode {
24
+ code: string;
25
+ expiresAt: number;
26
+ }
27
+ export { normalizeOrigin };
28
+ /**
29
+ * Check a proposed return URL against the app's registered origins and return it normalized, or null.
30
+ *
31
+ * The whole URL is rebuilt from its parts rather than echoed: the stored value is what a later
32
+ * redemption redirects the browser to, and reconstructing it means a caller cannot smuggle anything
33
+ * past the origin check in a component we never looked at.
34
+ */
35
+ export declare function resolveReturnUrl(services: Services, app: string, rawUrl: string): Promise<string | null>;
36
+ /** Issue a single-use code for a validated return URL. */
37
+ export declare function issueAuthCode(services: Services, input: {
38
+ app: string;
39
+ parentSessionId: string;
40
+ returnUrl: string;
41
+ challenge: string;
42
+ }): Promise<IssuedAuthCode>;
43
+ /** The principal and the login's terminal are surfaced so the caller can write the `auth_log` row of a refusal. */
44
+ export interface ExchangeOutcome {
45
+ result: ExchangeAuthCodeResult;
46
+ principalId: string | null;
47
+ terminal: SessionTerminal | null;
48
+ }
49
+ /**
50
+ * Redeem a code for an app-bound child session. Consumption is atomic and happens FIRST: a code that
51
+ * fails any later check is still spent, because a code that survives a failed redemption is a code an
52
+ * attacker can keep trying.
53
+ *
54
+ * The child inherits the parent's absolute expiry, so an app session can never outlive the login it
55
+ * came from, and `getActiveSessionByHash` re-checks the parent on every use so revocation reaches it.
56
+ */
57
+ export declare function exchangeAuthCode(services: Services, input: ExchangeAuthCodeInput): Promise<ExchangeOutcome>;
@@ -0,0 +1,2 @@
1
+ /** Escape a value for HTML text and a quoted attribute. Every value a page or an e-mail inserts passes through it. */
2
+ export declare function escapeHtml(value: string): string;
@@ -0,0 +1,22 @@
1
+ import type { Config } from './services';
2
+ /**
3
+ * Whether the installation names `email` as one of the organization's own: a bootstrap admin, an exact entry of
4
+ * `HUMAN_EMAILS`, or an address in a `HUMAN_EMAIL_DOMAINS` domain. A `*` entry names nobody: it admits everyone, and
5
+ * is no statement about who belongs to the organization. IAM never creates such a mailbox as an external principal.
6
+ */
7
+ export declare function organizationMailbox(email: string, config: Pick<Config, 'human' | 'bootstrapAdmins'>): boolean;
8
+ /**
9
+ * The human-admission allowlist for self-provisioning a brand-new identity. IAM owns this
10
+ * centrally (the deploy vars `FABRIKA_IAM_HUMAN_EMAIL_DOMAINS` / `FABRIKA_IAM_HUMAN_EMAILS`):
11
+ * - a `*` entry in EITHER list = admit anyone (allow-all);
12
+ * - an exact email match in `emails`;
13
+ * - the email's domain in `emailDomains` (case-insensitive);
14
+ * - a bootstrap admin.
15
+ * Returns false otherwise — an empty allowlist with no `*` means only known/invited principals and
16
+ * bootstrap admins may log in (fail-closed). Matching uses ONLY the IdP-verified email.
17
+ *
18
+ * Both sides of every comparison are normalized. Entra and Okta both preserve directory casing, so a
19
+ * `FABRIKA_IAM_HUMAN_EMAILS` entry spelled `Vip@Example.com` used to be a control that simply never
20
+ * matched, with nothing said about it either way.
21
+ */
22
+ export declare function admitted(email: string, config: Pick<Config, 'human' | 'bootstrapAdmins'>): boolean;
@@ -0,0 +1,30 @@
1
+ import { type AssertIdentityInput, type AssertIdentityResult, type CancelIdentificationInput, type CancelIdentificationResult, type InspectIdentificationInput, type InspectIdentificationResult } from '@fabrika/auth-core';
2
+ import { type SessionTerminal } from './db';
3
+ import type { Env } from './env';
4
+ import type { Services } from './services';
5
+ /** How long the person at a terminal has to identify before the sign-in starts over. */
6
+ export declare const IDENTIFICATION_TTL_SECONDS = 120;
7
+ /** How long the terminal's browser has, after an assertion, to complete the identification at IAM. */
8
+ export declare const COMPLETION_TTL_SECONDS = 60;
9
+ /** Where an application sends the terminal's browser after its assertion; IAM issues the code there. */
10
+ export declare const TERMINAL_COMPLETE_PATH = "/auth/terminals/complete";
11
+ type CallerEnv = Pick<Env, 'FABRIKA_IAM_SIGNING_KEYS' | 'ENVIRONMENT'>;
12
+ /** The terminal an open identification belongs to and when it expires; the application keys its throttle on the terminal. */
13
+ export declare function inspectIdentification(services: Services, env: CallerEnv, input: InspectIdentificationInput): Promise<InspectIdentificationResult>;
14
+ /** The answer of an assertion, with the principal and terminal its `auth_log` row of a refusal names. */
15
+ export interface AssertOutcome {
16
+ result: AssertIdentityResult;
17
+ principalId: string | null;
18
+ terminal: SessionTerminal | null;
19
+ }
20
+ /**
21
+ * The application's word that `principalId` stands at the identification's terminal. In one batch, IAM consumes the
22
+ * identification and opens a login for the person that no browser holds (the parent of the application session), with
23
+ * its `auth_log` row. It answers IAM's completion URL, never a code: only the terminal's own browser completes the
24
+ * identification there, and only then does IAM issue the code of the handoff the identification carries. A refused
25
+ * principal leaves the identification open, so the person can try again within its two minutes.
26
+ */
27
+ export declare function assertIdentity(services: Services, env: CallerEnv, input: AssertIdentityInput): Promise<AssertOutcome>;
28
+ /** End an identification of the asking application that the person abandoned. */
29
+ export declare function cancelIdentification(services: Services, env: CallerEnv, input: CancelIdentificationInput): Promise<CancelIdentificationResult>;
30
+ export {};