@hilbras/keystone 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (786) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/LICENSE +21 -0
  3. package/README.md +691 -0
  4. package/dist/cli.d.ts +3 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +144 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/config.d.ts +68 -0
  9. package/dist/config.d.ts.map +1 -0
  10. package/dist/config.js +118 -0
  11. package/dist/config.js.map +1 -0
  12. package/dist/container.d.ts +27 -0
  13. package/dist/container.d.ts.map +1 -0
  14. package/dist/container.js +14 -0
  15. package/dist/container.js.map +1 -0
  16. package/dist/db/index.d.ts +17 -0
  17. package/dist/db/index.d.ts.map +1 -0
  18. package/dist/db/index.js +46 -0
  19. package/dist/db/index.js.map +1 -0
  20. package/dist/db/migrations/0000_skinny_ben_parker.sql +553 -0
  21. package/dist/db/migrations/0001_brief_joseph.sql +10 -0
  22. package/dist/db/migrations/0002_add_account_lockout.sql +3 -0
  23. package/dist/db/migrations/0003_steep_rachel_grey.sql +1 -0
  24. package/dist/db/migrations/0004_clever_bill_hollister.sql +20 -0
  25. package/dist/db/migrations/0005_steep_the_call.sql +2 -0
  26. package/dist/db/migrations/0006_ambitious_boomer.sql +17 -0
  27. package/dist/db/migrations/0007_greedy_vindicator.sql +40 -0
  28. package/dist/db/migrations/meta/0000_snapshot.json +2964 -0
  29. package/dist/db/migrations/meta/0001_snapshot.json +3031 -0
  30. package/dist/db/migrations/meta/0003_snapshot.json +3051 -0
  31. package/dist/db/migrations/meta/0004_snapshot.json +3163 -0
  32. package/dist/db/migrations/meta/0005_snapshot.json +3177 -0
  33. package/dist/db/migrations/meta/0006_snapshot.json +3270 -0
  34. package/dist/db/migrations/meta/0007_snapshot.json +3489 -0
  35. package/dist/db/migrations/meta/_journal.json +62 -0
  36. package/dist/db/schema.d.ts +3671 -0
  37. package/dist/db/schema.d.ts.map +1 -0
  38. package/dist/db/schema.js +475 -0
  39. package/dist/db/schema.js.map +1 -0
  40. package/dist/db/seed.d.ts +2 -0
  41. package/dist/db/seed.d.ts.map +1 -0
  42. package/dist/db/seed.js +139 -0
  43. package/dist/db/seed.js.map +1 -0
  44. package/dist/di.d.ts +12 -0
  45. package/dist/di.d.ts.map +1 -0
  46. package/dist/di.js +56 -0
  47. package/dist/di.js.map +1 -0
  48. package/dist/index.d.ts +3 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +295 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/lib/errors.d.ts +46 -0
  53. package/dist/lib/errors.d.ts.map +1 -0
  54. package/dist/lib/errors.js +78 -0
  55. package/dist/lib/errors.js.map +1 -0
  56. package/dist/lib/result.d.ts +21 -0
  57. package/dist/lib/result.d.ts.map +1 -0
  58. package/dist/lib/result.js +22 -0
  59. package/dist/lib/result.js.map +1 -0
  60. package/dist/lib/webhookSignature.d.ts +11 -0
  61. package/dist/lib/webhookSignature.d.ts.map +1 -0
  62. package/dist/lib/webhookSignature.js +35 -0
  63. package/dist/lib/webhookSignature.js.map +1 -0
  64. package/dist/plugins/appContext.d.ts +4 -0
  65. package/dist/plugins/appContext.d.ts.map +1 -0
  66. package/dist/plugins/appContext.js +63 -0
  67. package/dist/plugins/appContext.js.map +1 -0
  68. package/dist/plugins/audit.d.ts +11 -0
  69. package/dist/plugins/audit.d.ts.map +1 -0
  70. package/dist/plugins/audit.js +23 -0
  71. package/dist/plugins/audit.js.map +1 -0
  72. package/dist/plugins/auth.d.ts +21 -0
  73. package/dist/plugins/auth.d.ts.map +1 -0
  74. package/dist/plugins/auth.js +190 -0
  75. package/dist/plugins/auth.js.map +1 -0
  76. package/dist/plugins/metrics.d.ts +8 -0
  77. package/dist/plugins/metrics.d.ts.map +1 -0
  78. package/dist/plugins/metrics.js +36 -0
  79. package/dist/plugins/metrics.js.map +1 -0
  80. package/dist/plugins/mtls.d.ts +14 -0
  81. package/dist/plugins/mtls.d.ts.map +1 -0
  82. package/dist/plugins/mtls.js +76 -0
  83. package/dist/plugins/mtls.js.map +1 -0
  84. package/dist/plugins/permissions.d.ts +9 -0
  85. package/dist/plugins/permissions.d.ts.map +1 -0
  86. package/dist/plugins/permissions.js +20 -0
  87. package/dist/plugins/permissions.js.map +1 -0
  88. package/dist/plugins/rateLimit.d.ts +20 -0
  89. package/dist/plugins/rateLimit.d.ts.map +1 -0
  90. package/dist/plugins/rateLimit.js +101 -0
  91. package/dist/plugins/rateLimit.js.map +1 -0
  92. package/dist/plugins/requestLogger.d.ts +4 -0
  93. package/dist/plugins/requestLogger.d.ts.map +1 -0
  94. package/dist/plugins/requestLogger.js +20 -0
  95. package/dist/plugins/requestLogger.js.map +1 -0
  96. package/dist/plugins/tracing.d.ts +3 -0
  97. package/dist/plugins/tracing.d.ts.map +1 -0
  98. package/dist/plugins/tracing.js +21 -0
  99. package/dist/plugins/tracing.js.map +1 -0
  100. package/dist/repositories/apiKey.d.ts +40 -0
  101. package/dist/repositories/apiKey.d.ts.map +1 -0
  102. package/dist/repositories/apiKey.js +122 -0
  103. package/dist/repositories/apiKey.js.map +1 -0
  104. package/dist/repositories/application.d.ts +13 -0
  105. package/dist/repositories/application.d.ts.map +1 -0
  106. package/dist/repositories/application.js +57 -0
  107. package/dist/repositories/application.js.map +1 -0
  108. package/dist/repositories/audit.d.ts +13 -0
  109. package/dist/repositories/audit.d.ts.map +1 -0
  110. package/dist/repositories/audit.js +26 -0
  111. package/dist/repositories/audit.js.map +1 -0
  112. package/dist/repositories/index.d.ts +10 -0
  113. package/dist/repositories/index.d.ts.map +1 -0
  114. package/dist/repositories/index.js +10 -0
  115. package/dist/repositories/index.js.map +1 -0
  116. package/dist/repositories/oidcConnection.d.ts +131 -0
  117. package/dist/repositories/oidcConnection.d.ts.map +1 -0
  118. package/dist/repositories/oidcConnection.js +59 -0
  119. package/dist/repositories/oidcConnection.js.map +1 -0
  120. package/dist/repositories/organization.d.ts +44 -0
  121. package/dist/repositories/organization.d.ts.map +1 -0
  122. package/dist/repositories/organization.js +145 -0
  123. package/dist/repositories/organization.js.map +1 -0
  124. package/dist/repositories/permission.d.ts +24 -0
  125. package/dist/repositories/permission.d.ts.map +1 -0
  126. package/dist/repositories/permission.js +133 -0
  127. package/dist/repositories/permission.js.map +1 -0
  128. package/dist/repositories/samlConnection.d.ts +107 -0
  129. package/dist/repositories/samlConnection.d.ts.map +1 -0
  130. package/dist/repositories/samlConnection.js +53 -0
  131. package/dist/repositories/samlConnection.js.map +1 -0
  132. package/dist/repositories/session.d.ts +73 -0
  133. package/dist/repositories/session.d.ts.map +1 -0
  134. package/dist/repositories/session.js +68 -0
  135. package/dist/repositories/session.js.map +1 -0
  136. package/dist/repositories/types.d.ts +155 -0
  137. package/dist/repositories/types.d.ts.map +1 -0
  138. package/dist/repositories/types.js +2 -0
  139. package/dist/repositories/types.js.map +1 -0
  140. package/dist/repositories/user.d.ts +40 -0
  141. package/dist/repositories/user.d.ts.map +1 -0
  142. package/dist/repositories/user.js +135 -0
  143. package/dist/repositories/user.js.map +1 -0
  144. package/dist/routes/admin/billing.d.ts +3 -0
  145. package/dist/routes/admin/billing.d.ts.map +1 -0
  146. package/dist/routes/admin/billing.js +31 -0
  147. package/dist/routes/admin/billing.js.map +1 -0
  148. package/dist/routes/admin/helpers.d.ts +36 -0
  149. package/dist/routes/admin/helpers.d.ts.map +1 -0
  150. package/dist/routes/admin/helpers.js +45 -0
  151. package/dist/routes/admin/helpers.js.map +1 -0
  152. package/dist/routes/admin/index.d.ts +3 -0
  153. package/dist/routes/admin/index.d.ts.map +1 -0
  154. package/dist/routes/admin/index.js +15 -0
  155. package/dist/routes/admin/index.js.map +1 -0
  156. package/dist/routes/admin/organizations.d.ts +3 -0
  157. package/dist/routes/admin/organizations.d.ts.map +1 -0
  158. package/dist/routes/admin/organizations.js +222 -0
  159. package/dist/routes/admin/organizations.js.map +1 -0
  160. package/dist/routes/admin/permissions.d.ts +3 -0
  161. package/dist/routes/admin/permissions.d.ts.map +1 -0
  162. package/dist/routes/admin/permissions.js +63 -0
  163. package/dist/routes/admin/permissions.js.map +1 -0
  164. package/dist/routes/admin/platform.d.ts +3 -0
  165. package/dist/routes/admin/platform.d.ts.map +1 -0
  166. package/dist/routes/admin/platform.js +294 -0
  167. package/dist/routes/admin/platform.js.map +1 -0
  168. package/dist/routes/admin/sso.d.ts +3 -0
  169. package/dist/routes/admin/sso.d.ts.map +1 -0
  170. package/dist/routes/admin/sso.js +97 -0
  171. package/dist/routes/admin/sso.js.map +1 -0
  172. package/dist/routes/admin/webhooks.d.ts +3 -0
  173. package/dist/routes/admin/webhooks.d.ts.map +1 -0
  174. package/dist/routes/admin/webhooks.js +68 -0
  175. package/dist/routes/admin/webhooks.js.map +1 -0
  176. package/dist/routes/admin.d.ts +2 -0
  177. package/dist/routes/admin.d.ts.map +1 -0
  178. package/dist/routes/admin.js +2 -0
  179. package/dist/routes/admin.js.map +1 -0
  180. package/dist/routes/apiKeys.d.ts +3 -0
  181. package/dist/routes/apiKeys.d.ts.map +1 -0
  182. package/dist/routes/apiKeys.js +50 -0
  183. package/dist/routes/apiKeys.js.map +1 -0
  184. package/dist/routes/auth.d.ts +3 -0
  185. package/dist/routes/auth.d.ts.map +1 -0
  186. package/dist/routes/auth.js +174 -0
  187. package/dist/routes/auth.js.map +1 -0
  188. package/dist/routes/authz.d.ts +3 -0
  189. package/dist/routes/authz.d.ts.map +1 -0
  190. package/dist/routes/authz.js +28 -0
  191. package/dist/routes/authz.js.map +1 -0
  192. package/dist/routes/config.d.ts +3 -0
  193. package/dist/routes/config.d.ts.map +1 -0
  194. package/dist/routes/config.js +63 -0
  195. package/dist/routes/config.js.map +1 -0
  196. package/dist/routes/emailVerification.d.ts +3 -0
  197. package/dist/routes/emailVerification.d.ts.map +1 -0
  198. package/dist/routes/emailVerification.js +64 -0
  199. package/dist/routes/emailVerification.js.map +1 -0
  200. package/dist/routes/federation.d.ts +3 -0
  201. package/dist/routes/federation.d.ts.map +1 -0
  202. package/dist/routes/federation.js +133 -0
  203. package/dist/routes/federation.js.map +1 -0
  204. package/dist/routes/helpers.d.ts +14 -0
  205. package/dist/routes/helpers.d.ts.map +1 -0
  206. package/dist/routes/helpers.js +15 -0
  207. package/dist/routes/helpers.js.map +1 -0
  208. package/dist/routes/magicLinks.d.ts +3 -0
  209. package/dist/routes/magicLinks.d.ts.map +1 -0
  210. package/dist/routes/magicLinks.js +82 -0
  211. package/dist/routes/magicLinks.js.map +1 -0
  212. package/dist/routes/oauth.d.ts +3 -0
  213. package/dist/routes/oauth.d.ts.map +1 -0
  214. package/dist/routes/oauth.js +146 -0
  215. package/dist/routes/oauth.js.map +1 -0
  216. package/dist/routes/oauth2.d.ts +3 -0
  217. package/dist/routes/oauth2.d.ts.map +1 -0
  218. package/dist/routes/oauth2.js +219 -0
  219. package/dist/routes/oauth2.js.map +1 -0
  220. package/dist/routes/oidcEnterprise.d.ts +3 -0
  221. package/dist/routes/oidcEnterprise.d.ts.map +1 -0
  222. package/dist/routes/oidcEnterprise.js +119 -0
  223. package/dist/routes/oidcEnterprise.js.map +1 -0
  224. package/dist/routes/password.d.ts +3 -0
  225. package/dist/routes/password.d.ts.map +1 -0
  226. package/dist/routes/password.js +83 -0
  227. package/dist/routes/password.js.map +1 -0
  228. package/dist/routes/profile.d.ts +3 -0
  229. package/dist/routes/profile.d.ts.map +1 -0
  230. package/dist/routes/profile.js +43 -0
  231. package/dist/routes/profile.js.map +1 -0
  232. package/dist/routes/saml.d.ts +3 -0
  233. package/dist/routes/saml.d.ts.map +1 -0
  234. package/dist/routes/saml.js +164 -0
  235. package/dist/routes/saml.js.map +1 -0
  236. package/dist/routes/scim.d.ts +3 -0
  237. package/dist/routes/scim.d.ts.map +1 -0
  238. package/dist/routes/scim.js +175 -0
  239. package/dist/routes/scim.js.map +1 -0
  240. package/dist/routes/sdk.d.ts +3 -0
  241. package/dist/routes/sdk.d.ts.map +1 -0
  242. package/dist/routes/sdk.js +129 -0
  243. package/dist/routes/sdk.js.map +1 -0
  244. package/dist/routes/serviceAccounts.d.ts +3 -0
  245. package/dist/routes/serviceAccounts.d.ts.map +1 -0
  246. package/dist/routes/serviceAccounts.js +82 -0
  247. package/dist/routes/serviceAccounts.js.map +1 -0
  248. package/dist/routes/sessions.d.ts +3 -0
  249. package/dist/routes/sessions.d.ts.map +1 -0
  250. package/dist/routes/sessions.js +55 -0
  251. package/dist/routes/sessions.js.map +1 -0
  252. package/dist/routes/setup.d.ts +3 -0
  253. package/dist/routes/setup.d.ts.map +1 -0
  254. package/dist/routes/setup.js +304 -0
  255. package/dist/routes/setup.js.map +1 -0
  256. package/dist/routes/smsOtp.d.ts +3 -0
  257. package/dist/routes/smsOtp.d.ts.map +1 -0
  258. package/dist/routes/smsOtp.js +50 -0
  259. package/dist/routes/smsOtp.js.map +1 -0
  260. package/dist/routes/totp.d.ts +3 -0
  261. package/dist/routes/totp.d.ts.map +1 -0
  262. package/dist/routes/totp.js +78 -0
  263. package/dist/routes/totp.js.map +1 -0
  264. package/dist/routes/webauthn.d.ts +3 -0
  265. package/dist/routes/webauthn.d.ts.map +1 -0
  266. package/dist/routes/webauthn.js +100 -0
  267. package/dist/routes/webauthn.js.map +1 -0
  268. package/dist/routes/workflows.d.ts +3 -0
  269. package/dist/routes/workflows.d.ts.map +1 -0
  270. package/dist/routes/workflows.js +140 -0
  271. package/dist/routes/workflows.js.map +1 -0
  272. package/dist/sdk/index.d.ts +5 -0
  273. package/dist/sdk/index.d.ts.map +1 -0
  274. package/dist/sdk/index.js +125 -0
  275. package/dist/sdk/index.js.map +1 -0
  276. package/dist/sdk/types.d.ts +110 -0
  277. package/dist/sdk/types.d.ts.map +1 -0
  278. package/dist/sdk/types.js +2 -0
  279. package/dist/sdk/types.js.map +1 -0
  280. package/dist/services/anomalyDetection.d.ts +14 -0
  281. package/dist/services/anomalyDetection.d.ts.map +1 -0
  282. package/dist/services/anomalyDetection.js +68 -0
  283. package/dist/services/anomalyDetection.js.map +1 -0
  284. package/dist/services/application/authentication.d.ts +38 -0
  285. package/dist/services/application/authentication.d.ts.map +1 -0
  286. package/dist/services/application/authentication.js +48 -0
  287. package/dist/services/application/authentication.js.map +1 -0
  288. package/dist/services/application/identity.d.ts +34 -0
  289. package/dist/services/application/identity.d.ts.map +1 -0
  290. package/dist/services/application/identity.js +34 -0
  291. package/dist/services/application/identity.js.map +1 -0
  292. package/dist/services/application/index.d.ts +4 -0
  293. package/dist/services/application/index.d.ts.map +1 -0
  294. package/dist/services/application/index.js +4 -0
  295. package/dist/services/application/index.js.map +1 -0
  296. package/dist/services/application/organization.d.ts +44 -0
  297. package/dist/services/application/organization.d.ts.map +1 -0
  298. package/dist/services/application/organization.js +53 -0
  299. package/dist/services/application/organization.js.map +1 -0
  300. package/dist/services/applications.d.ts +25 -0
  301. package/dist/services/applications.d.ts.map +1 -0
  302. package/dist/services/applications.js +64 -0
  303. package/dist/services/applications.js.map +1 -0
  304. package/dist/services/audit.d.ts +16 -0
  305. package/dist/services/audit.d.ts.map +1 -0
  306. package/dist/services/audit.js +28 -0
  307. package/dist/services/audit.js.map +1 -0
  308. package/dist/services/auditExport.d.ts +17 -0
  309. package/dist/services/auditExport.d.ts.map +1 -0
  310. package/dist/services/auditExport.js +37 -0
  311. package/dist/services/auditExport.js.map +1 -0
  312. package/dist/services/billing.d.ts +23 -0
  313. package/dist/services/billing.d.ts.map +1 -0
  314. package/dist/services/billing.js +67 -0
  315. package/dist/services/billing.js.map +1 -0
  316. package/dist/services/cache.d.ts +23 -0
  317. package/dist/services/cache.d.ts.map +1 -0
  318. package/dist/services/cache.js +114 -0
  319. package/dist/services/cache.js.map +1 -0
  320. package/dist/services/configuration/profiles.d.ts +13 -0
  321. package/dist/services/configuration/profiles.d.ts.map +1 -0
  322. package/dist/services/configuration/profiles.js +108 -0
  323. package/dist/services/configuration/profiles.js.map +1 -0
  324. package/dist/services/configuration.d.ts +50 -0
  325. package/dist/services/configuration.d.ts.map +1 -0
  326. package/dist/services/configuration.js +74 -0
  327. package/dist/services/configuration.js.map +1 -0
  328. package/dist/services/connectors/google.d.ts +17 -0
  329. package/dist/services/connectors/google.d.ts.map +1 -0
  330. package/dist/services/connectors/google.js +81 -0
  331. package/dist/services/connectors/google.js.map +1 -0
  332. package/dist/services/connectors/oidc.d.ts +14 -0
  333. package/dist/services/connectors/oidc.d.ts.map +1 -0
  334. package/dist/services/connectors/oidc.js +100 -0
  335. package/dist/services/connectors/oidc.js.map +1 -0
  336. package/dist/services/connectors/registry.d.ts +13 -0
  337. package/dist/services/connectors/registry.d.ts.map +1 -0
  338. package/dist/services/connectors/registry.js +109 -0
  339. package/dist/services/connectors/registry.js.map +1 -0
  340. package/dist/services/connectors/types.d.ts +36 -0
  341. package/dist/services/connectors/types.d.ts.map +1 -0
  342. package/dist/services/connectors/types.js +2 -0
  343. package/dist/services/connectors/types.js.map +1 -0
  344. package/dist/services/connectors/zitadel.d.ts +14 -0
  345. package/dist/services/connectors/zitadel.d.ts.map +1 -0
  346. package/dist/services/connectors/zitadel.js +70 -0
  347. package/dist/services/connectors/zitadel.js.map +1 -0
  348. package/dist/services/devices.d.ts +4 -0
  349. package/dist/services/devices.d.ts.map +1 -0
  350. package/dist/services/devices.js +59 -0
  351. package/dist/services/devices.js.map +1 -0
  352. package/dist/services/domain/authentication.d.ts +51 -0
  353. package/dist/services/domain/authentication.d.ts.map +1 -0
  354. package/dist/services/domain/authentication.js +218 -0
  355. package/dist/services/domain/authentication.js.map +1 -0
  356. package/dist/services/domain/authorization.d.ts +20 -0
  357. package/dist/services/domain/authorization.d.ts.map +1 -0
  358. package/dist/services/domain/authorization.js +36 -0
  359. package/dist/services/domain/authorization.js.map +1 -0
  360. package/dist/services/domain/identity.d.ts +43 -0
  361. package/dist/services/domain/identity.d.ts.map +1 -0
  362. package/dist/services/domain/identity.js +75 -0
  363. package/dist/services/domain/identity.js.map +1 -0
  364. package/dist/services/domain/index.d.ts +5 -0
  365. package/dist/services/domain/index.d.ts.map +1 -0
  366. package/dist/services/domain/index.js +5 -0
  367. package/dist/services/domain/index.js.map +1 -0
  368. package/dist/services/domain/organization.d.ts +60 -0
  369. package/dist/services/domain/organization.d.ts.map +1 -0
  370. package/dist/services/domain/organization.js +87 -0
  371. package/dist/services/domain/organization.js.map +1 -0
  372. package/dist/services/email.d.ts +24 -0
  373. package/dist/services/email.d.ts.map +1 -0
  374. package/dist/services/email.js +127 -0
  375. package/dist/services/email.js.map +1 -0
  376. package/dist/services/emailVerification.d.ts +20 -0
  377. package/dist/services/emailVerification.d.ts.map +1 -0
  378. package/dist/services/emailVerification.js +58 -0
  379. package/dist/services/emailVerification.js.map +1 -0
  380. package/dist/services/enterpriseSso.d.ts +34 -0
  381. package/dist/services/enterpriseSso.d.ts.map +1 -0
  382. package/dist/services/enterpriseSso.js +40 -0
  383. package/dist/services/enterpriseSso.js.map +1 -0
  384. package/dist/services/events/bus.d.ts +9 -0
  385. package/dist/services/events/bus.d.ts.map +1 -0
  386. package/dist/services/events/bus.js +36 -0
  387. package/dist/services/events/bus.js.map +1 -0
  388. package/dist/services/events/subscribers/anomaly.d.ts +3 -0
  389. package/dist/services/events/subscribers/anomaly.d.ts.map +1 -0
  390. package/dist/services/events/subscribers/anomaly.js +13 -0
  391. package/dist/services/events/subscribers/anomaly.js.map +1 -0
  392. package/dist/services/events/subscribers/auditLog.d.ts +3 -0
  393. package/dist/services/events/subscribers/auditLog.d.ts.map +1 -0
  394. package/dist/services/events/subscribers/auditLog.js +21 -0
  395. package/dist/services/events/subscribers/auditLog.js.map +1 -0
  396. package/dist/services/events/subscribers/webhook.d.ts +3 -0
  397. package/dist/services/events/subscribers/webhook.d.ts.map +1 -0
  398. package/dist/services/events/subscribers/webhook.js +36 -0
  399. package/dist/services/events/subscribers/webhook.js.map +1 -0
  400. package/dist/services/events/subscribers/webhookDispatch.d.ts +7 -0
  401. package/dist/services/events/subscribers/webhookDispatch.d.ts.map +1 -0
  402. package/dist/services/events/subscribers/webhookDispatch.js +14 -0
  403. package/dist/services/events/subscribers/webhookDispatch.js.map +1 -0
  404. package/dist/services/events/types.d.ts +21 -0
  405. package/dist/services/events/types.d.ts.map +1 -0
  406. package/dist/services/events/types.js +8 -0
  407. package/dist/services/events/types.js.map +1 -0
  408. package/dist/services/events/validate.d.ts +9 -0
  409. package/dist/services/events/validate.d.ts.map +1 -0
  410. package/dist/services/events/validate.js +103 -0
  411. package/dist/services/events/validate.js.map +1 -0
  412. package/dist/services/featureFlags.d.ts +15 -0
  413. package/dist/services/featureFlags.d.ts.map +1 -0
  414. package/dist/services/featureFlags.js +74 -0
  415. package/dist/services/featureFlags.js.map +1 -0
  416. package/dist/services/features.d.ts +12 -0
  417. package/dist/services/features.d.ts.map +1 -0
  418. package/dist/services/features.js +17 -0
  419. package/dist/services/features.js.map +1 -0
  420. package/dist/services/federation.d.ts +12 -0
  421. package/dist/services/federation.d.ts.map +1 -0
  422. package/dist/services/federation.js +22 -0
  423. package/dist/services/federation.js.map +1 -0
  424. package/dist/services/hibp.d.ts +2 -0
  425. package/dist/services/hibp.d.ts.map +1 -0
  426. package/dist/services/hibp.js +29 -0
  427. package/dist/services/hibp.js.map +1 -0
  428. package/dist/services/ipControls.d.ts +7 -0
  429. package/dist/services/ipControls.d.ts.map +1 -0
  430. package/dist/services/ipControls.js +92 -0
  431. package/dist/services/ipControls.js.map +1 -0
  432. package/dist/services/magicLinks.d.ts +16 -0
  433. package/dist/services/magicLinks.d.ts.map +1 -0
  434. package/dist/services/magicLinks.js +39 -0
  435. package/dist/services/magicLinks.js.map +1 -0
  436. package/dist/services/oauth2.d.ts +58 -0
  437. package/dist/services/oauth2.d.ts.map +1 -0
  438. package/dist/services/oauth2.js +144 -0
  439. package/dist/services/oauth2.js.map +1 -0
  440. package/dist/services/organizations.d.ts +39 -0
  441. package/dist/services/organizations.d.ts.map +1 -0
  442. package/dist/services/organizations.js +135 -0
  443. package/dist/services/organizations.js.map +1 -0
  444. package/dist/services/permissions.d.ts +19 -0
  445. package/dist/services/permissions.d.ts.map +1 -0
  446. package/dist/services/permissions.js +119 -0
  447. package/dist/services/permissions.js.map +1 -0
  448. package/dist/services/plugins/registry.d.ts +17 -0
  449. package/dist/services/plugins/registry.d.ts.map +1 -0
  450. package/dist/services/plugins/registry.js +196 -0
  451. package/dist/services/plugins/registry.js.map +1 -0
  452. package/dist/services/plugins/types.d.ts +86 -0
  453. package/dist/services/plugins/types.d.ts.map +1 -0
  454. package/dist/services/plugins/types.js +2 -0
  455. package/dist/services/plugins/types.js.map +1 -0
  456. package/dist/services/queue/bullmq.d.ts +16 -0
  457. package/dist/services/queue/bullmq.d.ts.map +1 -0
  458. package/dist/services/queue/bullmq.js +89 -0
  459. package/dist/services/queue/bullmq.js.map +1 -0
  460. package/dist/services/queue/inProcess.d.ts +15 -0
  461. package/dist/services/queue/inProcess.d.ts.map +1 -0
  462. package/dist/services/queue/inProcess.js +63 -0
  463. package/dist/services/queue/inProcess.js.map +1 -0
  464. package/dist/services/queue/index.d.ts +7 -0
  465. package/dist/services/queue/index.d.ts.map +1 -0
  466. package/dist/services/queue/index.js +19 -0
  467. package/dist/services/queue/index.js.map +1 -0
  468. package/dist/services/queue/types.d.ts +24 -0
  469. package/dist/services/queue/types.d.ts.map +1 -0
  470. package/dist/services/queue/types.js +2 -0
  471. package/dist/services/queue/types.js.map +1 -0
  472. package/dist/services/redis.d.ts +9 -0
  473. package/dist/services/redis.d.ts.map +1 -0
  474. package/dist/services/redis.js +15 -0
  475. package/dist/services/redis.js.map +1 -0
  476. package/dist/services/secrets/awsKms.d.ts +41 -0
  477. package/dist/services/secrets/awsKms.d.ts.map +1 -0
  478. package/dist/services/secrets/awsKms.js +81 -0
  479. package/dist/services/secrets/awsKms.js.map +1 -0
  480. package/dist/services/secrets/azureKeyVault.d.ts +44 -0
  481. package/dist/services/secrets/azureKeyVault.d.ts.map +1 -0
  482. package/dist/services/secrets/azureKeyVault.js +152 -0
  483. package/dist/services/secrets/azureKeyVault.js.map +1 -0
  484. package/dist/services/secrets/database.d.ts +29 -0
  485. package/dist/services/secrets/database.d.ts.map +1 -0
  486. package/dist/services/secrets/database.js +138 -0
  487. package/dist/services/secrets/database.js.map +1 -0
  488. package/dist/services/secrets/environment.d.ts +27 -0
  489. package/dist/services/secrets/environment.d.ts.map +1 -0
  490. package/dist/services/secrets/environment.js +102 -0
  491. package/dist/services/secrets/environment.js.map +1 -0
  492. package/dist/services/secrets/index.d.ts +30 -0
  493. package/dist/services/secrets/index.d.ts.map +1 -0
  494. package/dist/services/secrets/index.js +46 -0
  495. package/dist/services/secrets/index.js.map +1 -0
  496. package/dist/services/secrets/password.d.ts +10 -0
  497. package/dist/services/secrets/password.d.ts.map +1 -0
  498. package/dist/services/secrets/password.js +62 -0
  499. package/dist/services/secrets/password.js.map +1 -0
  500. package/dist/services/secrets/provider.d.ts +36 -0
  501. package/dist/services/secrets/provider.d.ts.map +1 -0
  502. package/dist/services/secrets/provider.js +2 -0
  503. package/dist/services/secrets/provider.js.map +1 -0
  504. package/dist/services/secrets/vault.d.ts +41 -0
  505. package/dist/services/secrets/vault.d.ts.map +1 -0
  506. package/dist/services/secrets/vault.js +133 -0
  507. package/dist/services/secrets/vault.js.map +1 -0
  508. package/dist/services/secrets.d.ts +2 -0
  509. package/dist/services/secrets.d.ts.map +1 -0
  510. package/dist/services/secrets.js +3 -0
  511. package/dist/services/secrets.js.map +1 -0
  512. package/dist/services/serviceAccounts.d.ts +24 -0
  513. package/dist/services/serviceAccounts.d.ts.map +1 -0
  514. package/dist/services/serviceAccounts.js +53 -0
  515. package/dist/services/serviceAccounts.js.map +1 -0
  516. package/dist/services/setup/configWriter.d.ts +18 -0
  517. package/dist/services/setup/configWriter.d.ts.map +1 -0
  518. package/dist/services/setup/configWriter.js +192 -0
  519. package/dist/services/setup/configWriter.js.map +1 -0
  520. package/dist/services/setup/diagnostics.d.ts +7 -0
  521. package/dist/services/setup/diagnostics.d.ts.map +1 -0
  522. package/dist/services/setup/diagnostics.js +73 -0
  523. package/dist/services/setup/diagnostics.js.map +1 -0
  524. package/dist/services/setup/token.d.ts +5 -0
  525. package/dist/services/setup/token.d.ts.map +1 -0
  526. package/dist/services/setup/token.js +37 -0
  527. package/dist/services/setup/token.js.map +1 -0
  528. package/dist/services/setup/types.d.ts +35 -0
  529. package/dist/services/setup/types.d.ts.map +1 -0
  530. package/dist/services/setup/types.js +2 -0
  531. package/dist/services/setup/types.js.map +1 -0
  532. package/dist/services/setup/validation.d.ts +7 -0
  533. package/dist/services/setup/validation.d.ts.map +1 -0
  534. package/dist/services/setup/validation.js +198 -0
  535. package/dist/services/setup/validation.js.map +1 -0
  536. package/dist/services/sms.d.ts +10 -0
  537. package/dist/services/sms.d.ts.map +1 -0
  538. package/dist/services/sms.js +62 -0
  539. package/dist/services/sms.js.map +1 -0
  540. package/dist/services/smsOtp.d.ts +7 -0
  541. package/dist/services/smsOtp.d.ts.map +1 -0
  542. package/dist/services/smsOtp.js +56 -0
  543. package/dist/services/smsOtp.js.map +1 -0
  544. package/dist/services/tokens.d.ts +66 -0
  545. package/dist/services/tokens.d.ts.map +1 -0
  546. package/dist/services/tokens.js +205 -0
  547. package/dist/services/tokens.js.map +1 -0
  548. package/dist/services/totp.d.ts +16 -0
  549. package/dist/services/totp.d.ts.map +1 -0
  550. package/dist/services/totp.js +96 -0
  551. package/dist/services/totp.js.map +1 -0
  552. package/dist/services/users.d.ts +39 -0
  553. package/dist/services/users.d.ts.map +1 -0
  554. package/dist/services/users.js +181 -0
  555. package/dist/services/users.js.map +1 -0
  556. package/dist/services/webauthn.d.ts +45 -0
  557. package/dist/services/webauthn.d.ts.map +1 -0
  558. package/dist/services/webauthn.js +147 -0
  559. package/dist/services/webauthn.js.map +1 -0
  560. package/dist/services/webhooks.d.ts +86 -0
  561. package/dist/services/webhooks.d.ts.map +1 -0
  562. package/dist/services/webhooks.js +164 -0
  563. package/dist/services/webhooks.js.map +1 -0
  564. package/dist/services/workflows/engine.d.ts +18 -0
  565. package/dist/services/workflows/engine.d.ts.map +1 -0
  566. package/dist/services/workflows/engine.js +104 -0
  567. package/dist/services/workflows/engine.js.map +1 -0
  568. package/dist/services/workflows/steps.d.ts +17 -0
  569. package/dist/services/workflows/steps.d.ts.map +1 -0
  570. package/dist/services/workflows/steps.js +109 -0
  571. package/dist/services/workflows/steps.js.map +1 -0
  572. package/dist/services/zitadel.d.ts +21 -0
  573. package/dist/services/zitadel.d.ts.map +1 -0
  574. package/dist/services/zitadel.js +228 -0
  575. package/dist/services/zitadel.js.map +1 -0
  576. package/dist/setup-server.d.ts +2 -0
  577. package/dist/setup-server.d.ts.map +1 -0
  578. package/dist/setup-server.js +63 -0
  579. package/dist/setup-server.js.map +1 -0
  580. package/dist/tests/errors.test.d.ts +2 -0
  581. package/dist/tests/errors.test.d.ts.map +1 -0
  582. package/dist/tests/errors.test.js +64 -0
  583. package/dist/tests/errors.test.js.map +1 -0
  584. package/dist/tests/events.test.d.ts +2 -0
  585. package/dist/tests/events.test.d.ts.map +1 -0
  586. package/dist/tests/events.test.js +45 -0
  587. package/dist/tests/events.test.js.map +1 -0
  588. package/dist/tests/featureFlags.test.d.ts +2 -0
  589. package/dist/tests/featureFlags.test.d.ts.map +1 -0
  590. package/dist/tests/featureFlags.test.js +24 -0
  591. package/dist/tests/featureFlags.test.js.map +1 -0
  592. package/dist/tests/integration/queue.test.d.ts +2 -0
  593. package/dist/tests/integration/queue.test.d.ts.map +1 -0
  594. package/dist/tests/integration/queue.test.js +49 -0
  595. package/dist/tests/integration/queue.test.js.map +1 -0
  596. package/dist/tests/plugins.test.d.ts +2 -0
  597. package/dist/tests/plugins.test.d.ts.map +1 -0
  598. package/dist/tests/plugins.test.js +56 -0
  599. package/dist/tests/plugins.test.js.map +1 -0
  600. package/dist/tests/result.test.d.ts +2 -0
  601. package/dist/tests/result.test.d.ts.map +1 -0
  602. package/dist/tests/result.test.js +46 -0
  603. package/dist/tests/result.test.js.map +1 -0
  604. package/dist/tests/setup/configWriter.test.d.ts +2 -0
  605. package/dist/tests/setup/configWriter.test.d.ts.map +1 -0
  606. package/dist/tests/setup/configWriter.test.js +55 -0
  607. package/dist/tests/setup/configWriter.test.js.map +1 -0
  608. package/dist/tests/setup/validation.test.d.ts +2 -0
  609. package/dist/tests/setup/validation.test.d.ts.map +1 -0
  610. package/dist/tests/setup/validation.test.js +26 -0
  611. package/dist/tests/setup/validation.test.js.map +1 -0
  612. package/dist/tests/smoke.test.d.ts +2 -0
  613. package/dist/tests/smoke.test.d.ts.map +1 -0
  614. package/dist/tests/smoke.test.js +124 -0
  615. package/dist/tests/smoke.test.js.map +1 -0
  616. package/dist/types.d.ts +50 -0
  617. package/dist/types.d.ts.map +1 -0
  618. package/dist/types.js +17 -0
  619. package/dist/types.js.map +1 -0
  620. package/package.json +69 -0
  621. package/src/cli.ts +172 -0
  622. package/src/config.ts +143 -0
  623. package/src/container.ts +48 -0
  624. package/src/db/index.ts +53 -0
  625. package/src/db/migrations/0000_skinny_ben_parker.sql +553 -0
  626. package/src/db/migrations/0001_brief_joseph.sql +10 -0
  627. package/src/db/migrations/0002_add_account_lockout.sql +3 -0
  628. package/src/db/migrations/0003_steep_rachel_grey.sql +1 -0
  629. package/src/db/migrations/0004_clever_bill_hollister.sql +20 -0
  630. package/src/db/migrations/0005_steep_the_call.sql +2 -0
  631. package/src/db/migrations/0006_ambitious_boomer.sql +17 -0
  632. package/src/db/migrations/0007_greedy_vindicator.sql +40 -0
  633. package/src/db/migrations/meta/0000_snapshot.json +2964 -0
  634. package/src/db/migrations/meta/0001_snapshot.json +3031 -0
  635. package/src/db/migrations/meta/0003_snapshot.json +3051 -0
  636. package/src/db/migrations/meta/0004_snapshot.json +3163 -0
  637. package/src/db/migrations/meta/0005_snapshot.json +3177 -0
  638. package/src/db/migrations/meta/0006_snapshot.json +3270 -0
  639. package/src/db/migrations/meta/0007_snapshot.json +3489 -0
  640. package/src/db/migrations/meta/_journal.json +62 -0
  641. package/src/db/schema.ts +676 -0
  642. package/src/db/seed.ts +146 -0
  643. package/src/di.ts +81 -0
  644. package/src/index.ts +326 -0
  645. package/src/lib/errors.ts +139 -0
  646. package/src/lib/result.ts +44 -0
  647. package/src/lib/webhookSignature.ts +41 -0
  648. package/src/plugins/appContext.ts +76 -0
  649. package/src/plugins/audit.ts +42 -0
  650. package/src/plugins/auth.ts +230 -0
  651. package/src/plugins/metrics.ts +41 -0
  652. package/src/plugins/mtls.ts +94 -0
  653. package/src/plugins/permissions.ts +29 -0
  654. package/src/plugins/rateLimit.ts +133 -0
  655. package/src/plugins/requestLogger.ts +25 -0
  656. package/src/plugins/tracing.ts +22 -0
  657. package/src/repositories/apiKey.ts +158 -0
  658. package/src/repositories/application.ts +70 -0
  659. package/src/repositories/audit.ts +32 -0
  660. package/src/repositories/index.ts +9 -0
  661. package/src/repositories/oidcConnection.ts +111 -0
  662. package/src/repositories/organization.ts +167 -0
  663. package/src/repositories/permission.ts +153 -0
  664. package/src/repositories/samlConnection.ts +96 -0
  665. package/src/repositories/session.ts +86 -0
  666. package/src/repositories/types.ts +134 -0
  667. package/src/repositories/user.ts +161 -0
  668. package/src/routes/admin/billing.ts +48 -0
  669. package/src/routes/admin/helpers.ts +50 -0
  670. package/src/routes/admin/index.ts +16 -0
  671. package/src/routes/admin/organizations.ts +299 -0
  672. package/src/routes/admin/permissions.ts +80 -0
  673. package/src/routes/admin/platform.ts +335 -0
  674. package/src/routes/admin/sso.ts +138 -0
  675. package/src/routes/admin/webhooks.ts +73 -0
  676. package/src/routes/admin.ts +1 -0
  677. package/src/routes/apiKeys.ts +60 -0
  678. package/src/routes/auth.ts +214 -0
  679. package/src/routes/authz.ts +38 -0
  680. package/src/routes/config.ts +67 -0
  681. package/src/routes/emailVerification.ts +73 -0
  682. package/src/routes/federation.ts +156 -0
  683. package/src/routes/helpers.ts +17 -0
  684. package/src/routes/magicLinks.ts +107 -0
  685. package/src/routes/oauth.ts +167 -0
  686. package/src/routes/oauth2.ts +284 -0
  687. package/src/routes/oidcEnterprise.ts +166 -0
  688. package/src/routes/password.ts +90 -0
  689. package/src/routes/profile.ts +44 -0
  690. package/src/routes/saml.ts +209 -0
  691. package/src/routes/scim.ts +199 -0
  692. package/src/routes/sdk.ts +141 -0
  693. package/src/routes/serviceAccounts.ts +124 -0
  694. package/src/routes/sessions.ts +62 -0
  695. package/src/routes/setup.ts +315 -0
  696. package/src/routes/smsOtp.ts +67 -0
  697. package/src/routes/totp.ts +122 -0
  698. package/src/routes/webauthn.ts +147 -0
  699. package/src/routes/workflows.ts +157 -0
  700. package/src/sdk/index.ts +152 -0
  701. package/src/sdk/types.ts +54 -0
  702. package/src/services/anomalyDetection.ts +73 -0
  703. package/src/services/application/authentication.ts +75 -0
  704. package/src/services/application/identity.ts +56 -0
  705. package/src/services/application/index.ts +3 -0
  706. package/src/services/application/organization.ts +77 -0
  707. package/src/services/applications.ts +89 -0
  708. package/src/services/audit.ts +41 -0
  709. package/src/services/auditExport.ts +59 -0
  710. package/src/services/billing.ts +87 -0
  711. package/src/services/cache.ts +131 -0
  712. package/src/services/configuration/profiles.ts +115 -0
  713. package/src/services/configuration.ts +120 -0
  714. package/src/services/connectors/google.ts +92 -0
  715. package/src/services/connectors/oidc.ts +111 -0
  716. package/src/services/connectors/registry.ts +124 -0
  717. package/src/services/connectors/types.ts +38 -0
  718. package/src/services/connectors/zitadel.ts +77 -0
  719. package/src/services/devices.ts +76 -0
  720. package/src/services/domain/authentication.ts +279 -0
  721. package/src/services/domain/authorization.ts +49 -0
  722. package/src/services/domain/identity.ts +108 -0
  723. package/src/services/domain/index.ts +4 -0
  724. package/src/services/domain/organization.ts +114 -0
  725. package/src/services/email.ts +167 -0
  726. package/src/services/emailVerification.ts +75 -0
  727. package/src/services/enterpriseSso.ts +58 -0
  728. package/src/services/events/bus.ts +43 -0
  729. package/src/services/events/subscribers/anomaly.ts +13 -0
  730. package/src/services/events/subscribers/auditLog.ts +21 -0
  731. package/src/services/events/subscribers/webhook.ts +39 -0
  732. package/src/services/events/subscribers/webhookDispatch.ts +14 -0
  733. package/src/services/events/types.ts +106 -0
  734. package/src/services/events/validate.ts +118 -0
  735. package/src/services/featureFlags.ts +90 -0
  736. package/src/services/features.ts +22 -0
  737. package/src/services/federation.ts +30 -0
  738. package/src/services/hibp.ts +28 -0
  739. package/src/services/ipControls.ts +99 -0
  740. package/src/services/magicLinks.ts +51 -0
  741. package/src/services/oauth2.ts +216 -0
  742. package/src/services/organizations.ts +171 -0
  743. package/src/services/permissions.ts +146 -0
  744. package/src/services/plugins/registry.ts +242 -0
  745. package/src/services/plugins/types.ts +98 -0
  746. package/src/services/queue/bullmq.ts +104 -0
  747. package/src/services/queue/inProcess.ts +75 -0
  748. package/src/services/queue/index.ts +19 -0
  749. package/src/services/queue/types.ts +26 -0
  750. package/src/services/redis.ts +16 -0
  751. package/src/services/secrets/awsKms.ts +97 -0
  752. package/src/services/secrets/azureKeyVault.ts +171 -0
  753. package/src/services/secrets/database.ts +166 -0
  754. package/src/services/secrets/environment.ts +117 -0
  755. package/src/services/secrets/index.ts +50 -0
  756. package/src/services/secrets/password.ts +73 -0
  757. package/src/services/secrets/provider.ts +38 -0
  758. package/src/services/secrets/vault.ts +149 -0
  759. package/src/services/secrets.ts +2 -0
  760. package/src/services/serviceAccounts.ts +74 -0
  761. package/src/services/setup/configWriter.ts +200 -0
  762. package/src/services/setup/diagnostics.ts +76 -0
  763. package/src/services/setup/token.ts +42 -0
  764. package/src/services/setup/types.ts +40 -0
  765. package/src/services/setup/validation.ts +205 -0
  766. package/src/services/sms.ts +81 -0
  767. package/src/services/smsOtp.ts +74 -0
  768. package/src/services/tokens.ts +288 -0
  769. package/src/services/totp.ts +113 -0
  770. package/src/services/users.ts +239 -0
  771. package/src/services/webauthn.ts +193 -0
  772. package/src/services/webhooks.ts +190 -0
  773. package/src/services/workflows/engine.ts +125 -0
  774. package/src/services/workflows/steps.ts +129 -0
  775. package/src/services/zitadel.ts +277 -0
  776. package/src/setup-server.ts +71 -0
  777. package/src/tests/errors.test.ts +74 -0
  778. package/src/tests/events.test.ts +52 -0
  779. package/src/tests/featureFlags.test.ts +26 -0
  780. package/src/tests/integration/queue.test.ts +54 -0
  781. package/src/tests/plugins.test.ts +73 -0
  782. package/src/tests/result.test.ts +52 -0
  783. package/src/tests/setup/configWriter.test.ts +69 -0
  784. package/src/tests/setup/validation.test.ts +29 -0
  785. package/src/tests/smoke.test.ts +136 -0
  786. package/src/types.ts +70 -0
@@ -0,0 +1,44 @@
1
+ export interface KeystoneError {
2
+ code: string;
3
+ message: string;
4
+ statusCode?: number;
5
+ details?: Record<string, unknown>;
6
+ }
7
+
8
+ export type Result<T> =
9
+ | { success: true; data: T; error?: undefined }
10
+ | { success: false; data?: undefined; error: KeystoneError };
11
+
12
+ export function ok<T>(data: T): Result<T> {
13
+ return { success: true, data };
14
+ }
15
+
16
+ export function err<T>(error: KeystoneError): Result<T> {
17
+ return { success: false, error };
18
+ }
19
+
20
+ export function errFromMessage<T>(
21
+ code: string,
22
+ message: string,
23
+ statusCode?: number,
24
+ details?: Record<string, unknown>
25
+ ): Result<T> {
26
+ return err({ code, message, statusCode, details });
27
+ }
28
+
29
+ export function mapResult<T, U>(result: Result<T>, fn: (data: T) => U): Result<U> {
30
+ if (result.success) {
31
+ return ok(fn(result.data));
32
+ }
33
+ return err(result.error);
34
+ }
35
+
36
+ export async function flatMapResult<T, U>(
37
+ result: Result<T>,
38
+ fn: (data: T) => Promise<Result<U>>
39
+ ): Promise<Result<U>> {
40
+ if (result.success) {
41
+ return fn(result.data);
42
+ }
43
+ return err(result.error);
44
+ }
@@ -0,0 +1,41 @@
1
+ import crypto from "node:crypto";
2
+
3
+ /**
4
+ * Sign a webhook payload using HMAC-SHA256.
5
+ * Returns a signature string in the format "t=<timestamp>,v1=<hex>".
6
+ */
7
+ export function signWebhookPayload(secret: string, payload: unknown): string {
8
+ const timestamp = Math.floor(Date.now() / 1000);
9
+ const body = JSON.stringify(payload);
10
+ const signedPayload = `${timestamp}.${body}`;
11
+ const signature = crypto.createHmac("sha256", secret).update(signedPayload).digest("hex");
12
+ return `t=${timestamp},v1=${signature}`;
13
+ }
14
+
15
+ /**
16
+ * Verify a webhook signature.
17
+ * Returns true if the signature matches the payload and timestamp is within tolerance.
18
+ */
19
+ export function verifyWebhookPayload(
20
+ secret: string,
21
+ signatureHeader: string,
22
+ payload: unknown,
23
+ toleranceSeconds = 300
24
+ ): boolean {
25
+ const parts = signatureHeader.split(",").reduce<Record<string, string>>((acc, part) => {
26
+ const [key, value] = part.split("=");
27
+ if (key && value) acc[key.trim()] = value.trim();
28
+ return acc;
29
+ }, {});
30
+
31
+ const timestamp = Number(parts.t);
32
+ const signature = parts.v1;
33
+ if (!timestamp || !signature) return false;
34
+
35
+ const now = Math.floor(Date.now() / 1000);
36
+ if (Math.abs(now - timestamp) > toleranceSeconds) return false;
37
+
38
+ const body = JSON.stringify(payload);
39
+ const expected = crypto.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex");
40
+ return crypto.timingSafeEqual(Buffer.from(signature, "hex"), Buffer.from(expected, "hex"));
41
+ }
@@ -0,0 +1,76 @@
1
+ import fp from "fastify-plugin";
2
+ import type { FastifyInstance, FastifyRequest } from "fastify";
3
+ import { eq, and, arrayContains } from "drizzle-orm";
4
+ import { db } from "../db/index.js";
5
+ import { applications, organizations, orgMemberships } from "../db/schema.js";
6
+
7
+ export default fp(async function appContextPlugin(app: FastifyInstance) {
8
+ app.addHook("onRequest", async (request: FastifyRequest) => {
9
+ // Ensure every request has a fresh state object.
10
+ request.state = {};
11
+
12
+ const clientId = extractClientId(request);
13
+ const origin = request.headers.origin;
14
+
15
+ const appRecord = clientId
16
+ ? await findApplicationByClientId(clientId)
17
+ : origin
18
+ ? await findApplicationByOrigin(origin)
19
+ : undefined;
20
+
21
+ if (!appRecord) return;
22
+
23
+ request.state.app = appRecord;
24
+ request.state.org = appRecord.organization;
25
+
26
+ if (request.user) {
27
+ const [membership] = await db
28
+ .select()
29
+ .from(orgMemberships)
30
+ .where(
31
+ and(
32
+ eq(orgMemberships.orgId, appRecord.organization.id),
33
+ eq(orgMemberships.userId, request.user.id)
34
+ )
35
+ )
36
+ .limit(1);
37
+ if (membership) {
38
+ request.state.membership = membership;
39
+ }
40
+ }
41
+ });
42
+ });
43
+
44
+ function extractClientId(request: FastifyRequest): string | undefined {
45
+ const header = request.headers["x-app-client-id"];
46
+ if (typeof header === "string" && header) return header;
47
+
48
+ const query = (request.query as Record<string, string | undefined>).client_id;
49
+ if (query) return query;
50
+
51
+ return undefined;
52
+ }
53
+
54
+ async function findApplicationByClientId(clientId: string) {
55
+ const [row] = await db
56
+ .select()
57
+ .from(applications)
58
+ .where(and(eq(applications.clientId, clientId), eq(applications.isActive, true)))
59
+ .innerJoin(organizations, eq(applications.orgId, organizations.id))
60
+ .limit(1);
61
+
62
+ if (!row) return undefined;
63
+ return { ...row.applications, organization: row.organizations };
64
+ }
65
+
66
+ async function findApplicationByOrigin(origin: string) {
67
+ const [row] = await db
68
+ .select()
69
+ .from(applications)
70
+ .where(and(arrayContains(applications.allowedOrigins, [origin]), eq(applications.isActive, true)))
71
+ .innerJoin(organizations, eq(applications.orgId, organizations.id))
72
+ .limit(1);
73
+
74
+ if (!row) return undefined;
75
+ return { ...row.applications, organization: row.organizations };
76
+ }
@@ -0,0 +1,42 @@
1
+ import fp from "fastify-plugin";
2
+ import type { FastifyInstance, FastifyRequest } from "fastify";
3
+ import { audit, type AuditEvent } from "../services/audit.js";
4
+ import { emit } from "../services/events/bus.js";
5
+ import type { EventPayload } from "../services/events/types.js";
6
+
7
+ declare module "fastify" {
8
+ interface FastifyRequest {
9
+ audit: (event: AuditEvent, metadata?: Record<string, unknown>) => Promise<void>;
10
+ emitEvent: (event: string, metadata?: Record<string, unknown>) => Promise<void>;
11
+ }
12
+ }
13
+
14
+ function buildPayload(request: FastifyRequest, metadata?: Record<string, unknown>): EventPayload {
15
+ return {
16
+ userId: request.user?.id,
17
+ orgId: request.state?.org?.id,
18
+ appId: request.state?.app?.id,
19
+ requestId: request.id,
20
+ ip: request.ip,
21
+ userAgent: request.headers["user-agent"],
22
+ metadata,
23
+ };
24
+ }
25
+
26
+ export default fp(async function auditPlugin(app: FastifyInstance) {
27
+ app.decorateRequest("audit", async function (
28
+ this: FastifyRequest,
29
+ event: AuditEvent,
30
+ metadata?: Record<string, unknown>
31
+ ) {
32
+ await audit({ ...buildPayload(this, metadata), event });
33
+ });
34
+
35
+ app.decorateRequest("emitEvent", async function (
36
+ this: FastifyRequest,
37
+ event: string,
38
+ metadata?: Record<string, unknown>
39
+ ) {
40
+ await emit({ type: event, payload: buildPayload(this, metadata) });
41
+ });
42
+ });
@@ -0,0 +1,230 @@
1
+ import fp from "fastify-plugin";
2
+ import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
3
+ import { eq, and, gt, isNull } from "drizzle-orm";
4
+ import { config } from "../config.js";
5
+ import { db } from "../db/index.js";
6
+ import { apiKeys, users, serviceAccounts, type User } from "../db/schema.js";
7
+ import { verifyAccessToken, hashApiKey } from "../services/tokens.js";
8
+ import type { TokenClaims } from "../types.js";
9
+
10
+ declare module "fastify" {
11
+ interface FastifyInstance {
12
+ authenticate: (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
13
+ authenticateOrApiKey: (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
14
+ requireScopes: (...scopes: string[]) => (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
15
+ }
16
+
17
+ interface FastifyRequest {
18
+ serviceAccount?: typeof serviceAccounts.$inferSelect;
19
+ apiKeyScopes?: string[];
20
+ }
21
+ }
22
+
23
+ const DEFAULT_ACCESS_COOKIE = config.COOKIE_NAME;
24
+ const DEFAULT_REFRESH_COOKIE = `${config.COOKIE_NAME}-refresh`;
25
+
26
+ export function accessCookieName(clientId?: string): string {
27
+ return clientId ? `app-${clientId}-session` : DEFAULT_ACCESS_COOKIE;
28
+ }
29
+
30
+ export function refreshCookieName(clientId?: string): string {
31
+ return clientId ? `app-${clientId}-session-refresh` : DEFAULT_REFRESH_COOKIE;
32
+ }
33
+
34
+ function cookieOptions(): {
35
+ path: string;
36
+ httpOnly: boolean;
37
+ secure: boolean;
38
+ sameSite: "strict" | "lax" | "none";
39
+ domain: string | undefined;
40
+ } {
41
+ const sameSite = (config.COOKIE_SAME_SITE as "strict" | "lax" | "none") || (config.NODE_ENV === "production" ? "strict" : "lax");
42
+ return {
43
+ path: "/",
44
+ httpOnly: true,
45
+ secure: config.COOKIE_SECURE,
46
+ sameSite,
47
+ domain: config.COOKIE_DOMAIN || undefined,
48
+ };
49
+ }
50
+
51
+ export function setSessionCookies(
52
+ reply: FastifyReply,
53
+ accessToken: string,
54
+ refreshToken: string,
55
+ clientId?: string
56
+ ): void {
57
+ const opts = cookieOptions();
58
+
59
+ reply.setCookie(accessCookieName(clientId), accessToken, {
60
+ ...opts,
61
+ maxAge: config.ACCESS_TOKEN_TTL_SECONDS,
62
+ });
63
+ reply.setCookie(refreshCookieName(clientId), refreshToken, {
64
+ ...opts,
65
+ maxAge: config.REFRESH_TOKEN_TTL_SECONDS,
66
+ });
67
+ }
68
+
69
+ export function clearSessionCookies(reply: FastifyReply, clientId?: string): void {
70
+ const opts = cookieOptions();
71
+ reply.clearCookie(accessCookieName(clientId), opts);
72
+ reply.clearCookie(refreshCookieName(clientId), opts);
73
+ }
74
+
75
+ export function getRefreshToken(request: FastifyRequest, clientId?: string): string | undefined {
76
+ return request.cookies[refreshCookieName(clientId)];
77
+ }
78
+
79
+ async function resolveUserFromClaims(claims: TokenClaims) {
80
+ const [user] = await db.select().from(users).where(eq(users.id, claims.sub)).limit(1);
81
+ return user;
82
+ }
83
+
84
+ async function resolveApiKeyRecord(key: string) {
85
+ const hash = hashApiKey(key);
86
+ const [keyRecord] = await db
87
+ .select()
88
+ .from(apiKeys)
89
+ .where(and(eq(apiKeys.keyHash, hash), isNull(apiKeys.revokedAt)))
90
+ .limit(1);
91
+ return keyRecord;
92
+ }
93
+
94
+ async function resolveUserFromApiKey(key: string): Promise<{ user: User; scopes: string[] } | undefined> {
95
+ const keyRecord = await resolveApiKeyRecord(key);
96
+ if (!keyRecord) return undefined;
97
+ if (keyRecord.expiresAt && keyRecord.expiresAt < new Date()) return undefined;
98
+
99
+ await db.update(apiKeys).set({ lastUsedAt: new Date() }).where(eq(apiKeys.id, keyRecord.id));
100
+
101
+ if (keyRecord.userId) {
102
+ const [user] = await db.select().from(users).where(eq(users.id, keyRecord.userId)).limit(1);
103
+ if (!user) return undefined;
104
+ return { user, scopes: keyRecord.scopes ?? [] };
105
+ }
106
+
107
+ return undefined;
108
+ }
109
+
110
+ function extractAccessToken(request: FastifyRequest): string | undefined {
111
+ // Prefer the app-specific cookie if an app context is present.
112
+ const appClientId = request.state?.app?.clientId;
113
+ const appCookie = appClientId ? request.cookies[accessCookieName(appClientId)] : undefined;
114
+ if (appCookie) return appCookie;
115
+
116
+ const defaultCookie = request.cookies[DEFAULT_ACCESS_COOKIE];
117
+ if (defaultCookie) return defaultCookie;
118
+
119
+ const header = request.headers.authorization;
120
+ if (header?.startsWith("Bearer ")) return header.slice(7);
121
+ return undefined;
122
+ }
123
+
124
+ export default fp(async function authPlugin(app: FastifyInstance) {
125
+ app.decorate("authenticate", async function authenticate(request, reply) {
126
+ const token = extractAccessToken(request);
127
+ if (!token) {
128
+ return reply.status(401).send({ error: "Unauthorized" });
129
+ }
130
+ try {
131
+ const claims = await verifyAccessToken(token);
132
+ const user = await resolveUserFromClaims(claims);
133
+ if (!user) {
134
+ return reply.status(401).send({ error: "User not found" });
135
+ }
136
+ request.user = user;
137
+ } catch {
138
+ return reply.status(401).send({ error: "Invalid token" });
139
+ }
140
+ });
141
+
142
+ app.decorate("authenticateOrApiKey", async function authenticateOrApiKey(request, reply) {
143
+ const token = extractAccessToken(request);
144
+ if (!token) {
145
+ return reply.status(401).send({ error: "Unauthorized" });
146
+ }
147
+
148
+ try {
149
+ const claims = await verifyAccessToken(token);
150
+ const user = await resolveUserFromClaims(claims);
151
+ if (!user) {
152
+ return reply.status(401).send({ error: "User not found" });
153
+ }
154
+ request.user = user;
155
+ return;
156
+ } catch {
157
+ // Not a valid access token — try API key.
158
+ }
159
+
160
+ const apiKeyUser = await resolveUserFromApiKey(token);
161
+ if (apiKeyUser) {
162
+ request.user = apiKeyUser.user;
163
+ request.apiKeyScopes = apiKeyUser.scopes;
164
+ return;
165
+ }
166
+
167
+ const serviceAccount = await resolveServiceAccountFromApiKey(token);
168
+ if (serviceAccount) {
169
+ request.serviceAccount = serviceAccount;
170
+ request.apiKeyScopes = ["api:read", "api:write", "service_account"];
171
+ // Synthesize a user so existing routes that expect request.user keep working.
172
+ request.user = {
173
+ id: `sa:${serviceAccount.id}`,
174
+ email: `service-account@${serviceAccount.id}.internal`,
175
+ username: `sa-${serviceAccount.id.slice(0, 8)}`,
176
+ name: serviceAccount.name,
177
+ avatarUrl: null,
178
+ emailVerified: true,
179
+ plan: "enterprise",
180
+ role: "service_account",
181
+ provider: "api_key",
182
+ zitadelUserId: null,
183
+ defaultOrgId: serviceAccount.orgId,
184
+ phoneNumber: null,
185
+ phoneVerified: false,
186
+ totpSecret: null,
187
+ totpEnabled: false,
188
+ totpVerifiedAt: null,
189
+ createdAt: serviceAccount.createdAt,
190
+ updatedAt: serviceAccount.updatedAt,
191
+ } as User;
192
+ return;
193
+ }
194
+
195
+ return reply.status(401).send({ error: "Invalid token or API key" });
196
+ });
197
+
198
+ app.decorate("requireScopes", function requireScopes(...required: string[]) {
199
+ return async function scopeCheck(request: FastifyRequest, reply: FastifyReply) {
200
+ // Session-based authentication has full scope access.
201
+ if (!request.apiKeyScopes) return;
202
+ const scopes = request.apiKeyScopes;
203
+ const hasAll = required.every((scope) => scopes.includes(scope) || scopes.includes("service_account"));
204
+ if (!hasAll) {
205
+ return reply.status(403).send({ error: "Insufficient API key scope", required });
206
+ }
207
+ };
208
+ });
209
+ });
210
+
211
+ async function resolveServiceAccountFromApiKey(key: string) {
212
+ const hash = hashApiKey(key);
213
+ const [keyRecord] = await db
214
+ .select()
215
+ .from(apiKeys)
216
+ .where(and(eq(apiKeys.keyHash, hash), isNull(apiKeys.revokedAt)))
217
+ .limit(1);
218
+
219
+ if (!keyRecord) return undefined;
220
+ if (keyRecord.expiresAt && keyRecord.expiresAt < new Date()) return undefined;
221
+ if (!keyRecord.serviceAccountId) return undefined;
222
+
223
+ await db.update(apiKeys).set({ lastUsedAt: new Date() }).where(eq(apiKeys.id, keyRecord.id));
224
+ const [account] = await db
225
+ .select()
226
+ .from(serviceAccounts)
227
+ .where(and(eq(serviceAccounts.id, keyRecord.serviceAccountId), eq(serviceAccounts.isActive, true)))
228
+ .limit(1);
229
+ return account;
230
+ }
@@ -0,0 +1,41 @@
1
+ import fp from "fastify-plugin";
2
+ import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
3
+ import { register, Counter, Histogram } from "prom-client";
4
+
5
+ export const httpRequestsTotal = new Counter({
6
+ name: "keystone_http_requests_total",
7
+ help: "Total HTTP requests",
8
+ labelNames: ["method", "route", "status_code"],
9
+ });
10
+
11
+ export const httpRequestDurationSeconds = new Histogram({
12
+ name: "keystone_http_request_duration_seconds",
13
+ help: "HTTP request duration in seconds",
14
+ labelNames: ["method", "route", "status_code"],
15
+ buckets: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
16
+ });
17
+
18
+ export const failedLoginsTotal = new Counter({
19
+ name: "keystone_failed_logins_total",
20
+ help: "Total failed login attempts",
21
+ labelNames: ["reason"],
22
+ });
23
+
24
+ export default fp(async function metricsPlugin(app: FastifyInstance) {
25
+ app.addHook("onResponse", async (request: FastifyRequest, reply: FastifyReply) => {
26
+ const route = (request as unknown as { routeOptions?: { url?: string } }).routeOptions?.url || request.url;
27
+ const labels = {
28
+ method: request.method,
29
+ route,
30
+ status_code: String(reply.statusCode),
31
+ };
32
+ httpRequestsTotal.inc(labels);
33
+ const elapsedMs = (reply as unknown as { elapsedTime?: number }).elapsedTime ?? 0;
34
+ httpRequestDurationSeconds.observe(labels, elapsedMs / 1000);
35
+ });
36
+
37
+ app.get("/metrics", async (_request: FastifyRequest, reply: FastifyReply) => {
38
+ reply.header("Content-Type", register.contentType);
39
+ return register.metrics();
40
+ });
41
+ });
@@ -0,0 +1,94 @@
1
+ import fp from "fastify-plugin";
2
+ import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
3
+ import { eq } from "drizzle-orm";
4
+ import { db } from "../db/index.js";
5
+ import { serviceAccounts } from "../db/schema.js";
6
+
7
+ /**
8
+ * mTLS authentication plugin.
9
+ *
10
+ * In production, terminate TLS at a reverse proxy (nginx, envoy, AWS ALB, etc.)
11
+ * that validates the client certificate and forwards the certificate fingerprint
12
+ * or subject in a trusted header. This plugin reads that header and maps
13
+ * certificates to service accounts.
14
+ *
15
+ * Headers read:
16
+ * - x-client-cert-fingerprint: SHA-256 fingerprint of the client certificate
17
+ * - x-forwarded-client-cert: PEM-encoded client certificate or DN subject
18
+ * - x-service-account-id: Optional explicit service account ID (for non-mTLS fallback)
19
+ */
20
+
21
+ const MTLS_HEADER = "x-forwarded-client-cert";
22
+ const MTLS_FINGERPRINT_HEADER = "x-client-cert-fingerprint";
23
+ const SERVICE_ACCOUNT_ID_HEADER = "x-service-account-id";
24
+
25
+ declare module "fastify" {
26
+ interface FastifyInstance {
27
+ requireMTLS: (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
28
+ }
29
+ }
30
+
31
+ export function extractClientCert(request: FastifyRequest): { fingerprint?: string; subject?: string } {
32
+ const fingerprint = request.headers[MTLS_FINGERPRINT_HEADER];
33
+ const cert = request.headers[MTLS_HEADER];
34
+ return {
35
+ fingerprint: typeof fingerprint === "string" ? fingerprint : undefined,
36
+ subject: typeof cert === "string" ? cert : undefined,
37
+ };
38
+ }
39
+
40
+ async function resolveServiceAccount(request: FastifyRequest): Promise<typeof serviceAccounts.$inferSelect | undefined> {
41
+ const explicitId = request.headers[SERVICE_ACCOUNT_ID_HEADER];
42
+ if (typeof explicitId === "string" && explicitId) {
43
+ const [sa] = await db
44
+ .select()
45
+ .from(serviceAccounts)
46
+ .where(eq(serviceAccounts.id, explicitId))
47
+ .limit(1);
48
+ if (sa?.isActive) {
49
+ return sa;
50
+ }
51
+ }
52
+
53
+ const { fingerprint, subject } = extractClientCert(request);
54
+ if (!fingerprint && !subject) return undefined;
55
+
56
+ // Look up service accounts by name matching the fingerprint or subject.
57
+ // In a production system, you would store the certificate fingerprint in
58
+ // the service_accounts table and query by it directly.
59
+ const [sa] = await db
60
+ .select()
61
+ .from(serviceAccounts)
62
+ .where(eq(serviceAccounts.name, fingerprint || subject || ""))
63
+ .limit(1);
64
+
65
+ if (sa?.isActive) {
66
+ return sa;
67
+ }
68
+
69
+ return undefined;
70
+ }
71
+
72
+ export function requireMTLS() {
73
+ return async function (request: FastifyRequest, reply: FastifyReply) {
74
+ const { fingerprint, subject } = extractClientCert(request);
75
+ const explicitId = request.headers[SERVICE_ACCOUNT_ID_HEADER];
76
+
77
+ if (!fingerprint && !subject && !explicitId) {
78
+ return reply.status(401).send({ error: "Client certificate required" });
79
+ }
80
+
81
+ const serviceAccount = await resolveServiceAccount(request);
82
+ if (!serviceAccount) {
83
+ request.log.warn({ fingerprint, subject }, "mTLS: no matching service account found");
84
+ return reply.status(403).send({ error: "Client certificate not mapped to a service account" });
85
+ }
86
+
87
+ request.serviceAccount = serviceAccount;
88
+ request.log.debug({ serviceAccountId: serviceAccount.id }, "mTLS: service account authenticated");
89
+ };
90
+ }
91
+
92
+ export default fp(async function mtlsPlugin(app: FastifyInstance) {
93
+ app.decorate("requireMTLS", requireMTLS());
94
+ });
@@ -0,0 +1,29 @@
1
+ import fp from "fastify-plugin";
2
+ import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
3
+ import { requirePermission, hasPermission, type PermissionInput } from "../services/permissions.js";
4
+
5
+ declare module "fastify" {
6
+ interface FastifyInstance {
7
+ requirePermission: (resource: string, action: string) => (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
8
+ }
9
+ }
10
+
11
+ export default fp(async function permissionsPlugin(app: FastifyInstance) {
12
+ app.decorate(
13
+ "requirePermission",
14
+ function (resource: string, action: string) {
15
+ return async function (request: FastifyRequest, reply: FastifyReply) {
16
+ const membership = request.state?.membership;
17
+ if (!membership) {
18
+ return reply.status(403).send({ error: "Organization membership required" });
19
+ }
20
+ try {
21
+ await requirePermission(membership.role, resource, action);
22
+ } catch (err) {
23
+ const message = err instanceof Error ? err.message : "Forbidden";
24
+ return reply.status(403).send({ error: message });
25
+ }
26
+ };
27
+ }
28
+ );
29
+ });