@fabrika/iam 0.0.0-stage → 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 +70 -5
  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,26 @@
1
+ import { type ApiKeyDetail, type ApiKeyIdInput, type CursorList, type ListApiKeysInput, type OkResponse, type ProvisionApiKeyRequest, type ProvisionApiKeyResponse, type RotateApiKeyInput, type RotateApiKeyResponse } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ /**
4
+ * One page of service principals with their grants and live credentials. THREE queries per page, whatever the page
5
+ * holds: the roster read, then one grants read and one credentials read for the page's ids. It used to be 1+N over an unbounded
6
+ * roster, with no pagination at all (SEC-22).
7
+ */
8
+ export declare function listApiKeysUseCase(c: AdminContext, input: ListApiKeysInput): Promise<CursorList<ApiKeyDetail>>;
9
+ /** One key with its grants and its live credential, for the console's key page. */
10
+ export declare function getApiKeyUseCase(c: AdminContext, input: ApiKeyIdInput): Promise<ApiKeyDetail>;
11
+ export declare function provisionApiKeyUseCase(c: AdminContext, input: ProvisionApiKeyRequest): Promise<ProvisionApiKeyResponse>;
12
+ export declare function revokeApiKeyUseCase(c: AdminContext, input: {
13
+ principalId: string;
14
+ }): Promise<OkResponse>;
15
+ /**
16
+ * Rotate: same principal, same grants, new secret. Effective immediately.
17
+ *
18
+ * Two things the old implementation got wrong. It DROPPED the credential's expiry — a key provisioned
19
+ * to die in 30 days came back immortal, and an operator rotating a key on schedule was quietly
20
+ * removing its bound (CORR-5); the replacement carries the old expiry forward unless the caller states
21
+ * a new one, and a stated one must be in the future exactly as provisioning requires. And it rotated a
22
+ * DISABLED principal's key, handing out a working secret for an account somebody had just revoked —
23
+ * the same guard `passwordUser` already applies.
24
+ */
25
+ export declare function rotateApiKeyUseCase(c: AdminContext, input: RotateApiKeyInput): Promise<RotateApiKeyResponse>;
26
+ export declare function parseProvisionApiKeyRequest(body: unknown): ProvisionApiKeyRequest;
@@ -0,0 +1,8 @@
1
+ import type { AdministeredAppDto, AppPeopleDto, AppPeopleInput, GrantAppRoleRequest, GrantAppRoleResponse, RevokeAppRoleRequest, RevokeAppRoleResponse } from '@fabrika/iam-contract';
2
+ import type { IamAppContext } from '../app';
3
+ export declare function listAdministeredApps(ctx: IamAppContext): Promise<{
4
+ items: AdministeredAppDto[];
5
+ }>;
6
+ export declare function listAppPeople(ctx: IamAppContext, input: AppPeopleInput): Promise<AppPeopleDto>;
7
+ export declare function grantAppRole(ctx: IamAppContext, input: GrantAppRoleRequest): Promise<GrantAppRoleResponse>;
8
+ export declare function revokeAppRole(ctx: IamAppContext, input: RevokeAppRoleRequest): Promise<RevokeAppRoleResponse>;
@@ -0,0 +1,32 @@
1
+ import { type AppDto, type AppInput, type AppSchemaDto, type ListRolesInput, type ReturnOriginsDto, type RoleDto, type SetReturnOriginsRequest } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ /** The app ids a grant can be scoped to — the apps that have registered a vocabulary — with their display names. */
4
+ export declare function listAppsUseCase(c: AdminContext): Promise<{
5
+ items: AppDto[];
6
+ }>;
7
+ /**
8
+ * The roles available to grant for an app: the built-ins (cross-app, e.g. `admin`)
9
+ * plus the app's DB roles (origin 'app' + 'custom'). Without an app, only built-ins are
10
+ * listed. Built-ins win on a key collision so an app cannot shadow the cross-app `admin`.
11
+ */
12
+ export declare function listRolesUseCase(c: AdminContext, input: ListRolesInput): Promise<{
13
+ items: RoleDto[];
14
+ }>;
15
+ /**
16
+ * Reconcile an app's declared vocabulary (idempotent): upsert its scopes/actions and
17
+ * origin='app' roles, delete app-origin rows absent from the body, and NEVER touch
18
+ * origin='custom' roles. Every role's patterns are validated against the body's own
19
+ * action catalog. The `:app` path segment is the app id this vocabulary belongs to.
20
+ */
21
+ export declare function putAppSchema(c: AdminContext, app: string): Promise<Response>;
22
+ /**
23
+ * Replace an app's registered return origins (ADR-0022). Every value is canonicalized before it is
24
+ * stored, so the comparison at issue time is against one spelling and an operator cannot register
25
+ * `https://App.Example.com/` and then wonder why `https://app.example.com` is refused.
26
+ *
27
+ * The app is validated FIRST, so a typo in the app id is reported as a typo in the app id rather than
28
+ * as an origin problem. An EMPTY set is refused as a caller error: it is indistinguishable from an
29
+ * app that never registered, and reaching that state through this endpoint is always a mistake.
30
+ */
31
+ export declare function setReturnOriginsUseCase(c: AdminContext, input: SetReturnOriginsRequest): Promise<ReturnOriginsDto>;
32
+ export declare function getAppSchemaUseCase(c: AdminContext, input: AppInput): Promise<AppSchemaDto>;
@@ -0,0 +1,10 @@
1
+ import { type AuditEventDto, type AuthLogDto, type ListAuditInput, type ListAuthLogInput } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ export declare function listAuditUseCase(c: AdminContext, input: ListAuditInput): Promise<{
4
+ items: AuditEventDto[];
5
+ nextCursor: string | null;
6
+ }>;
7
+ export declare function listAuthLogUseCase(c: AdminContext, input: ListAuthLogInput): Promise<{
8
+ items: AuthLogDto[];
9
+ nextCursor: string | null;
10
+ }>;
@@ -0,0 +1,10 @@
1
+ import type { InstallationBrandDto, SetInstallationBrandRequest } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ export declare function getInstallationBrandUseCase(c: AdminContext): Promise<InstallationBrandDto>;
4
+ /**
5
+ * Store the brand, checked here again whatever the console checked: every reader trusts what IAM stored no more than
6
+ * this, and checks it again too. The record names the types of the images it stored, never their bytes.
7
+ */
8
+ export declare function setInstallationBrandUseCase(c: AdminContext, input: SetInstallationBrandRequest): Promise<InstallationBrandDto>;
9
+ /** Clear the brand, so every page draws the fabrika mark again. Clearing an absent brand changes and records nothing. */
10
+ export declare function clearInstallationBrandUseCase(c: AdminContext): Promise<InstallationBrandDto>;
@@ -0,0 +1,5 @@
1
+ import type { CursorList, GrantIdInput, ListSessionsInput, OkResponse, UserConnectionDto } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ /** OAuth consents are installation administration, like the audit and credentials pages. */
4
+ export declare function listConnections(c: AdminContext, input: ListSessionsInput): Promise<CursorList<UserConnectionDto>>;
5
+ export declare function revokeConnection(c: AdminContext, input: GrantIdInput): Promise<OkResponse>;
@@ -0,0 +1,46 @@
1
+ import { type PermissionEntry, type PrincipalType } from '@fabrika/auth-core';
2
+ import { type AuditEventInput } from '../db';
3
+ import { type RequestContext } from '../env';
4
+ import { type Services } from '../services';
5
+ import { type Administration } from './user-admin';
6
+ /**
7
+ * Context every admin handler receives: the resolved admin caller (already gated on its administration), the
8
+ * request, parsed URL, and the verified app id for audit labeling.
9
+ */
10
+ export interface AdminContext {
11
+ services: Services;
12
+ request: Request;
13
+ url: URL;
14
+ /** The resolved admin caller (already gated on its administration). `label` is null for a label-less key. */
15
+ admin: {
16
+ id: string;
17
+ type: PrincipalType;
18
+ label: string | null;
19
+ permissions: PermissionEntry[];
20
+ };
21
+ /** The installation, or the people of some applications (ADR-0058); every user-admin rule reads it. */
22
+ administration: Administration;
23
+ /** IAM's own app id — the audience the admin was resolved against; used for audit labeling. */
24
+ app: string;
25
+ /** Correlation id supplied by the proxy/edge or generated at IAM. */
26
+ requestId: string;
27
+ ctx: RequestContext;
28
+ }
29
+ /** Structural domain failure shared by REST adapters and the RPC dispatcher. */
30
+ export declare class AdminUseCaseError extends Error {
31
+ readonly httpStatus: number;
32
+ readonly type: string;
33
+ constructor(httpStatus: number, message: string);
34
+ }
35
+ export declare function fail(status: number, message: string): never;
36
+ /**
37
+ * The record of a change the admin made. A use case hands it to the repository that makes the change, which writes it
38
+ * in the change's own transaction, so a committed change always has its row and a failed write fails the change.
39
+ */
40
+ export declare function adminEvent(c: AdminContext, event: {
41
+ action: string;
42
+ resourceType: string;
43
+ resourceId?: string | null;
44
+ diff?: unknown;
45
+ metadata?: unknown;
46
+ }): AuditEventInput;
@@ -0,0 +1,59 @@
1
+ import { type RoleDef } from '@fabrika/auth-core';
2
+ import { type CreateGrantRequest, type GrantDto } from '@fabrika/iam-contract';
3
+ import { type GrantRow, type RoleRow } from '../db';
4
+ import { type Services } from '../services';
5
+ import { type AdminContext } from './context';
6
+ /** Parse a `roles` row's JSON permissions into a string array (fail-closed on junk, incl. unparseable text). */
7
+ export declare function rolePermissions(json: string): string[];
8
+ /**
9
+ * Loads (and memoizes) an app's role_key set on demand so DTO mappers can flag
10
+ * dangling role grants without re-querying per row. A grant/mapping with `app = null`
11
+ * (cross-app) is checked against the built-ins only — there is no per-app row set.
12
+ */
13
+ export declare class RoleKnownCache {
14
+ private readonly services;
15
+ private readonly perApp;
16
+ constructor(services: Services);
17
+ private appRoleKeys;
18
+ /** True iff `roleKey` resolves for `app` — a built-in, or a row in the app's roles. */
19
+ isKnown(roleKey: string, app: string | null): Promise<boolean>;
20
+ }
21
+ export declare function toGrantDto(row: GrantRow, roleCache: RoleKnownCache): Promise<GrantDto>;
22
+ /** Map a list of grant rows to DTOs sharing one role-known cache (one query per app). */
23
+ export declare function toGrantDtos(rows: GrantRow[], services: Services, cache?: RoleKnownCache): Promise<GrantDto[]>;
24
+ /** The set of app ids IAM knows about — the live registry derived from the schema tables. */
25
+ export declare function knownApps(c: AdminContext): Promise<string[]>;
26
+ /** Validate an admin-supplied `app`: null (all apps) or a known (registered) app. */
27
+ export declare function appField(c: AdminContext, body: Pick<CreateGrantRequest, 'app'>): Promise<{
28
+ ok: true;
29
+ app: string | null;
30
+ } | {
31
+ ok: false;
32
+ }>;
33
+ /** A `roles` row → core `RoleDef` for resolution. */
34
+ export declare function dbRoleToDef(row: RoleRow): RoleDef;
35
+ /**
36
+ * Validate the scope coordinate on a grant/key request: `scopeType`/`scopeValue` are
37
+ * both-or-neither (both null = global). A half-set pair is a 400.
38
+ */
39
+ export declare function parseScope(body: Pick<CreateGrantRequest, 'scopeType' | 'scopeValue'>): {
40
+ ok: true;
41
+ scopeType: string | null;
42
+ scopeValue: string | null;
43
+ } | {
44
+ ok: false;
45
+ };
46
+ /**
47
+ * Validate the role-or-inline choice for a grant/key against the app: EXACTLY one of
48
+ * `roleKey` / `permissions`. A `roleKey` must be a known role for the app (built-in
49
+ * `admin` OR a `roles` row). Inline `permissions` must each be a pattern the relevant
50
+ * action catalog knows. Returns a normalized result or an error message for a 400.
51
+ */
52
+ export declare function parseRoleOrInline(c: AdminContext, body: Pick<CreateGrantRequest, 'roleKey' | 'permissions'>, app: string | null): Promise<{
53
+ ok: true;
54
+ roleKey: string | null;
55
+ permissions: string[] | null;
56
+ } | {
57
+ ok: false;
58
+ message: string;
59
+ }>;
@@ -0,0 +1,8 @@
1
+ import { type CreateGrantRequest, type GrantDto, type OkResponse, type UpdateGrantInput } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ export declare function createGrantUseCase(c: AdminContext, input: CreateGrantRequest): Promise<GrantDto>;
4
+ export declare function deleteGrantUseCase(c: AdminContext, input: {
5
+ id: string;
6
+ }): Promise<OkResponse>;
7
+ /** Edit a grant in place within its original application. Both paths use the same role, scope and external-person rules. */
8
+ export declare function updateGrantUseCase(c: AdminContext, input: UpdateGrantInput): Promise<GrantDto>;
@@ -0,0 +1,82 @@
1
+ import { getApiKeyUseCase, listApiKeysUseCase, provisionApiKeyUseCase, revokeApiKeyUseCase, rotateApiKeyUseCase } from './api-keys';
2
+ import { getAppSchemaUseCase, listAppsUseCase, listRolesUseCase, setReturnOriginsUseCase } from './app-schema';
3
+ import { listAuditUseCase, listAuthLogUseCase } from './audit';
4
+ import { clearInstallationBrandUseCase, getInstallationBrandUseCase, setInstallationBrandUseCase } from './brand';
5
+ import { type AdminContext } from './context';
6
+ import { createGrantUseCase, deleteGrantUseCase, updateGrantUseCase } from './grants';
7
+ import { issueMembershipKeyUseCase } from './membership-keys';
8
+ import { getPasswordPolicyUseCase, setPasswordPolicyUseCase } from './password-policy';
9
+ import { disablePasswordUseCase, issuePasswordEnrollmentUseCase, issuePasswordResetUseCase } from './passwords';
10
+ import { createPolicyUseCase, deletePolicyUseCase, listPoliciesUseCase, updatePolicyUseCase } from './policies';
11
+ import { getPrincipalUseCase, invitePrincipalUseCase, listPrincipalsUseCase, me, promotePrincipalUseCase, updatePrincipalUseCase } from './principals';
12
+ import { listSessionsUseCase, revokeSessionsForPrincipalUseCase, revokeSessionUseCase } from './sessions';
13
+ import { createShareLinkUseCase, listShareLinksUseCase, revokeShareLinkUseCase } from './share-links';
14
+ import { listTerminalsUseCase, revokeTerminalUseCase, setTerminalProfileUseCase } from './terminals';
15
+ import { issueWorkloadKeyUseCase, revokeWorkloadKeysUseCase } from './workloads';
16
+ /** Return the app's scopes, actions, and origin='app' roles (the reconciled vocabulary). */
17
+ export declare function getAppSchema(c: AdminContext, app: string): Promise<Response>;
18
+ /**
19
+ * Provision an API key: create a native service principal + grant and mint a `px_`
20
+ * credential bound to it — resolved by the IAM-native path (`mintFromKey`), no
21
+ * Cloudflare Access in front. The plaintext `px_` token is returned ONCE.
22
+ *
23
+ * There is no distributed transaction; the writes are local D1 (principal → grant →
24
+ * credential). A failure partway leaves an orphan principal at worst — harmless (it
25
+ * holds no live credential) and revocable from this page.
26
+ */
27
+ export declare function provisionApiKey(c: AdminContext): Promise<Response>;
28
+ /**
29
+ * Revoke an API key: hard-delete its grants, soft-disable the service principal, and
30
+ * revoke its `px_` credentials so they stop minting immediately. Revocation is
31
+ * effective at once — `mintFromKey` re-resolves the credential on every mint.
32
+ */
33
+ export declare function revokeApiKey(c: AdminContext, principalId: string): Promise<Response>;
34
+ /** The typed application operations. `/admin/rpc` serves all of them; REST serves four. */
35
+ export declare const adminUseCases: {
36
+ me: typeof me;
37
+ listPrincipals: typeof listPrincipalsUseCase;
38
+ getPrincipal: typeof getPrincipalUseCase;
39
+ invitePrincipal: typeof invitePrincipalUseCase;
40
+ updatePrincipal: typeof updatePrincipalUseCase;
41
+ promotePrincipal: typeof promotePrincipalUseCase;
42
+ listSessions: typeof listSessionsUseCase;
43
+ revokeSession: typeof revokeSessionUseCase;
44
+ revokeSessionsForPrincipal: typeof revokeSessionsForPrincipalUseCase;
45
+ issuePasswordEnrollment: typeof issuePasswordEnrollmentUseCase;
46
+ issuePasswordReset: typeof issuePasswordResetUseCase;
47
+ disablePassword: typeof disablePasswordUseCase;
48
+ createGrant: typeof createGrantUseCase;
49
+ updateGrant: typeof updateGrantUseCase;
50
+ deleteGrant: typeof deleteGrantUseCase;
51
+ listApps: typeof listAppsUseCase;
52
+ listRoles: typeof listRolesUseCase;
53
+ getAppSchema: typeof getAppSchemaUseCase;
54
+ setReturnOrigins: typeof setReturnOriginsUseCase;
55
+ listPolicies: typeof listPoliciesUseCase;
56
+ createPolicy: typeof createPolicyUseCase;
57
+ updatePolicy: typeof updatePolicyUseCase;
58
+ deletePolicy: typeof deletePolicyUseCase;
59
+ listApiKeys: typeof listApiKeysUseCase;
60
+ getApiKey: typeof getApiKeyUseCase;
61
+ provisionApiKey: typeof provisionApiKeyUseCase;
62
+ rotateApiKey: typeof rotateApiKeyUseCase;
63
+ revokeApiKey: typeof revokeApiKeyUseCase;
64
+ listShareLinks: typeof listShareLinksUseCase;
65
+ createShareLink: typeof createShareLinkUseCase;
66
+ revokeShareLink: typeof revokeShareLinkUseCase;
67
+ listAudit: typeof listAuditUseCase;
68
+ listAuthLog: typeof listAuthLogUseCase;
69
+ issueWorkloadKey: typeof issueWorkloadKeyUseCase;
70
+ revokeWorkloadKeys: typeof revokeWorkloadKeysUseCase;
71
+ issueMembershipKey: typeof issueMembershipKeyUseCase;
72
+ getInstallationBrand: typeof getInstallationBrandUseCase;
73
+ setInstallationBrand: typeof setInstallationBrandUseCase;
74
+ clearInstallationBrand: typeof clearInstallationBrandUseCase;
75
+ getPasswordPolicy: typeof getPasswordPolicyUseCase;
76
+ setPasswordPolicy: typeof setPasswordPolicyUseCase;
77
+ listTerminals: typeof listTerminalsUseCase;
78
+ setTerminalProfile: typeof setTerminalProfileUseCase;
79
+ revokeTerminal: typeof revokeTerminalUseCase;
80
+ };
81
+ export { putAppSchema } from './app-schema';
82
+ export { type AdminContext, AdminUseCaseError } from './context';
@@ -0,0 +1,9 @@
1
+ /** JSON response helper for the admin API. */
2
+ export declare function json(body: unknown, init?: ResponseInit): Response;
3
+ /** A structured JSON error with an HTTP status. */
4
+ export declare function error(status: number, message: string): Response;
5
+ /**
6
+ * Parse a JSON request body as `unknown` (undefined on parse failure). Callers
7
+ * narrow fields with the readers in `../json` — no `as` casts on untrusted input.
8
+ */
9
+ export declare function readJson(request: Request): Promise<unknown>;
@@ -0,0 +1,8 @@
1
+ import type { IssueMembershipKeyRequest, IssueMembershipKeyResponse } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ /**
4
+ * Issue a fresh membership transport key for one application environment (`src/membership-http.ts`). The key the caller
5
+ * recorded as active (`keep`) stays valid, so the version still running keeps working until the caller has recorded the
6
+ * new one; every other key of the environment is an orphan of an attempt whose record failed, and is deleted.
7
+ */
8
+ export declare function issueMembershipKeyUseCase(c: AdminContext, input: IssueMembershipKeyRequest): Promise<IssueMembershipKeyResponse>;
@@ -0,0 +1,5 @@
1
+ /** Group rows by a key, preserving order — how a single page-wide query becomes per-row lists. */
2
+ export declare function groupBy<T>(rows: readonly T[], key: (row: T) => string): Map<string, T[]>;
3
+ /** The `before` value for the next page, or null when this page is the last one. */
4
+ export declare function cursorOf<T>(items: readonly T[], limit: number, id: (item: T) => string): string | null;
5
+ export declare function normalizeLimit(limit: number | undefined): number;
@@ -0,0 +1,9 @@
1
+ import { type PasswordPolicyDto, type SetPasswordPolicyRequest } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ export declare function getPasswordPolicyUseCase(c: AdminContext): Promise<PasswordPolicyDto>;
4
+ /**
5
+ * Store the minimum, held here to this runtime's floor whatever the console checked. It applies to the next password
6
+ * chosen; a stored verifier is never re-judged, so raising it asks nobody to change a password and lowering it weakens
7
+ * none. Setting the minimum already stored changes and records nothing.
8
+ */
9
+ export declare function setPasswordPolicyUseCase(c: AdminContext, input: SetPasswordPolicyRequest): Promise<PasswordPolicyDto>;
@@ -0,0 +1,5 @@
1
+ import { type OkResponse, type PasswordActionDelivery, type PrincipalIdInput } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ export declare function issuePasswordEnrollmentUseCase(c: AdminContext, input: PrincipalIdInput): Promise<PasswordActionDelivery>;
4
+ export declare function issuePasswordResetUseCase(c: AdminContext, input: PrincipalIdInput): Promise<PasswordActionDelivery>;
5
+ export declare function disablePasswordUseCase(c: AdminContext, input: PrincipalIdInput): Promise<OkResponse>;
@@ -0,0 +1,15 @@
1
+ import { type AppInput, type CreatePolicyInput, type OkResponse, type PolicyDto, type UpdatePolicyInput } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ /** List an app's custom policies (origin='custom' role rows). */
4
+ export declare function listPoliciesUseCase(c: AdminContext, input: AppInput): Promise<{
5
+ items: PolicyDto[];
6
+ }>;
7
+ /** Create a custom policy (origin='custom' role). Rejects a key that already exists. */
8
+ export declare function createPolicyUseCase(c: AdminContext, input: CreatePolicyInput): Promise<PolicyDto>;
9
+ /** Update a custom policy. Rejects if the key is missing or is an origin='app' role. */
10
+ export declare function updatePolicyUseCase(c: AdminContext, input: UpdatePolicyInput): Promise<PolicyDto>;
11
+ /** Delete a custom policy. Refuses to delete an origin='app' (reconciled) role. */
12
+ export declare function deletePolicyUseCase(c: AdminContext, input: {
13
+ app: string;
14
+ key: string;
15
+ }): Promise<OkResponse>;
@@ -0,0 +1,15 @@
1
+ import { type CursorList, type InviteRequest, type ListPrincipalsInput, type MeDto, type PrincipalDetail, type PrincipalIdInput, type PrincipalListItem, type UpdatePrincipalInput } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ export declare function me(c: AdminContext): MeDto;
4
+ export declare function listPrincipalsUseCase(c: AdminContext, input: ListPrincipalsInput): Promise<CursorList<PrincipalListItem>>;
5
+ export declare function getPrincipalUseCase(c: AdminContext, input: PrincipalIdInput): Promise<PrincipalDetail>;
6
+ export declare function invitePrincipalUseCase(c: AdminContext, input: InviteRequest): Promise<PrincipalListItem>;
7
+ export declare function updatePrincipalUseCase(c: AdminContext, input: UpdatePrincipalInput): Promise<PrincipalListItem>;
8
+ /**
9
+ * Make an external user internal (ADR-0051). Its grant rows stay as they are, but what it may reach widens: it may then
10
+ * hold any role, an OIDC login presenting its address may claim it, and a mailbox listed in `IAM_BOOTSTRAP_ADMINS`
11
+ * becomes an installation admin at once. So the promotion revokes every session of the user and spends its pending
12
+ * password actions in the same transaction, and its record says whether the mailbox is a bootstrap admin. There is no
13
+ * demotion.
14
+ */
15
+ export declare function promotePrincipalUseCase(c: AdminContext, input: PrincipalIdInput): Promise<PrincipalListItem>;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * `/admin/*` — the MACHINE PROVISIONING surface, and the shared admission code `/admin/rpc` uses.
3
+ *
4
+ * It is not a second copy of the administration API. It used to be: about two dozen REST operations
5
+ * mirrored `/admin/rpc` procedure for procedure, and every one of them was a second place a gate
6
+ * could be forgotten (SEC-11) or an internal message could leak (CORR-4) — for operations that had
7
+ * no REST caller at all. They are gone. The console and every operator action go through
8
+ * `/admin/rpc`, so "policy, audit and hidden-object behaviour must not diverge by transport" is no
9
+ * longer a property anyone has to maintain for them; there is one transport.
10
+ *
11
+ * What is left is exactly what cannot be an RPC call from a browser:
12
+ * - `GET|PUT /admin/apps/:app/schema` — a deploy step reconciling an app's vocabulary
13
+ * (`reconcileSchema`, `@fabrika/auth`), which runs outside the installation over plain HTTPS;
14
+ * - `POST /admin/api-keys`, `DELETE /admin/api-keys/:principalId` — first-machine-caller bootstrap,
15
+ * which runs before a console exists.
16
+ * Adding a route here means proving no `/admin/rpc` procedure can serve the caller.
17
+ *
18
+ * **The whole surface is BEARER-ONLY.** The console reaches it through Control's gateway, which
19
+ * forwards the proxy-injected token as a bearer; machines present a `px_` key. No browser cookie is
20
+ * read, so there is no ambient authority and no CSRF check to keep.
21
+ *
22
+ * `extractCredentials` and `resolveAdmin` live here and are SHARED with `admin/rpc.ts`, so the
23
+ * caller is resolved in one place for both.
24
+ */
25
+ import { type PermissionEntry, type PrincipalType } from '@fabrika/auth-core';
26
+ import type { Env, RequestContext } from '../env';
27
+ import type { Services } from '../services';
28
+ export declare const ADMIN_ACTION: "iam.admin";
29
+ export declare const IAM_APP = "propustka";
30
+ /**
31
+ * The admin credential read off the request: an `Authorization: Bearer` holding a `px_` admin or
32
+ * provisioning key, or a proxy-injected access JWT forwarded by a first-party gateway.
33
+ */
34
+ export declare function extractCredentials(request: Request, requestId: string): {
35
+ bearer: string | null;
36
+ requestId: string;
37
+ };
38
+ /** The resolved admin (already authenticated; the `iam.admin` gate is applied by `handleAdmin`). */
39
+ export interface ResolvedAdmin {
40
+ id: string;
41
+ type: PrincipalType;
42
+ label: string | null;
43
+ permissions: PermissionEntry[];
44
+ /** The app the admin's credential was verified for: a registered console gateway, or IAM itself for a `px_` key. */
45
+ audience: string;
46
+ /** The credential is a signed-in session's token (`AccessTokenClaims.session`), not one a `px_` key minted. */
47
+ session: boolean;
48
+ }
49
+ export type AdminResolution = {
50
+ ok: true;
51
+ admin: ResolvedAdmin;
52
+ } | {
53
+ ok: false;
54
+ status: 401 | 403;
55
+ reason: string;
56
+ };
57
+ /**
58
+ * Resolve the admin caller from its bearer:
59
+ * - a signed-in session's access JWT whose `aud` is a REGISTERED admin gateway → verify identity, then resolve IAM
60
+ * permissions;
61
+ * - a `px_<key>` machine credential (CI / provisioning) → `resolveCaller`.
62
+ * No bearer is 401. Returns the caller + permissions; `handleAdmin` then enforces `iam.admin`. An ANONYMOUS credential
63
+ * (a share link, no principal) is rejected — admin needs an accountable principal.
64
+ */
65
+ export declare function resolveAdmin(services: Services, env: Pick<Env, 'FABRIKA_IAM_SIGNING_KEYS' | 'FABRIKA_IAM_PROVISIONING_KEY' | 'ENVIRONMENT'>, creds: {
66
+ bearer: string | null;
67
+ requestId: string;
68
+ }): Promise<AdminResolution>;
69
+ /**
70
+ * Handle a `/admin/*` PROVISIONING request. The caller is resolved from its bearer and every handler runs only after `can('iam.admin')`
71
+ * passes in-Worker (scope-less → global only). Returns 401 when the caller can't be authenticated,
72
+ * 403 when authenticated but not an admin. `requestId` is the correlation id the composition root
73
+ * allowed (`src/request-id.ts`); a caller that supplies none gets a generated one.
74
+ */
75
+ export declare function handleAdmin(request: Request, services: Services, env: Pick<Env, 'FABRIKA_IAM_SIGNING_KEYS' | 'FABRIKA_IAM_PROVISIONING_KEY' | 'ENVIRONMENT'>, ctx: RequestContext, requestId?: string): Promise<Response>;
@@ -0,0 +1,6 @@
1
+ import { type RpcRouterFor } from '@fabrika/app';
2
+ import { type IamAdminRpcContract } from '@fabrika/iam-contract';
3
+ import type { IamAppContext } from '../app';
4
+ export declare const adminRpcRouter: RpcRouterFor<IamAppContext, IamAdminRpcContract>;
5
+ /** Resolve the admin behind an `/admin/rpc` request, then run `next` with it on `ctx`; anyone else is refused. */
6
+ export declare const adminRpcAuth: (request: Request, ctx: IamAppContext, next: () => Promise<Response>) => Promise<Response>;
@@ -0,0 +1,14 @@
1
+ import { type ListSessionsInput, type PrincipalIdInput, type RevokedSessionsResponse, type SessionIdInput, type SessionList } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ /** Page by sign-in when requested, keeping all of that page's application sessions with their parent. */
4
+ export declare function listSessionsUseCase(c: AdminContext, input: ListSessionsInput): Promise<SessionList>;
5
+ /**
6
+ * Revoke ONE session.
7
+ *
8
+ * Revoking an IAM session ends every app session derived from it in the same write: a child is valid
9
+ * only while its parent is, and the lookup joins to the parent on every use (ADR-0022). So there is
10
+ * no sweep to run and no window in which a child outlives its parent.
11
+ */
12
+ export declare function revokeSessionUseCase(c: AdminContext, input: SessionIdInput): Promise<RevokedSessionsResponse>;
13
+ /** Revoke every live session a principal holds — the "sign them out everywhere" answer. */
14
+ export declare function revokeSessionsForPrincipalUseCase(c: AdminContext, input: PrincipalIdInput): Promise<RevokedSessionsResponse>;
@@ -0,0 +1,21 @@
1
+ import { type CursorList, type IssuedShareLinkResponse, type IssueShareLinkRequest, type ListShareLinksInput, type OkResponse, type ShareLinkListItem } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ /**
4
+ * One page of share links. Two queries per page (the credentials read plus one grants read for the
5
+ * page's ids), revoked links hidden unless asked for, and `app` finally filterable now that an
6
+ * anonymous credential carries one (SEC-2, SEC-22).
7
+ */
8
+ export declare function listShareLinksUseCase(c: AdminContext, input: ListShareLinksInput): Promise<CursorList<ShareLinkListItem>>;
9
+ /**
10
+ * Issue an anonymous share link FOR ONE APP.
11
+ *
12
+ * `app` is required and is not IAM's own. A share link's grants are frozen at issue and spent
13
+ * wherever the holder presents them, so the app has to be stated: it is what `resolveCredential`
14
+ * checks at every mint, and without it an admin of one app could mint authority good at every other
15
+ * app behind the proxy (SEC-2). Delegation still runs against the admin's permissions — resolved for
16
+ * that app, which is the same question the credential will later ask.
17
+ */
18
+ export declare function createShareLinkUseCase(c: AdminContext, input: IssueShareLinkRequest): Promise<IssuedShareLinkResponse>;
19
+ export declare function revokeShareLinkUseCase(c: AdminContext, input: {
20
+ id: string;
21
+ }): Promise<OkResponse>;
@@ -0,0 +1,13 @@
1
+ import { type CursorList, type ListTerminalsInput, type OkResponse, type SetTerminalProfileRequest, type TerminalDto, type TerminalIdInput } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ /** One page of terminals, newest first, revoked ones included. Two queries: the page and its asserters. */
4
+ export declare function listTerminalsUseCase(c: AdminContext, input: ListTerminalsInput): Promise<CursorList<TerminalDto>>;
5
+ /**
6
+ * Replace an enrolled terminal's profile. An asserter is a registered application that is not a platform audience: a
7
+ * platform audience's token carries cross-app authority, and IAM's own re-resolves the subject's permissions, either of
8
+ * which would step past the ceiling. Each ceiling pattern must name actions of its application, as a typo check; the
9
+ * ceiling only narrows what the person brings, so a pattern there grants nothing.
10
+ */
11
+ export declare function setTerminalProfileUseCase(c: AdminContext, input: SetTerminalProfileRequest): Promise<TerminalDto>;
12
+ /** Revoke a terminal and every session issued on it. Repeating it answers the same; an unknown terminal is a 404. */
13
+ export declare function revokeTerminalUseCase(c: AdminContext, input: TerminalIdInput): Promise<OkResponse>;
@@ -0,0 +1,30 @@
1
+ import { type IamAdministrationScope } from '@fabrika/iam-contract';
2
+ import { type PrincipalRow } from '../db';
3
+ import type { Services } from '../services';
4
+ import { type AdminContext } from './context';
5
+ import type { ResolvedAdmin } from './router';
6
+ /** What the caller administers: the installation, or the people of some applications (`null` = every application). */
7
+ export type Administration = IamAdministrationScope;
8
+ /**
9
+ * The caller's administration, or null when it holds none. A user administrator is a person signed in to the console,
10
+ * as for `appPeople`: a `px_` key administers only with `iam.admin`.
11
+ */
12
+ export declare function administrationOf(admin: Pick<ResolvedAdmin, 'permissions' | 'type' | 'audience' | 'session'>): Administration | null;
13
+ /** True when `administration` may write a grant at `app`: never cross-app, never an installation app, only in scope. */
14
+ export declare function managesApp(services: Pick<Services, 'config'>, administration: Administration, app: string | null): boolean;
15
+ /** Refuse a grant write at `app` that the caller's administration does not reach. */
16
+ export declare function requireManagedApp(c: AdminContext, app: string | null): void;
17
+ /** Refuse a user administrator a grant write on a service principal: an API key's grants are edited like the rest of `apiKeys.*`. */
18
+ export declare function requireGrantablePrincipal(c: AdminContext, principal: Pick<PrincipalRow, 'type'>): void;
19
+ /**
20
+ * Refuse to act on `principal` unless the caller could have made every grant it holds. That keeps an installation
21
+ * administrator, a deployer, a console admin, a bootstrap mailbox and every other user administrator out of reach.
22
+ */
23
+ export declare function requireActableTarget(c: AdminContext, principal: PrincipalRow): Promise<void>;
24
+ /**
25
+ * Refuse a user administrator an invitation for a mailbox in `IAM_BOOTSTRAP_ADMINS`. The row it would create decides how
26
+ * that installation administrator signs in, and `requireActableTarget` keeps the row out of the caller's reach afterwards.
27
+ */
28
+ export declare function requireInvitableMailbox(c: AdminContext, mailbox: string): void;
29
+ /** The same rule serves UI capabilities and the write guard. */
30
+ export declare function canManagePrincipal(c: AdminContext, principal: PrincipalRow): Promise<boolean>;
@@ -0,0 +1,5 @@
1
+ import type { IssueWorkloadKeyRequest, IssueWorkloadKeyResponse, RevokeWorkloadKeysRequest, RevokeWorkloadKeysResponse } from '@fabrika/iam-contract';
2
+ import { type AdminContext } from './context';
3
+ export declare function issueWorkloadKeyUseCase(c: AdminContext, input: IssueWorkloadKeyRequest): Promise<IssueWorkloadKeyResponse>;
4
+ /** Revoke every live key of one workload, so a consumer that stopped importing keeps no key at the owner. */
5
+ export declare function revokeWorkloadKeysUseCase(c: AdminContext, input: RevokeWorkloadKeysRequest): Promise<RevokeWorkloadKeysResponse>;