@sixb/core 0.1.12 → 0.1.13

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 (527) hide show
  1. package/dist/actions/index.d.ts +2 -2
  2. package/dist/actions/index.d.ts.map +1 -1
  3. package/dist/actions/index.js +28 -26
  4. package/dist/actions/index.js.map +1 -1
  5. package/dist/actions/read-facade.d.ts +14 -16
  6. package/dist/actions/read-facade.d.ts.map +1 -1
  7. package/dist/actions/request.d.ts.map +1 -1
  8. package/dist/actions/run-dispatch.d.ts +2 -0
  9. package/dist/actions/run-dispatch.d.ts.map +1 -1
  10. package/dist/actions/types/context.d.ts +18 -31
  11. package/dist/actions/types/context.d.ts.map +1 -1
  12. package/dist/actions/types/params.d.ts +2 -1
  13. package/dist/actions/types/params.d.ts.map +1 -1
  14. package/dist/actions/worker.js +1 -1
  15. package/dist/agents/index.js +41 -39
  16. package/dist/agents/index.js.map +1 -1
  17. package/dist/agents/streams/index.js +2 -2
  18. package/dist/agents/streams/internal.js +2 -2
  19. package/dist/assert-never.d.ts +6 -0
  20. package/dist/assert-never.d.ts.map +1 -0
  21. package/dist/auth/client-address.d.ts +3 -0
  22. package/dist/auth/client-address.d.ts.map +1 -0
  23. package/dist/auth/csrf.d.ts +5 -1
  24. package/dist/auth/csrf.d.ts.map +1 -1
  25. package/dist/auth/index.d.ts +3 -2
  26. package/dist/auth/index.d.ts.map +1 -1
  27. package/dist/auth/index.js +14 -8
  28. package/dist/auth/index.js.map +1 -1
  29. package/dist/auth/runtime.d.ts +58 -41
  30. package/dist/auth/runtime.d.ts.map +1 -1
  31. package/dist/auth/session-cache.d.ts +10 -3
  32. package/dist/auth/session-cache.d.ts.map +1 -1
  33. package/dist/auth/sessions.d.ts +12 -0
  34. package/dist/auth/sessions.d.ts.map +1 -1
  35. package/dist/auth/strategy.js +1 -1
  36. package/dist/auth/types.d.ts +8 -15
  37. package/dist/auth/types.d.ts.map +1 -1
  38. package/dist/authorization/index.js +3 -3
  39. package/dist/bootstrap/index.d.ts +1 -1
  40. package/dist/bootstrap/index.d.ts.map +1 -1
  41. package/dist/bootstrap/index.js +45 -43
  42. package/dist/bootstrap/index.js.map +1 -1
  43. package/dist/bootstrap/ontology-type-manifest.d.ts +8 -0
  44. package/dist/bootstrap/ontology-type-manifest.d.ts.map +1 -1
  45. package/dist/{chunk-q5gz3g2j.js → chunk-0321g649.js} +2 -16
  46. package/dist/{chunk-q5gz3g2j.js.map → chunk-0321g649.js.map} +2 -2
  47. package/dist/{chunk-e1f1sqba.js → chunk-04h4t2b5.js} +3 -3
  48. package/dist/{chunk-y3ev53cq.js → chunk-2fv8sajb.js} +2 -2
  49. package/dist/{chunk-3bnt2wna.js → chunk-2hbhn1ff.js} +1 -1
  50. package/dist/{chunk-eyjzgav0.js → chunk-3nx8vj5a.js} +6 -4
  51. package/dist/chunk-3nx8vj5a.js.map +12 -0
  52. package/dist/{chunk-5tetw4hn.js → chunk-4tnrzqqh.js} +1 -1
  53. package/dist/{chunk-g50nxqs5.js → chunk-63fp9x3q.js} +63 -20
  54. package/dist/chunk-63fp9x3q.js.map +20 -0
  55. package/dist/{chunk-qm535afa.js → chunk-693f3zn8.js} +66 -24
  56. package/dist/chunk-693f3zn8.js.map +15 -0
  57. package/dist/{chunk-7zgecwy1.js → chunk-6x0pqh32.js} +12 -1
  58. package/dist/{chunk-7zgecwy1.js.map → chunk-6x0pqh32.js.map} +3 -3
  59. package/dist/{chunk-6ma8dvzc.js → chunk-898y24dd.js} +49 -42
  60. package/dist/chunk-898y24dd.js.map +15 -0
  61. package/dist/{chunk-7qnvhtcd.js → chunk-91wthfwe.js} +17 -17
  62. package/dist/{chunk-7qnvhtcd.js.map → chunk-91wthfwe.js.map} +5 -5
  63. package/dist/chunk-96yw3pwd.js.map +2 -2
  64. package/dist/{chunk-2cxv584m.js → chunk-9pfw47qx.js} +309 -204
  65. package/dist/chunk-9pfw47qx.js.map +44 -0
  66. package/dist/{chunk-4k53sm9e.js → chunk-a0073121.js} +59 -59
  67. package/dist/{chunk-4k53sm9e.js.map → chunk-a0073121.js.map} +5 -5
  68. package/dist/{chunk-jjwhy3rs.js → chunk-a69fkrtr.js} +5 -5
  69. package/dist/{chunk-y1ahv8b7.js → chunk-bdhfn0ww.js} +1 -1
  70. package/dist/{chunk-4ph94nhd.js → chunk-bep5rrdq.js} +2 -2
  71. package/dist/{chunk-kept9cdd.js → chunk-bxx3ms5t.js} +1 -1
  72. package/dist/{chunk-xtfryrfb.js → chunk-cbn96bve.js} +2 -2
  73. package/dist/{chunk-nzsy3xrp.js → chunk-cvrbhvtr.js} +69 -44
  74. package/dist/{chunk-nzsy3xrp.js.map → chunk-cvrbhvtr.js.map} +7 -7
  75. package/dist/{chunk-vsg0g7h9.js → chunk-d8yes9yx.js} +304 -45
  76. package/dist/chunk-d8yes9yx.js.map +20 -0
  77. package/dist/{chunk-tg4g4zh0.js → chunk-darm7eeg.js} +9 -9
  78. package/dist/{chunk-tg4g4zh0.js.map → chunk-darm7eeg.js.map} +3 -3
  79. package/dist/{chunk-vpxss818.js → chunk-drz59ve0.js} +9 -8
  80. package/dist/chunk-drz59ve0.js.map +10 -0
  81. package/dist/{chunk-7c2g3sz9.js → chunk-dsfw1bdr.js} +5 -5
  82. package/dist/{chunk-7c2g3sz9.js.map → chunk-dsfw1bdr.js.map} +1 -1
  83. package/dist/{chunk-p6r1ex7t.js → chunk-ffwvdgk1.js} +5 -13
  84. package/dist/chunk-ffwvdgk1.js.map +10 -0
  85. package/dist/{chunk-r5zythxp.js → chunk-gbcrz0gr.js} +7 -7
  86. package/dist/{chunk-ybhz3j9g.js → chunk-gc226ten.js} +104 -148
  87. package/dist/{chunk-ybhz3j9g.js.map → chunk-gc226ten.js.map} +7 -8
  88. package/dist/{chunk-3ghw2t5q.js → chunk-gmt22nxx.js} +10 -16
  89. package/dist/chunk-gmt22nxx.js.map +10 -0
  90. package/dist/chunk-h89wz928.js +42 -0
  91. package/dist/chunk-h89wz928.js.map +10 -0
  92. package/dist/{chunk-hkw8rykk.js → chunk-ht4a7mjg.js} +74 -4
  93. package/dist/chunk-ht4a7mjg.js.map +15 -0
  94. package/dist/{chunk-t7dzd1tm.js → chunk-jhyc777j.js} +2 -2
  95. package/dist/{chunk-xn686q2e.js → chunk-jmwy25mf.js} +75 -57
  96. package/dist/{chunk-xn686q2e.js.map → chunk-jmwy25mf.js.map} +3 -3
  97. package/dist/{chunk-f06sf7rr.js → chunk-k4kkp58d.js} +18 -5
  98. package/dist/chunk-k4kkp58d.js.map +11 -0
  99. package/dist/{chunk-2h63nrde.js → chunk-ky7zpbtt.js} +5 -7
  100. package/dist/{chunk-2h63nrde.js.map → chunk-ky7zpbtt.js.map} +3 -4
  101. package/dist/chunk-m4ehq95f.js +9 -0
  102. package/dist/chunk-m4ehq95f.js.map +10 -0
  103. package/dist/{chunk-0mza4xb2.js → chunk-m8zkvep1.js} +2 -2
  104. package/dist/{chunk-b768c93y.js → chunk-mf6hwpzh.js} +83 -28
  105. package/dist/{chunk-b768c93y.js.map → chunk-mf6hwpzh.js.map} +5 -5
  106. package/dist/{chunk-yxb4c62x.js → chunk-mr60an99.js} +3 -2
  107. package/dist/{chunk-yxb4c62x.js.map → chunk-mr60an99.js.map} +3 -3
  108. package/dist/chunk-n33e8dz8.js +191 -0
  109. package/dist/chunk-n33e8dz8.js.map +11 -0
  110. package/dist/chunk-rdghfsss.js.map +2 -2
  111. package/dist/{chunk-m7cx05vp.js → chunk-rqtdtm43.js} +126 -59
  112. package/dist/{chunk-m7cx05vp.js.map → chunk-rqtdtm43.js.map} +13 -12
  113. package/dist/{chunk-bbaa1fet.js → chunk-rzcjp5m2.js} +7 -3
  114. package/dist/chunk-rzcjp5m2.js.map +25 -0
  115. package/dist/{chunk-hzw7yv5g.js → chunk-rzkr70gr.js} +5 -1
  116. package/dist/{chunk-hzw7yv5g.js.map → chunk-rzkr70gr.js.map} +3 -3
  117. package/dist/{chunk-sfypc7mk.js → chunk-s24qbp32.js} +4 -4
  118. package/dist/{chunk-axndsymr.js → chunk-tw03bsmb.js} +2 -2
  119. package/dist/{chunk-axndsymr.js.map → chunk-tw03bsmb.js.map} +3 -3
  120. package/dist/{chunk-y0v18c2j.js → chunk-vef6qa14.js} +2 -2
  121. package/dist/{chunk-gzt6v1ja.js → chunk-vn3yh259.js} +1 -1
  122. package/dist/{chunk-bg2bs62d.js → chunk-w9bp61e7.js} +5 -5
  123. package/dist/{chunk-3h7ctayx.js → chunk-xgptywp0.js} +4 -3
  124. package/dist/chunk-xgptywp0.js.map +11 -0
  125. package/dist/{chunk-gswwr35f.js → chunk-y487ywrv.js} +4 -4
  126. package/dist/{chunk-bet1rb9h.js → chunk-y6vnvayj.js} +1 -1
  127. package/dist/{chunk-x9tmx3fc.js → chunk-ypj2wqtj.js} +3 -6
  128. package/dist/{chunk-x9tmx3fc.js.map → chunk-ypj2wqtj.js.map} +4 -4
  129. package/dist/{chunk-g2gezsg5.js → chunk-z9h698s8.js} +1 -1
  130. package/dist/{chunk-wjffn5m4.js → chunk-zdkcdshk.js} +3 -36
  131. package/dist/{chunk-wjffn5m4.js.map → chunk-zdkcdshk.js.map} +3 -4
  132. package/dist/{chunk-bfjv1adk.js → chunk-znw0zvy4.js} +1 -1
  133. package/dist/edits/types.d.ts +19 -19
  134. package/dist/edits/types.d.ts.map +1 -1
  135. package/dist/error-reporting/internal.js +3 -3
  136. package/dist/errors/catalog.d.ts +4 -0
  137. package/dist/errors/catalog.d.ts.map +1 -1
  138. package/dist/errors/internal.js +1 -1
  139. package/dist/events/envelope.d.ts +0 -12
  140. package/dist/events/envelope.d.ts.map +1 -1
  141. package/dist/events/index.d.ts +1 -1
  142. package/dist/events/index.d.ts.map +1 -1
  143. package/dist/events/index.js +3 -3
  144. package/dist/events/service.d.ts +1 -2
  145. package/dist/events/service.d.ts.map +1 -1
  146. package/dist/events/toStoredEvent.d.ts +1 -2
  147. package/dist/events/toStoredEvent.d.ts.map +1 -1
  148. package/dist/events/types/index.d.ts +2 -1
  149. package/dist/events/types/index.d.ts.map +1 -1
  150. package/dist/execution/agent.d.ts +1 -2
  151. package/dist/execution/agent.d.ts.map +1 -1
  152. package/dist/execution/agent.js +39 -37
  153. package/dist/execution/agent.js.map +1 -1
  154. package/dist/execution/authorized-object-reader.d.ts.map +1 -1
  155. package/dist/execution/primitive.d.ts +1 -2
  156. package/dist/execution/primitive.d.ts.map +1 -1
  157. package/dist/execution/primitive.js +38 -36
  158. package/dist/execution/primitive.js.map +3 -3
  159. package/dist/execution/request.d.ts +1 -2
  160. package/dist/execution/request.d.ts.map +1 -1
  161. package/dist/execution/request.js +39 -37
  162. package/dist/execution/request.js.map +3 -3
  163. package/dist/index.d.ts +6 -6
  164. package/dist/index.d.ts.map +1 -1
  165. package/dist/index.js +56 -50
  166. package/dist/index.js.map +1 -1
  167. package/dist/maintenance/ontology-maintenance.d.ts +11 -1
  168. package/dist/maintenance/ontology-maintenance.d.ts.map +1 -1
  169. package/dist/materialization/errors.d.ts +3 -1
  170. package/dist/materialization/errors.d.ts.map +1 -1
  171. package/dist/materialization/events.d.ts +27 -2
  172. package/dist/materialization/events.d.ts.map +1 -1
  173. package/dist/materializer/edits/commit.d.ts.map +1 -1
  174. package/dist/materializer/edits/operations.d.ts +2 -1
  175. package/dist/materializer/edits/operations.d.ts.map +1 -1
  176. package/dist/materializer/edits/plan.d.ts +2 -2
  177. package/dist/materializer/edits/plan.d.ts.map +1 -1
  178. package/dist/materializer/edits/user-refs.d.ts +30 -0
  179. package/dist/materializer/edits/user-refs.d.ts.map +1 -0
  180. package/dist/materializer/effective/build-events.d.ts +2 -2
  181. package/dist/materializer/effective/build-events.d.ts.map +1 -1
  182. package/dist/materializer/execution/scope.d.ts +11 -3
  183. package/dist/materializer/execution/scope.d.ts.map +1 -1
  184. package/dist/materializer/index.js +23 -21
  185. package/dist/materializer/index.js.map +1 -1
  186. package/dist/materializer/projections/replacement-plan.d.ts +2 -0
  187. package/dist/materializer/projections/replacement-plan.d.ts.map +1 -1
  188. package/dist/materializer/telemetry/plan.d.ts +2 -2
  189. package/dist/materializer/telemetry/plan.d.ts.map +1 -1
  190. package/dist/models/execution/index.js +23 -21
  191. package/dist/models/execution/index.js.map +1 -1
  192. package/dist/models/index.js +1 -1
  193. package/dist/objects/execution.d.ts +21 -27
  194. package/dist/objects/execution.d.ts.map +1 -1
  195. package/dist/objects/index.js +28 -26
  196. package/dist/objects/index.js.map +1 -1
  197. package/dist/objects/query/executor.d.ts.map +1 -1
  198. package/dist/objects/query/index.js +27 -25
  199. package/dist/objects/query/index.js.map +1 -1
  200. package/dist/objects/query/ir.d.ts +8 -1
  201. package/dist/objects/query/ir.d.ts.map +1 -1
  202. package/dist/objects/query/scalar-values.d.ts.map +1 -1
  203. package/dist/objects/query/validate.d.ts.map +1 -1
  204. package/dist/objects/sdk/object-handle.d.ts +1 -2
  205. package/dist/objects/sdk/object-handle.d.ts.map +1 -1
  206. package/dist/objects/sdk/object-set.d.ts +2 -3
  207. package/dist/objects/sdk/object-set.d.ts.map +1 -1
  208. package/dist/objects/sdk/query-builder.d.ts +8 -10
  209. package/dist/objects/sdk/query-builder.d.ts.map +1 -1
  210. package/dist/objects/sdk/telemetry-channel.d.ts +1 -2
  211. package/dist/objects/sdk/telemetry-channel.d.ts.map +1 -1
  212. package/dist/objects/sdk/where.d.ts +2 -3
  213. package/dist/objects/sdk/where.d.ts.map +1 -1
  214. package/dist/ontology/builders.d.ts +11 -10
  215. package/dist/ontology/builders.d.ts.map +1 -1
  216. package/dist/ontology/index.d.ts +4 -2
  217. package/dist/ontology/index.d.ts.map +1 -1
  218. package/dist/ontology/index.js +6 -4
  219. package/dist/ontology/index.js.map +1 -1
  220. package/dist/ontology/inference/index.d.ts +34 -22
  221. package/dist/ontology/inference/index.d.ts.map +1 -1
  222. package/dist/ontology/internal.d.ts +1 -0
  223. package/dist/ontology/internal.d.ts.map +1 -1
  224. package/dist/ontology/internal.js +9 -7
  225. package/dist/ontology/internal.js.map +1 -1
  226. package/dist/ontology/primitives.d.ts +38 -0
  227. package/dist/ontology/primitives.d.ts.map +1 -0
  228. package/dist/ontology/query-capabilities.d.ts +38 -0
  229. package/dist/ontology/query-capabilities.d.ts.map +1 -0
  230. package/dist/ontology/refs.d.ts +23 -2
  231. package/dist/ontology/refs.d.ts.map +1 -1
  232. package/dist/ontology/registered.d.ts +16 -0
  233. package/dist/ontology/registered.d.ts.map +1 -0
  234. package/dist/ontology/registry.d.ts.map +1 -1
  235. package/dist/ontology/tokens.d.ts +35 -1
  236. package/dist/ontology/tokens.d.ts.map +1 -1
  237. package/dist/ontology/types.d.ts +18 -4
  238. package/dist/ontology/types.d.ts.map +1 -1
  239. package/dist/ontology/user-ref.d.ts +35 -0
  240. package/dist/ontology/user-ref.d.ts.map +1 -0
  241. package/dist/ontology/validation/definition.d.ts.map +1 -1
  242. package/dist/ontology/validation/index.d.ts +1 -1
  243. package/dist/ontology/validation/index.d.ts.map +1 -1
  244. package/dist/ontology/validation/normalize.d.ts.map +1 -1
  245. package/dist/ontology/validation/properties.d.ts +6 -1
  246. package/dist/ontology/validation/properties.d.ts.map +1 -1
  247. package/dist/ontology/validation/query.d.ts.map +1 -1
  248. package/dist/ontology/validation/schema.d.ts.map +1 -1
  249. package/dist/pipelines/index.js +26 -24
  250. package/dist/pipelines/index.js.map +1 -1
  251. package/dist/predicates/types.d.ts +53 -3
  252. package/dist/predicates/types.d.ts.map +1 -1
  253. package/dist/projections/builders.d.ts +19 -1
  254. package/dist/projections/builders.d.ts.map +1 -1
  255. package/dist/projections/internal.js +23 -21
  256. package/dist/projections/internal.js.map +1 -1
  257. package/dist/projections/validation.d.ts.map +1 -1
  258. package/dist/query.js +2 -2
  259. package/dist/queues/in-memory.d.ts +1 -1
  260. package/dist/queues/in-memory.d.ts.map +1 -1
  261. package/dist/runtime/create.d.ts +1 -1
  262. package/dist/runtime/create.d.ts.map +1 -1
  263. package/dist/runtime/host.d.ts +5 -5
  264. package/dist/runtime/host.d.ts.map +1 -1
  265. package/dist/runtime/index.d.ts +1 -1
  266. package/dist/runtime/index.d.ts.map +1 -1
  267. package/dist/runtime/internal.js +27 -25
  268. package/dist/runtime/internal.js.map +1 -1
  269. package/dist/runtime/sixb.d.ts +5 -5
  270. package/dist/runtime/sixb.d.ts.map +1 -1
  271. package/dist/runtime/types.d.ts +171 -188
  272. package/dist/runtime/types.d.ts.map +1 -1
  273. package/dist/sandboxes/index.js +5 -5
  274. package/dist/sandboxes/sandbox.d.ts +4 -1
  275. package/dist/sandboxes/sandbox.d.ts.map +1 -1
  276. package/dist/shared/params/types.d.ts +4 -3
  277. package/dist/shared/params/types.d.ts.map +1 -1
  278. package/dist/shared/params/user-refs.d.ts +19 -0
  279. package/dist/shared/params/user-refs.d.ts.map +1 -0
  280. package/dist/shares/compiler.d.ts.map +1 -1
  281. package/dist/shares/internal.js +24 -22
  282. package/dist/shares/internal.js.map +2 -2
  283. package/dist/storage/action-runs/failure.js +2 -2
  284. package/dist/storage/action-runs/types.d.ts +1 -1
  285. package/dist/storage/action-runs/types.d.ts.map +1 -1
  286. package/dist/storage/agents/provider.js +1 -1
  287. package/dist/storage/ai-limits/enforcement.js +2 -2
  288. package/dist/storage/auth/in-memory/access-tokens.d.ts.map +1 -1
  289. package/dist/storage/auth/in-memory/auth-storage.d.ts.map +1 -1
  290. package/dist/storage/auth/in-memory/device-authorizations.d.ts.map +1 -1
  291. package/dist/storage/auth/in-memory/sessions.d.ts +8 -1
  292. package/dist/storage/auth/in-memory/sessions.d.ts.map +1 -1
  293. package/dist/storage/auth/in-memory/shared.d.ts.map +1 -1
  294. package/dist/storage/auth/index.d.ts +1 -1
  295. package/dist/storage/auth/index.d.ts.map +1 -1
  296. package/dist/storage/auth/types.d.ts +62 -13
  297. package/dist/storage/auth/types.d.ts.map +1 -1
  298. package/dist/storage/connector-connections/provider.js +1 -1
  299. package/dist/storage/executions/provider.js +1 -1
  300. package/dist/storage/file-upload-sessions/in-memory.d.ts +9 -18
  301. package/dist/storage/file-upload-sessions/in-memory.d.ts.map +1 -1
  302. package/dist/storage/file-upload-sessions/index.d.ts +1 -1
  303. package/dist/storage/file-upload-sessions/index.d.ts.map +1 -1
  304. package/dist/storage/file-upload-sessions/provider.d.ts +52 -0
  305. package/dist/storage/file-upload-sessions/provider.d.ts.map +1 -0
  306. package/dist/storage/file-upload-sessions/provider.js +24 -0
  307. package/dist/storage/file-upload-sessions/provider.js.map +9 -0
  308. package/dist/storage/file-upload-sessions/types.d.ts +19 -1
  309. package/dist/storage/file-upload-sessions/types.d.ts.map +1 -1
  310. package/dist/storage/file-upload-sessions/utils.d.ts +8 -2
  311. package/dist/storage/file-upload-sessions/utils.d.ts.map +1 -1
  312. package/dist/storage/index.d.ts +3 -3
  313. package/dist/storage/index.d.ts.map +1 -1
  314. package/dist/storage/index.js +29 -25
  315. package/dist/storage/index.js.map +1 -1
  316. package/dist/storage/internal.js +11 -9
  317. package/dist/storage/internal.js.map +1 -1
  318. package/dist/storage/objects/in-memory/query.d.ts.map +1 -1
  319. package/dist/storage/ontology/commits.d.ts +6 -2
  320. package/dist/storage/ontology/commits.d.ts.map +1 -1
  321. package/dist/storage/ontology/in-memory/materializations.d.ts.map +1 -1
  322. package/dist/storage/ontology/provider-work.d.ts.map +1 -1
  323. package/dist/storage/ontology/provider.d.ts +14 -1
  324. package/dist/storage/ontology/provider.d.ts.map +1 -1
  325. package/dist/storage/ontology/provider.js +8 -2
  326. package/dist/storage/ontology/provider.js.map +1 -1
  327. package/dist/storage/operation-scope.d.ts.map +1 -1
  328. package/dist/storage/operation-scope.js +1 -1
  329. package/dist/storage/projection-runs/provider.js +2 -2
  330. package/dist/storage/types.d.ts +1 -1
  331. package/dist/storage/types.d.ts.map +1 -1
  332. package/dist/storage/workflow-interventions/index.d.ts +1 -1
  333. package/dist/storage/workflow-interventions/index.d.ts.map +1 -1
  334. package/dist/storage/workflow-interventions/types.d.ts +5 -8
  335. package/dist/storage/workflow-interventions/types.d.ts.map +1 -1
  336. package/dist/storage/workflow-runs/provider.js +8 -8
  337. package/dist/syncs/index.js +27 -25
  338. package/dist/syncs/index.js.map +1 -1
  339. package/dist/testing/action-execution.d.ts +4 -0
  340. package/dist/testing/action-execution.d.ts.map +1 -1
  341. package/dist/testing/auth-storage-contract.d.ts.map +1 -1
  342. package/dist/testing/execution.d.ts +1 -2
  343. package/dist/testing/execution.d.ts.map +1 -1
  344. package/dist/testing/file-upload-session-storage-contract.d.ts +12 -0
  345. package/dist/testing/file-upload-session-storage-contract.d.ts.map +1 -0
  346. package/dist/testing/index.d.ts +2 -0
  347. package/dist/testing/index.d.ts.map +1 -1
  348. package/dist/testing/index.js +1951 -1242
  349. package/dist/testing/index.js.map +15 -13
  350. package/dist/testing/materializer-storage-contract.d.ts.map +1 -1
  351. package/dist/testing/object-query-contract.d.ts.map +1 -1
  352. package/dist/testing/ontology-contract-fixture.d.ts +8 -0
  353. package/dist/testing/ontology-contract-fixture.d.ts.map +1 -1
  354. package/dist/testing/ontology-storage-contract.d.ts.map +1 -1
  355. package/dist/testing/sandboxes-contract.d.ts.map +1 -1
  356. package/dist/testing/workflow-intervention-storage-contract.d.ts +8 -0
  357. package/dist/testing/workflow-intervention-storage-contract.d.ts.map +1 -0
  358. package/dist/webhooks/internal.js +24 -22
  359. package/dist/webhooks/internal.js.map +2 -2
  360. package/dist/webhooks/types.d.ts +2 -2
  361. package/dist/webhooks/types.d.ts.map +1 -1
  362. package/dist/workers/index.js +1 -1
  363. package/dist/workflows/index.js +42 -40
  364. package/dist/workflows/index.js.map +1 -1
  365. package/dist/workflows/run-dispatch.d.ts.map +1 -1
  366. package/dist/workflows/types.d.ts +2 -2
  367. package/dist/workflows/types.d.ts.map +1 -1
  368. package/package.json +7 -1
  369. package/src/actions/index.ts +0 -3
  370. package/src/actions/read-facade.ts +102 -62
  371. package/src/actions/request.ts +13 -0
  372. package/src/actions/run-dispatch.ts +3 -0
  373. package/src/actions/types/context.ts +17 -65
  374. package/src/actions/types/params.ts +2 -1
  375. package/src/agents/authority.ts +1 -1
  376. package/src/assert-never.ts +7 -0
  377. package/src/auth/client-address.ts +12 -0
  378. package/src/auth/csrf.ts +14 -5
  379. package/src/auth/index.ts +3 -2
  380. package/src/auth/runtime.ts +299 -277
  381. package/src/auth/session-cache.ts +18 -6
  382. package/src/auth/sessions.ts +30 -0
  383. package/src/auth/types.ts +7 -17
  384. package/src/bootstrap/index.ts +1 -0
  385. package/src/bootstrap/ontology-type-manifest.ts +112 -60
  386. package/src/edits/types.ts +47 -63
  387. package/src/errors/catalog.ts +4 -0
  388. package/src/events/envelope.ts +0 -13
  389. package/src/events/index.ts +1 -1
  390. package/src/events/service.ts +1 -11
  391. package/src/events/toStoredEvent.ts +1 -3
  392. package/src/events/types/index.ts +1 -1
  393. package/src/execution/agent.ts +1 -2
  394. package/src/execution/authorized-object-reader.ts +5 -7
  395. package/src/execution/primitive.ts +1 -2
  396. package/src/execution/request.ts +1 -2
  397. package/src/index.ts +8 -7
  398. package/src/maintenance/ontology-maintenance.ts +77 -1
  399. package/src/materialization/errors.ts +2 -0
  400. package/src/materialization/events.ts +27 -2
  401. package/src/materializer/README.md +2 -0
  402. package/src/materializer/edits/commit.ts +21 -12
  403. package/src/materializer/edits/operations.ts +32 -4
  404. package/src/materializer/edits/plan.ts +4 -5
  405. package/src/materializer/edits/user-refs.ts +115 -0
  406. package/src/materializer/effective/build-events.ts +4 -5
  407. package/src/materializer/execution/scope.ts +40 -7
  408. package/src/materializer/projections/replace.ts +2 -0
  409. package/src/materializer/projections/replacement-plan.ts +4 -0
  410. package/src/materializer/telemetry/append.ts +4 -12
  411. package/src/materializer/telemetry/plan.ts +4 -5
  412. package/src/objects/execution.ts +33 -62
  413. package/src/objects/query/executor.ts +12 -3
  414. package/src/objects/query/ir.ts +7 -0
  415. package/src/objects/query/planner.ts +1 -0
  416. package/src/objects/query/scalar-values.ts +19 -0
  417. package/src/objects/query/validate.ts +55 -44
  418. package/src/objects/sdk/object-handle.ts +8 -8
  419. package/src/objects/sdk/object-set.ts +8 -15
  420. package/src/objects/sdk/query-builder.ts +59 -71
  421. package/src/objects/sdk/telemetry-channel.ts +6 -7
  422. package/src/objects/sdk/where.ts +6 -13
  423. package/src/ontology/builders.ts +15 -11
  424. package/src/ontology/index.ts +4 -0
  425. package/src/ontology/inference/index.ts +56 -36
  426. package/src/ontology/internal.ts +1 -0
  427. package/src/ontology/json-schema.ts +12 -0
  428. package/src/ontology/primitives.ts +91 -0
  429. package/src/ontology/query-capabilities.ts +136 -0
  430. package/src/ontology/refs.ts +33 -6
  431. package/src/ontology/registered.ts +22 -0
  432. package/src/ontology/registry.ts +6 -3
  433. package/src/ontology/tokens.ts +41 -2
  434. package/src/ontology/types.ts +19 -3
  435. package/src/ontology/user-ref.ts +120 -0
  436. package/src/ontology/validation/definition.ts +2 -13
  437. package/src/ontology/validation/index.ts +1 -0
  438. package/src/ontology/validation/normalize.ts +39 -3
  439. package/src/ontology/validation/properties.ts +95 -19
  440. package/src/ontology/validation/query.ts +11 -42
  441. package/src/ontology/validation/schema.ts +16 -0
  442. package/src/predicates/types.ts +43 -33
  443. package/src/projections/builders.ts +24 -3
  444. package/src/projections/validation.ts +15 -1
  445. package/src/runtime/create.ts +2 -2
  446. package/src/runtime/host.ts +10 -12
  447. package/src/runtime/index.ts +3 -2
  448. package/src/runtime/sixb.ts +13 -23
  449. package/src/runtime/types.ts +277 -479
  450. package/src/sandboxes/sandbox.ts +4 -1
  451. package/src/shared/params/types.ts +4 -3
  452. package/src/shared/params/user-refs.ts +48 -0
  453. package/src/shares/compiler.ts +6 -16
  454. package/src/storage/action-runs/types.ts +1 -0
  455. package/src/storage/auth/in-memory/access-tokens.ts +5 -2
  456. package/src/storage/auth/in-memory/auth-storage.ts +5 -8
  457. package/src/storage/auth/in-memory/device-authorizations.ts +0 -2
  458. package/src/storage/auth/in-memory/sessions.ts +69 -1
  459. package/src/storage/auth/in-memory/shared.ts +13 -7
  460. package/src/storage/auth/index.ts +2 -1
  461. package/src/storage/auth/types.ts +57 -13
  462. package/src/storage/executions/validation.ts +1 -1
  463. package/src/storage/file-upload-sessions/in-memory.ts +64 -113
  464. package/src/storage/file-upload-sessions/index.ts +1 -0
  465. package/src/storage/file-upload-sessions/provider.ts +258 -0
  466. package/src/storage/file-upload-sessions/types.ts +20 -1
  467. package/src/storage/file-upload-sessions/utils.ts +25 -9
  468. package/src/storage/index.ts +3 -2
  469. package/src/storage/objects/in-memory/query.ts +13 -3
  470. package/src/storage/ontology/commits.ts +6 -2
  471. package/src/storage/ontology/in-memory/materializations.ts +6 -34
  472. package/src/storage/ontology/provider-header-validation.ts +57 -0
  473. package/src/storage/ontology/provider-work.ts +15 -3
  474. package/src/storage/ontology/provider.ts +59 -1
  475. package/src/storage/operation-scope.ts +1 -0
  476. package/src/storage/types.ts +0 -1
  477. package/src/storage/workflow-interventions/index.ts +0 -1
  478. package/src/storage/workflow-interventions/types.ts +5 -9
  479. package/src/testing/action-execution.ts +13 -3
  480. package/src/testing/auth-storage-contract.ts +149 -62
  481. package/src/testing/execution-storage-contract.ts +1 -2
  482. package/src/testing/execution.ts +4 -7
  483. package/src/testing/file-upload-session-storage-contract.ts +335 -0
  484. package/src/testing/index.ts +8 -0
  485. package/src/testing/materializer-storage-contract.ts +86 -4
  486. package/src/testing/object-query-contract.ts +121 -2
  487. package/src/testing/ontology-contract-fixture.ts +23 -3
  488. package/src/testing/ontology-storage-contract.ts +58 -0
  489. package/src/testing/sandboxes-contract.ts +27 -0
  490. package/src/testing/workflow-intervention-storage-contract.ts +203 -0
  491. package/src/webhooks/types.ts +2 -2
  492. package/src/workflows/run-dispatch.ts +12 -1
  493. package/src/workflows/snapshot.ts +16 -7
  494. package/src/workflows/types.ts +2 -2
  495. package/dist/chunk-2cxv584m.js.map +0 -43
  496. package/dist/chunk-3ghw2t5q.js.map +0 -10
  497. package/dist/chunk-3h7ctayx.js.map +0 -11
  498. package/dist/chunk-6ma8dvzc.js.map +0 -15
  499. package/dist/chunk-bbaa1fet.js.map +0 -25
  500. package/dist/chunk-eyjzgav0.js.map +0 -12
  501. package/dist/chunk-f06sf7rr.js.map +0 -11
  502. package/dist/chunk-g50nxqs5.js.map +0 -18
  503. package/dist/chunk-hkw8rykk.js.map +0 -15
  504. package/dist/chunk-p6r1ex7t.js.map +0 -10
  505. package/dist/chunk-qm535afa.js.map +0 -15
  506. package/dist/chunk-vpxss818.js.map +0 -10
  507. package/dist/chunk-vsg0g7h9.js.map +0 -17
  508. /package/dist/{chunk-e1f1sqba.js.map → chunk-04h4t2b5.js.map} +0 -0
  509. /package/dist/{chunk-y3ev53cq.js.map → chunk-2fv8sajb.js.map} +0 -0
  510. /package/dist/{chunk-3bnt2wna.js.map → chunk-2hbhn1ff.js.map} +0 -0
  511. /package/dist/{chunk-5tetw4hn.js.map → chunk-4tnrzqqh.js.map} +0 -0
  512. /package/dist/{chunk-jjwhy3rs.js.map → chunk-a69fkrtr.js.map} +0 -0
  513. /package/dist/{chunk-y1ahv8b7.js.map → chunk-bdhfn0ww.js.map} +0 -0
  514. /package/dist/{chunk-4ph94nhd.js.map → chunk-bep5rrdq.js.map} +0 -0
  515. /package/dist/{chunk-kept9cdd.js.map → chunk-bxx3ms5t.js.map} +0 -0
  516. /package/dist/{chunk-xtfryrfb.js.map → chunk-cbn96bve.js.map} +0 -0
  517. /package/dist/{chunk-r5zythxp.js.map → chunk-gbcrz0gr.js.map} +0 -0
  518. /package/dist/{chunk-t7dzd1tm.js.map → chunk-jhyc777j.js.map} +0 -0
  519. /package/dist/{chunk-0mza4xb2.js.map → chunk-m8zkvep1.js.map} +0 -0
  520. /package/dist/{chunk-sfypc7mk.js.map → chunk-s24qbp32.js.map} +0 -0
  521. /package/dist/{chunk-y0v18c2j.js.map → chunk-vef6qa14.js.map} +0 -0
  522. /package/dist/{chunk-gzt6v1ja.js.map → chunk-vn3yh259.js.map} +0 -0
  523. /package/dist/{chunk-bg2bs62d.js.map → chunk-w9bp61e7.js.map} +0 -0
  524. /package/dist/{chunk-gswwr35f.js.map → chunk-y487ywrv.js.map} +0 -0
  525. /package/dist/{chunk-bet1rb9h.js.map → chunk-y6vnvayj.js.map} +0 -0
  526. /package/dist/{chunk-g2gezsg5.js.map → chunk-z9h698s8.js.map} +0 -0
  527. /package/dist/{chunk-bfjv1adk.js.map → chunk-znw0zvy4.js.map} +0 -0
@@ -5,23 +5,23 @@ import {
5
5
  canAccessApplication2,
6
6
  resolveRoleGrants2,
7
7
  resolveAuthorizationContext2
8
- } from "./chunk-bbaa1fet.js";
8
+ } from "./chunk-rzcjp5m2.js";
9
9
  import {
10
10
  AuthRuntimeError2,
11
+ DEFAULT_AUTH_SESSION_AUDIENCE2,
11
12
  resolveAuthSessionAudience2,
12
13
  resolveAuthCookieOptionsForAudience,
13
14
  getCookie2,
14
15
  resolveAuthConfig2,
15
16
  resolveInvitationExpiresAt,
16
- sanitizeReturnTo,
17
17
  assertNonEmpty3,
18
18
  normalizePagination,
19
19
  isInvitationDeliveryAuthStrategy2
20
- } from "./chunk-q5gz3g2j.js";
20
+ } from "./chunk-0321g649.js";
21
21
  import {
22
22
  normalizeParams,
23
23
  coerceParamsToTyped
24
- } from "./chunk-y3ev53cq.js";
24
+ } from "./chunk-2fv8sajb.js";
25
25
  import {
26
26
  snapshotLinkPathSelection
27
27
  } from "./chunk-t6f3tdnr.js";
@@ -109,6 +109,14 @@ function accessTokenKindFromLabel(label) {
109
109
  }
110
110
  return null;
111
111
  }
112
+ // src/auth/client-address.ts
113
+ var clientAddresses = new WeakMap;
114
+ function setRequestClientAddress2(request, address) {
115
+ clientAddresses.set(request, address);
116
+ }
117
+ function getRequestClientAddress2(request) {
118
+ return clientAddresses.get(request);
119
+ }
112
120
  // src/auth/csrf.ts
113
121
  import { randomBytes as randomBytes2, timingSafeEqual } from "crypto";
114
122
  var CSRF_HEADER_NAME2 = "x-sixb-csrf";
@@ -123,12 +131,17 @@ function verifyDoubleSubmitCsrf2(request, options) {
123
131
  if (isCsrfExemptMethod2(request.method)) {
124
132
  return true;
125
133
  }
134
+ return verifyCsrfToken2(request, {
135
+ cookieName: options.cookieName,
136
+ token: request.headers.get(CSRF_HEADER_NAME2)
137
+ });
138
+ }
139
+ function verifyCsrfToken2(request, options) {
126
140
  const cookieValue = getCookie2(request, options.cookieName);
127
- const headerValue = request.headers.get(options.headerName ?? CSRF_HEADER_NAME2);
128
- if (!cookieValue || !headerValue) {
141
+ if (!cookieValue || !options.token) {
129
142
  return false;
130
143
  }
131
- return safeEqual(cookieValue, headerValue);
144
+ return safeEqual(cookieValue, options.token);
132
145
  }
133
146
  function safeEqual(left, right) {
134
147
  const leftBytes = Buffer.from(left);
@@ -1366,7 +1379,12 @@ function createSessionRecord(state, input) {
1366
1379
  expiresAt: cloneDate(input.expiresAt),
1367
1380
  absoluteExpiresAt: input.absoluteExpiresAt ? cloneDate(input.absoluteExpiresAt) : undefined,
1368
1381
  userAgent: input.userAgent,
1369
- ipAddress: input.ipAddress
1382
+ ipAddress: input.ipAddress,
1383
+ bearer: input.bearer ? {
1384
+ clientName: assertNonEmpty4(input.bearer.clientName, "Session client name"),
1385
+ accessExpiresAt: cloneDate(input.bearer.accessExpiresAt),
1386
+ refreshTokenHash: assertNonEmpty4(input.bearer.refreshTokenHash, "Refresh token hash")
1387
+ } : undefined
1370
1388
  };
1371
1389
  state.sessions.set(sessionKey(projectId, id), cloneRecord(session));
1372
1390
  return session;
@@ -1420,10 +1438,10 @@ function createAccessTokenRecord(state, input) {
1420
1438
  const id = assertNonEmpty4(input.id, "Access token id");
1421
1439
  const projectId = assertNonEmpty4(input.projectId, "Project id");
1422
1440
  const name = assertNonEmpty4(input.name, "Access token name");
1423
- const subjectId = assertNonEmpty4(input.subjectId, "Access token subject id");
1441
+ const subjectId = assertNonEmpty4(input.subject.id, "Access token subject id");
1424
1442
  const tokenHash = assertNonEmpty4(input.tokenHash, "Access token hash");
1425
- assertAccessTokenSubject(input.kind, input.subjectType);
1426
- assertAccessTokenSubjectExists(state, projectId, input.subjectType, subjectId);
1443
+ assertAccessTokenSubject(input.kind, input.subject.type);
1444
+ assertAccessTokenSubjectExists(state, projectId, input.subject.type, subjectId);
1427
1445
  const key = accessTokenKey(projectId, id);
1428
1446
  if (state.accessTokens.has(key)) {
1429
1447
  throw new AuthStorageError2("duplicate_access_token", `[Sixb] Access token '${id}' already exists for project '${projectId}'.`);
@@ -1433,8 +1451,7 @@ function createAccessTokenRecord(state, input) {
1433
1451
  projectId,
1434
1452
  name,
1435
1453
  kind: input.kind,
1436
- subjectType: input.subjectType,
1437
- subjectId,
1454
+ subject: { type: input.subject.type, id: subjectId },
1438
1455
  tokenHash,
1439
1456
  groupIds: normalizeOptionalGroupIds(input.groupIds),
1440
1457
  createdByPrincipal: input.createdByPrincipal,
@@ -1556,7 +1573,7 @@ class InMemoryAuthAccessTokenStore {
1556
1573
  async list(input) {
1557
1574
  const order = input.order ?? "asc";
1558
1575
  const offset = input.offset ?? 0;
1559
- const rows = [...this.state.accessTokens.values()].filter((token) => token.projectId === input.projectId).filter((token) => input.kind === undefined || token.kind === input.kind).filter((token) => input.subjectType === undefined || token.subjectType === input.subjectType).filter((token) => input.subjectId === undefined || token.subjectId === input.subjectId).filter((token) => input.includeRevoked || !token.revokedAt).sort((a, b) => compareByCreatedAt(a, b, order));
1576
+ const rows = [...this.state.accessTokens.values()].filter((token) => token.projectId === input.projectId).filter((token) => input.kind === undefined || token.kind === input.kind).filter((token) => input.subject === undefined || token.subject.type === input.subject.type && token.subject.id === input.subject.id).filter((token) => input.includeRevoked || !token.revokedAt).sort((a, b) => compareByCreatedAt(a, b, order));
1560
1577
  const page = rows.slice(offset, input.limit === undefined ? undefined : offset + input.limit);
1561
1578
  return {
1562
1579
  accessTokens: page.map(cloneRecord),
@@ -1632,8 +1649,6 @@ class InMemoryAuthDeviceAuthorizationStore {
1632
1649
  deviceCodeHash: assertNonEmpty4(input.deviceCodeHash, "Device code hash"),
1633
1650
  userCode: assertNonEmpty4(input.userCode, "User code"),
1634
1651
  clientName: assertNonEmpty4(input.clientName, "Client name"),
1635
- tokenName: assertNonEmpty4(input.tokenName, "Token name"),
1636
- tokenExpiresAt: new Date(input.tokenExpiresAt),
1637
1652
  status: "pending",
1638
1653
  createdAt: new Date(input.createdAt),
1639
1654
  expiresAt: new Date(input.expiresAt)
@@ -2080,15 +2095,54 @@ class InMemoryAuthSessionStore {
2080
2095
  }
2081
2096
  async findValidByTokenHash(params) {
2082
2097
  const session = this.state.sessions.get(sessionKey(params.projectId, params.id));
2083
- if (!session || session.audience !== params.audience || session.tokenHash !== params.tokenHash || !isActiveSession(session, params.now)) {
2098
+ if (!session || session.bearer || session.audience !== params.audience || session.tokenHash !== params.tokenHash || !isActiveSession(session, params.now)) {
2099
+ return null;
2100
+ }
2101
+ return cloneRecord(session);
2102
+ }
2103
+ async findValidByAccessTokenHash(params) {
2104
+ const session = this.state.sessions.get(sessionKey(params.projectId, params.id));
2105
+ if (!session?.bearer || session.tokenHash !== params.tokenHash || session.bearer.accessExpiresAt <= params.now || !isActiveSession(session, params.now)) {
2084
2106
  return null;
2085
2107
  }
2086
2108
  return cloneRecord(session);
2087
2109
  }
2110
+ async rotateRefreshToken(params) {
2111
+ const key = sessionKey(params.projectId, params.id);
2112
+ const session = this.state.sessions.get(key);
2113
+ if (!session?.bearer || !isActiveSession(session, params.now)) {
2114
+ return { status: "invalid" };
2115
+ }
2116
+ const { bearer } = session;
2117
+ const replacedRecently = bearer.previousRefreshTokenHash === params.refreshTokenHash && bearer.refreshedAt !== undefined && params.now.getTime() - bearer.refreshedAt.getTime() <= params.reuseGraceMs;
2118
+ if (bearer.refreshTokenHash !== params.refreshTokenHash && !replacedRecently) {
2119
+ if (bearer.previousRefreshTokenHash !== params.refreshTokenHash) {
2120
+ return { status: "invalid" };
2121
+ }
2122
+ this.state.sessions.set(key, cloneRecord({ ...session, revokedAt: cloneDate(params.now) }));
2123
+ return { status: "reused" };
2124
+ }
2125
+ const requestedExpiresAt = session.absoluteExpiresAt ? new Date(Math.min(params.next.expiresAt.getTime(), session.absoluteExpiresAt.getTime())) : params.next.expiresAt;
2126
+ const next = {
2127
+ ...session,
2128
+ tokenHash: params.next.tokenHash,
2129
+ expiresAt: new Date(Math.max(session.expiresAt.getTime(), requestedExpiresAt.getTime())),
2130
+ lastSeenAt: cloneDate(params.now),
2131
+ bearer: {
2132
+ clientName: bearer.clientName,
2133
+ accessExpiresAt: cloneDate(params.next.accessExpiresAt),
2134
+ refreshTokenHash: params.next.refreshTokenHash,
2135
+ previousRefreshTokenHash: bearer.refreshTokenHash,
2136
+ refreshedAt: cloneDate(params.now)
2137
+ }
2138
+ };
2139
+ this.state.sessions.set(key, cloneRecord(next));
2140
+ return { status: "rotated", session: cloneRecord(next) };
2141
+ }
2088
2142
  async renewIfValid(params) {
2089
2143
  const key = sessionKey(params.projectId, params.id);
2090
2144
  const session = this.state.sessions.get(key);
2091
- if (!session || session.audience !== params.audience || session.tokenHash !== params.tokenHash || !isActiveSession(session, params.now)) {
2145
+ if (!session || session.bearer || session.audience !== params.audience || session.tokenHash !== params.tokenHash || !isActiveSession(session, params.now)) {
2092
2146
  return null;
2093
2147
  }
2094
2148
  const requestedExpiresAt = session.absoluteExpiresAt ? new Date(Math.min(params.expiresAt.getTime(), session.absoluteExpiresAt.getTime())) : params.expiresAt;
@@ -2274,17 +2328,17 @@ class InMemoryAuthStorage2 {
2274
2328
  if (authorization.status !== "approved" || !authorization.approvedUserId || !authorization.approvedSessionId || authorization.expiresAt <= input.completedAt) {
2275
2329
  throw new AuthStorageError2("invalid_device_authorization", "[Sixb] Device authorization is invalid.");
2276
2330
  }
2277
- if (input.accessToken.projectId !== input.projectId || input.accessToken.subjectType !== "user" || input.accessToken.subjectId !== authorization.approvedUserId || input.accessToken.createdBySessionId !== authorization.approvedSessionId) {
2278
- throw new AuthStorageError2("invalid_device_authorization", "[Sixb] Device access token is invalid.");
2331
+ if (input.session.projectId !== input.projectId || input.session.userId !== authorization.approvedUserId) {
2332
+ throw new AuthStorageError2("invalid_device_authorization", "[Sixb] Device session is invalid.");
2279
2333
  }
2280
- const accessToken = createAccessTokenRecord(this.state, input.accessToken);
2334
+ const session = createSessionRecord(this.state, input.session);
2281
2335
  const consumed = {
2282
2336
  ...authorization,
2283
2337
  status: "consumed",
2284
2338
  consumedAt: new Date(input.completedAt)
2285
2339
  };
2286
2340
  this.state.deviceAuthorizations.set(key, cloneRecord(consumed));
2287
- return { authorization: cloneRecord(consumed), accessToken: cloneRecord(accessToken) };
2341
+ return { authorization: cloneRecord(consumed), session: cloneRecord(session) };
2288
2342
  }
2289
2343
  async completeMagicLinkSignIn(input) {
2290
2344
  const projectId = assertNonEmpty4(input.projectId, "Project id");
@@ -2596,20 +2650,22 @@ class SessionCache {
2596
2650
  if (!entry) {
2597
2651
  return;
2598
2652
  }
2599
- if (entry.expiresAtMs <= input.nowMs || entry.tokenHash !== input.tokenHash || entry.audience !== input.audience) {
2653
+ if (entry.expiresAtMs <= input.nowMs || entry.tokenHash !== input.tokenHash || entry.transport !== input.transport || input.audience !== undefined && entry.audience !== input.audience) {
2600
2654
  this.entries.delete(input.sessionId);
2601
2655
  return;
2602
2656
  }
2603
2657
  return entry.session;
2604
2658
  }
2605
2659
  set(input) {
2606
- const expiresAtMs = Math.min(input.nowMs + this.ttlMs, input.sessionExpiresAtMs, input.sessionAbsoluteExpiresAtMs ?? Number.POSITIVE_INFINITY);
2660
+ const bearer = input.session.session.bearer;
2661
+ const expiresAtMs = Math.min(input.nowMs + this.ttlMs, input.sessionExpiresAtMs, input.sessionAbsoluteExpiresAtMs ?? Number.POSITIVE_INFINITY, bearer?.accessExpiresAt.getTime() ?? Number.POSITIVE_INFINITY);
2607
2662
  if (expiresAtMs <= input.nowMs) {
2608
2663
  return;
2609
2664
  }
2610
2665
  this.entries.delete(input.sessionId);
2611
2666
  this.entries.set(input.sessionId, {
2612
2667
  tokenHash: input.tokenHash,
2668
+ transport: bearer ? "bearer" : "cookie",
2613
2669
  audience: input.audience,
2614
2670
  session: input.session,
2615
2671
  expiresAtMs
@@ -2672,10 +2728,27 @@ function createSessionCredential2(sessionId = `ses_${randomUUID2()}`) {
2672
2728
  cookieValue: formatSessionCookieValue2(sessionId, sessionSecret)
2673
2729
  };
2674
2730
  }
2731
+ var SESSION_ACCESS_TOKEN_PREFIX = "sixb_at_";
2732
+ var SESSION_REFRESH_TOKEN_PREFIX = "sixb_rt_";
2733
+ function createBearerSessionTokens(sessionId) {
2734
+ const accessSecret = generateSessionSecret2();
2735
+ const refreshSecret = generateSessionSecret2();
2736
+ return {
2737
+ accessToken: `${SESSION_ACCESS_TOKEN_PREFIX}${formatSessionCookieValue2(sessionId, accessSecret)}`,
2738
+ refreshToken: `${SESSION_REFRESH_TOKEN_PREFIX}${formatSessionCookieValue2(sessionId, refreshSecret)}`,
2739
+ tokenHash: hashSessionSecret2(accessSecret),
2740
+ refreshTokenHash: hashSessionSecret2(refreshSecret)
2741
+ };
2742
+ }
2743
+ function parseBearerSessionToken(prefix, value) {
2744
+ return value.startsWith(prefix) ? parseSessionCookieValue2(value.slice(prefix.length)) : null;
2745
+ }
2675
2746
 
2676
2747
  // src/auth/runtime.ts
2677
2748
  var SESSION_TOUCH_INTERVAL_MS = 60000;
2678
2749
  var ACCESS_TOKEN_TOUCH_INTERVAL_MS = 60000;
2750
+ var BEARER_ACCESS_TOKEN_TTL_MS = 15 * 60000;
2751
+ var REFRESH_REUSE_GRACE_MS = 60000;
2679
2752
 
2680
2753
  class AuthRuntime2 {
2681
2754
  projectId;
@@ -2730,19 +2803,17 @@ class AuthRuntime2 {
2730
2803
  return { authenticated: false, reason: "auth_disabled" };
2731
2804
  }
2732
2805
  const audience = resolveAuthSessionAudience2(options.audience);
2733
- const credentialSource = options.credentialSource ?? "session";
2734
- if (credentialSource !== "session") {
2735
- const authorizationHeader = request.headers.get("authorization");
2806
+ if (options.credentialSource === "any") {
2736
2807
  const tokenValue = getBearerAccessTokenValue2(request);
2808
+ if (tokenValue?.startsWith(SESSION_ACCESS_TOKEN_PREFIX)) {
2809
+ return this.resolveBearerSession(tokenValue);
2810
+ }
2737
2811
  if (tokenValue) {
2738
2812
  return this.resolveAccessTokenSession(request, tokenValue);
2739
2813
  }
2740
- if (authorizationHeader) {
2814
+ if (request.headers.get("authorization")) {
2741
2815
  return { authenticated: false, reason: "invalid_access_token" };
2742
2816
  }
2743
- if (credentialSource === "accessToken") {
2744
- return { authenticated: false, reason: "missing_access_token" };
2745
- }
2746
2817
  }
2747
2818
  return this.resolveCookieSession(request, audience, options.sessionActivity);
2748
2819
  }
@@ -2761,6 +2832,7 @@ class AuthRuntime2 {
2761
2832
  const cached = this.sessionCache?.get({
2762
2833
  sessionId: parts.sessionId,
2763
2834
  tokenHash,
2835
+ transport: "cookie",
2764
2836
  audience,
2765
2837
  nowMs
2766
2838
  });
@@ -2799,41 +2871,109 @@ class AuthRuntime2 {
2799
2871
  session = renewed;
2800
2872
  sessionRenewed = true;
2801
2873
  }
2802
- const user = await storage.users.getById({
2803
- projectId: this.projectId,
2804
- id: session.userId
2805
- });
2806
- if (!user) {
2807
- return { authenticated: false, reason: "missing_user" };
2874
+ if (!sessionRenewed) {
2875
+ await this.touchSessionLastSeen(storage, session, now);
2808
2876
  }
2809
- if (user.status === "suspended") {
2810
- return { authenticated: false, reason: "suspended_user" };
2877
+ const result = await this.authenticateSession(storage, session, tokenHash, now);
2878
+ return result.authenticated && sessionRenewed ? { ...result, sessionRenewed: true } : result;
2879
+ }
2880
+ async resolveBearerSession(tokenValue) {
2881
+ const parts = parseBearerSessionToken(SESSION_ACCESS_TOKEN_PREFIX, tokenValue);
2882
+ if (!parts) {
2883
+ return { authenticated: false, reason: "invalid_access_token" };
2811
2884
  }
2812
- const memberships = await storage.groupMemberships.listForUser({
2885
+ const tokenHash = hashSessionSecret2(parts.sessionSecret);
2886
+ const now = new Date;
2887
+ const cached = this.sessionCache?.get({
2888
+ sessionId: parts.sessionId,
2889
+ tokenHash,
2890
+ transport: "bearer",
2891
+ nowMs: now.getTime()
2892
+ });
2893
+ if (cached) {
2894
+ return cached;
2895
+ }
2896
+ const storage = this.requireAuthStorage();
2897
+ const session = await storage.sessions.findValidByAccessTokenHash({
2813
2898
  projectId: this.projectId,
2814
- userId: user.id
2899
+ id: parts.sessionId,
2900
+ tokenHash,
2901
+ now
2815
2902
  });
2816
- if (!sessionRenewed) {
2817
- await this.touchSessionLastSeen(storage, session, now);
2903
+ if (!session) {
2904
+ return { authenticated: false, reason: "invalid_access_token" };
2905
+ }
2906
+ await this.touchSessionLastSeen(storage, session, now);
2907
+ return this.authenticateSession(storage, session, tokenHash, now);
2908
+ }
2909
+ async authenticateSession(storage, session, tokenHash, now) {
2910
+ const member = await this.loadActiveUser(storage, session.userId);
2911
+ if (!member.authenticated) {
2912
+ return member;
2818
2913
  }
2819
2914
  const result = {
2820
2915
  authenticated: true,
2821
2916
  credentialSource: "session",
2822
- principal: { type: "user", id: user.id },
2823
- user,
2917
+ principal: { type: "user", id: member.user.id },
2918
+ user: member.user,
2824
2919
  session,
2825
- groupIds: memberships.map((membership) => membership.groupId)
2920
+ groupIds: member.groupIds
2826
2921
  };
2827
2922
  this.sessionCache?.set({
2828
- sessionId: parts.sessionId,
2923
+ sessionId: session.id,
2829
2924
  tokenHash,
2830
- audience,
2925
+ audience: session.audience,
2831
2926
  session: result,
2832
- nowMs,
2927
+ nowMs: now.getTime(),
2833
2928
  sessionExpiresAtMs: session.expiresAt.getTime(),
2834
2929
  sessionAbsoluteExpiresAtMs: session.absoluteExpiresAt?.getTime()
2835
2930
  });
2836
- return sessionRenewed ? { ...result, sessionRenewed: true } : result;
2931
+ return result;
2932
+ }
2933
+ prepareBearerSession(input) {
2934
+ const sessionId = `ses_${randomUUID3()}`;
2935
+ const tokens = createBearerSessionTokens(sessionId);
2936
+ return {
2937
+ tokens,
2938
+ session: {
2939
+ id: sessionId,
2940
+ projectId: this.projectId,
2941
+ userId: input.userId,
2942
+ strategyId: "device",
2943
+ audience: DEFAULT_AUTH_SESSION_AUDIENCE2,
2944
+ tokenHash: tokens.tokenHash,
2945
+ createdAt: input.now,
2946
+ ...this.createSessionDeadlines(input.now),
2947
+ bearer: {
2948
+ clientName: input.clientName,
2949
+ accessExpiresAt: new Date(input.now.getTime() + BEARER_ACCESS_TOKEN_TTL_MS),
2950
+ refreshTokenHash: tokens.refreshTokenHash
2951
+ }
2952
+ }
2953
+ };
2954
+ }
2955
+ async refreshSession(refreshToken) {
2956
+ const parts = parseBearerSessionToken(SESSION_REFRESH_TOKEN_PREFIX, refreshToken);
2957
+ if (!parts || !this.isEnabled()) {
2958
+ return null;
2959
+ }
2960
+ const now = new Date;
2961
+ const tokens = createBearerSessionTokens(parts.sessionId);
2962
+ const result = await this.requireAuthStorage().sessions.rotateRefreshToken({
2963
+ projectId: this.projectId,
2964
+ id: parts.sessionId,
2965
+ refreshTokenHash: hashSessionSecret2(parts.sessionSecret),
2966
+ now,
2967
+ reuseGraceMs: REFRESH_REUSE_GRACE_MS,
2968
+ next: {
2969
+ tokenHash: tokens.tokenHash,
2970
+ accessExpiresAt: new Date(now.getTime() + BEARER_ACCESS_TOKEN_TTL_MS),
2971
+ refreshTokenHash: tokens.refreshTokenHash,
2972
+ expiresAt: new Date(now.getTime() + this.config.session.idleTimeoutMs)
2973
+ }
2974
+ });
2975
+ this.sessionCache?.invalidate(parts.sessionId);
2976
+ return result.status === "rotated" ? { tokens, session: result.session } : null;
2837
2977
  }
2838
2978
  canRenewSession(session, nowMs) {
2839
2979
  if (session.expiresAt.getTime() - nowMs > this.config.session.renewalWindowMs) {
@@ -2863,33 +3003,23 @@ class AuthRuntime2 {
2863
3003
  return { authenticated: false, reason: "invalid_access_token" };
2864
3004
  }
2865
3005
  await this.touchAccessTokenLastUsed(storage, accessToken, request, now);
2866
- if (accessToken.subjectType === "user") {
2867
- const user = await storage.users.getById({
2868
- projectId: this.projectId,
2869
- id: accessToken.subjectId
2870
- });
2871
- if (!user) {
2872
- return { authenticated: false, reason: "missing_user" };
3006
+ if (accessToken.subject.type === "user") {
3007
+ const member = await this.loadActiveUser(storage, accessToken.subject.id);
3008
+ if (!member.authenticated) {
3009
+ return member;
2873
3010
  }
2874
- if (user.status === "suspended") {
2875
- return { authenticated: false, reason: "suspended_user" };
2876
- }
2877
- const memberships = await storage.groupMemberships.listForUser({
2878
- projectId: this.projectId,
2879
- userId: user.id
2880
- });
2881
3011
  return {
2882
3012
  authenticated: true,
2883
3013
  credentialSource: "accessToken",
2884
- principal: { type: "user", id: user.id },
2885
- user,
3014
+ principal: { type: "user", id: member.user.id },
3015
+ user: member.user,
2886
3016
  accessToken,
2887
- groupIds: constrainTokenGroupIds(memberships.map((membership) => membership.groupId), accessToken)
3017
+ groupIds: constrainTokenGroupIds(member.groupIds, accessToken)
2888
3018
  };
2889
3019
  }
2890
3020
  const serviceAccount = await storage.serviceAccounts.getById({
2891
3021
  projectId: this.projectId,
2892
- id: accessToken.subjectId
3022
+ id: accessToken.subject.id
2893
3023
  });
2894
3024
  if (!serviceAccount) {
2895
3025
  return { authenticated: false, reason: "missing_service_account" };
@@ -2910,8 +3040,23 @@ class AuthRuntime2 {
2910
3040
  groupIds: constrainTokenGroupIds(memberships.map((membership) => membership.groupId), accessToken)
2911
3041
  };
2912
3042
  }
2913
- invalidateSession(sessionId) {
2914
- this.sessionCache?.invalidate(sessionId);
3043
+ async loadActiveUser(storage, userId) {
3044
+ const user = await storage.users.getById({ projectId: this.projectId, id: userId });
3045
+ if (!user) {
3046
+ return { authenticated: false, reason: "missing_user" };
3047
+ }
3048
+ if (user.status === "suspended") {
3049
+ return { authenticated: false, reason: "suspended_user" };
3050
+ }
3051
+ const memberships = await storage.groupMemberships.listForUser({
3052
+ projectId: this.projectId,
3053
+ userId
3054
+ });
3055
+ return {
3056
+ authenticated: true,
3057
+ user,
3058
+ groupIds: memberships.map((membership) => membership.groupId)
3059
+ };
2915
3060
  }
2916
3061
  async touchSessionLastSeen(storage, session, now) {
2917
3062
  const lastSeen = session.lastSeenAt?.getTime() ?? 0;
@@ -2933,76 +3078,33 @@ class AuthRuntime2 {
2933
3078
  id: accessToken.id,
2934
3079
  lastUsedAt: now,
2935
3080
  userAgent: request.headers.get("user-agent")?.trim() || undefined,
2936
- ipAddress: resolveRequestIpAddress(request)
3081
+ ipAddress: getRequestClientAddress2(request)
2937
3082
  });
2938
3083
  } catch {}
2939
3084
  }
2940
- async requirePrincipal(request, options = {}) {
2941
- const session = await this.getSession(request, options);
2942
- if (!session.authenticated) {
2943
- throw new AuthRuntimeError2("authentication_required", "[Sixb] Authentication is required.");
2944
- }
2945
- return session.principal;
2946
- }
2947
- async requireUser(request, options = {}) {
2948
- const session = await this.getSession(request, { ...options, credentialSource: "session" });
2949
- if (!session.authenticated) {
2950
- throw new AuthRuntimeError2("authentication_required", "[Sixb] Authentication is required.");
2951
- }
2952
- return session;
2953
- }
2954
- async requireUserRequest(request, options = {}) {
2955
- const session = await this.getSession(request, { ...options, credentialSource: "any" });
2956
- if (!session.authenticated) {
2957
- throw new AuthRuntimeError2("authentication_required", "[Sixb] Authentication is required.");
2958
- }
2959
- if (!isAuthenticatedUserRequestSession(session)) {
2960
- throw new AuthRuntimeError2("authorization_denied", "[Sixb] User authentication is required.");
2961
- }
2962
- return session;
2963
- }
2964
- async createSecurityContext(request, options = {}) {
2965
- const session = await this.requireUser(request, options);
2966
- return {
2967
- principal: session.principal,
2968
- sessionId: session.session.id,
2969
- projectId: this.projectId,
2970
- correlationId: resolveCorrelationId(request)
2971
- };
2972
- }
2973
- async createAuthorizationContext(request, options = {}) {
2974
- const session = await this.getSession(request, options);
2975
- if (!session.authenticated) {
2976
- throw new AuthRuntimeError2("authentication_required", "[Sixb] Authentication is required.");
2977
- }
2978
- return this.contextFromSession(session);
2979
- }
2980
3085
  contextFromSession(session) {
2981
3086
  return resolveAuthorizationContext2({
2982
3087
  principal: session.principal,
2983
- sessionId: session.credentialSource === "session" ? session.session.id : undefined,
3088
+ sessionId: callerSessionId(session),
2984
3089
  groupIds: session.groupIds,
2985
3090
  roles: this.security.listResolvedRoles()
2986
3091
  });
2987
3092
  }
2988
- async listPersonalAccessTokens(request, options = {}) {
2989
- const session = await this.requireUserRequest(request, options);
3093
+ async listPersonalAccessTokens(caller) {
2990
3094
  const storage = this.requireAuthStorage();
2991
3095
  const result = await storage.accessTokens.list({
2992
3096
  projectId: this.projectId,
2993
3097
  kind: "personal",
2994
- subjectType: "user",
2995
- subjectId: session.user.id,
3098
+ subject: { type: "user", id: caller.user.id },
2996
3099
  includeRevoked: true,
2997
3100
  order: "desc",
2998
3101
  limit: 100
2999
3102
  });
3000
3103
  return { accessTokens: result.accessTokens };
3001
3104
  }
3002
- async createPersonalAccessToken(request, input, options = {}) {
3003
- const session = await this.requireUserRequest(request, options);
3105
+ async createPersonalAccessToken(caller, input) {
3004
3106
  const storage = this.requireAuthStorage();
3005
- const groupIds = constrainRequestedGroupIds(input.groupIds, session.groupIds, {
3107
+ const groupIds = constrainRequestedGroupIds(input.groupIds, caller.groupIds, {
3006
3108
  subject: "personal access token"
3007
3109
  });
3008
3110
  const credential = createAccessTokenCredential2("personal");
@@ -3011,25 +3113,23 @@ class AuthRuntime2 {
3011
3113
  projectId: this.projectId,
3012
3114
  name: input.name,
3013
3115
  kind: "personal",
3014
- subjectType: "user",
3015
- subjectId: session.user.id,
3116
+ subject: { type: "user", id: caller.user.id },
3016
3117
  tokenHash: credential.tokenHash,
3017
3118
  groupIds,
3018
- createdByPrincipal: session.principal,
3019
- createdBySessionId: session.credentialSource === "session" ? session.session.id : undefined,
3119
+ createdByPrincipal: caller.principal,
3120
+ createdBySessionId: callerSessionId(caller),
3020
3121
  createdAt: new Date,
3021
3122
  expiresAt: input.expiresAt
3022
3123
  });
3023
3124
  return { accessToken, tokenValue: credential.tokenValue };
3024
3125
  }
3025
- async revokePersonalAccessToken(request, input, options = {}) {
3026
- const session = await this.requireUserRequest(request, options);
3126
+ async revokePersonalAccessToken(caller, input) {
3027
3127
  const storage = this.requireAuthStorage();
3028
3128
  const token = await storage.accessTokens.getById({
3029
3129
  projectId: this.projectId,
3030
3130
  id: input.tokenId
3031
3131
  });
3032
- if (!token || token.kind !== "personal" || token.subjectType !== "user" || token.subjectId !== session.user.id) {
3132
+ if (!token || token.kind !== "personal" || token.subject.type !== "user" || token.subject.id !== caller.user.id) {
3033
3133
  throw missingAccessTokenError(input.tokenId, this.projectId);
3034
3134
  }
3035
3135
  const accessToken = await storage.accessTokens.revoke({
@@ -3039,8 +3139,7 @@ class AuthRuntime2 {
3039
3139
  });
3040
3140
  return { accessToken };
3041
3141
  }
3042
- async listServiceAccounts(request, options = {}) {
3043
- const session = await this.requireUserRequest(request, options);
3142
+ async listServiceAccounts(caller) {
3044
3143
  const storage = this.requireAuthStorage();
3045
3144
  const result = await storage.serviceAccounts.list({
3046
3145
  projectId: this.projectId,
@@ -3052,13 +3151,12 @@ class AuthRuntime2 {
3052
3151
  groupIds: await this.listServiceAccountGroupIds(storage, serviceAccount.id)
3053
3152
  })));
3054
3153
  return {
3055
- serviceAccounts: withGroups.filter(({ groupIds }) => callerCanManageServiceAccount(session.groupIds, groupIds))
3154
+ serviceAccounts: withGroups.filter(({ groupIds }) => callerCanManageServiceAccount(caller.groupIds, groupIds))
3056
3155
  };
3057
3156
  }
3058
- async createServiceAccount(request, input, options = {}) {
3059
- const session = await this.requireUserRequest(request, options);
3157
+ async createServiceAccount(caller, input) {
3060
3158
  const storage = this.requireAuthStorage();
3061
- const groupIds = constrainRequestedGroupIds(input.groupIds, session.groupIds, {
3159
+ const groupIds = constrainRequestedGroupIds(input.groupIds, caller.groupIds, {
3062
3160
  subject: "service account"
3063
3161
  }) ?? [];
3064
3162
  const now = new Date;
@@ -3067,8 +3165,8 @@ class AuthRuntime2 {
3067
3165
  projectId: this.projectId,
3068
3166
  name: input.name,
3069
3167
  description: input.description,
3070
- createdByPrincipal: session.principal,
3071
- createdBySessionId: session.credentialSource === "session" ? session.session.id : undefined,
3168
+ createdByPrincipal: caller.principal,
3169
+ createdBySessionId: callerSessionId(caller),
3072
3170
  createdAt: now,
3073
3171
  updatedAt: now
3074
3172
  });
@@ -3084,10 +3182,9 @@ class AuthRuntime2 {
3084
3182
  }
3085
3183
  return { serviceAccount, groupMemberships };
3086
3184
  }
3087
- async disableServiceAccount(request, input, options = {}) {
3088
- const session = await this.requireUserRequest(request, options);
3185
+ async disableServiceAccount(caller, input) {
3089
3186
  const storage = this.requireAuthStorage();
3090
- const { serviceAccount, groupIds } = await this.requireManageableServiceAccount(storage, session.groupIds, input.serviceAccountId);
3187
+ const { serviceAccount, groupIds } = await this.requireManageableServiceAccount(storage, caller.groupIds, input.serviceAccountId);
3091
3188
  const updated = await storage.serviceAccounts.update({
3092
3189
  projectId: this.projectId,
3093
3190
  id: serviceAccount.id,
@@ -3096,25 +3193,22 @@ class AuthRuntime2 {
3096
3193
  });
3097
3194
  return { serviceAccount: updated, groupIds };
3098
3195
  }
3099
- async listServiceAccountAccessTokens(request, input, options = {}) {
3100
- const session = await this.requireUserRequest(request, options);
3196
+ async listServiceAccountAccessTokens(caller, input) {
3101
3197
  const storage = this.requireAuthStorage();
3102
- const { serviceAccount } = await this.requireManageableServiceAccount(storage, session.groupIds, input.serviceAccountId);
3198
+ const { serviceAccount } = await this.requireManageableServiceAccount(storage, caller.groupIds, input.serviceAccountId);
3103
3199
  const result = await storage.accessTokens.list({
3104
3200
  projectId: this.projectId,
3105
3201
  kind: "serviceAccount",
3106
- subjectType: "serviceAccount",
3107
- subjectId: serviceAccount.id,
3202
+ subject: { type: "serviceAccount", id: serviceAccount.id },
3108
3203
  includeRevoked: true,
3109
3204
  order: "desc",
3110
3205
  limit: 100
3111
3206
  });
3112
3207
  return { serviceAccount, accessTokens: result.accessTokens };
3113
3208
  }
3114
- async createServiceAccountAccessToken(request, input, options = {}) {
3115
- const session = await this.requireUserRequest(request, options);
3209
+ async createServiceAccountAccessToken(caller, input) {
3116
3210
  const storage = this.requireAuthStorage();
3117
- const { serviceAccount, groupIds: serviceAccountGroupIds } = await this.requireManageableServiceAccount(storage, session.groupIds, input.serviceAccountId);
3211
+ const { serviceAccount, groupIds: serviceAccountGroupIds } = await this.requireManageableServiceAccount(storage, caller.groupIds, input.serviceAccountId);
3118
3212
  if (serviceAccount.status === "suspended") {
3119
3213
  throw new AuthStorageError2("suspended_service_account", `[Sixb] Service account '${input.serviceAccountId}' is suspended for project '${this.projectId}'.`);
3120
3214
  }
@@ -3127,26 +3221,24 @@ class AuthRuntime2 {
3127
3221
  projectId: this.projectId,
3128
3222
  name: input.name,
3129
3223
  kind: "serviceAccount",
3130
- subjectType: "serviceAccount",
3131
- subjectId: serviceAccount.id,
3224
+ subject: { type: "serviceAccount", id: serviceAccount.id },
3132
3225
  tokenHash: credential.tokenHash,
3133
3226
  groupIds,
3134
- createdByPrincipal: session.principal,
3135
- createdBySessionId: session.credentialSource === "session" ? session.session.id : undefined,
3227
+ createdByPrincipal: caller.principal,
3228
+ createdBySessionId: callerSessionId(caller),
3136
3229
  createdAt: new Date,
3137
3230
  expiresAt: input.expiresAt
3138
3231
  });
3139
3232
  return { accessToken, tokenValue: credential.tokenValue, serviceAccount };
3140
3233
  }
3141
- async revokeServiceAccountAccessToken(request, input, options = {}) {
3142
- const session = await this.requireUserRequest(request, options);
3234
+ async revokeServiceAccountAccessToken(caller, input) {
3143
3235
  const storage = this.requireAuthStorage();
3144
- const { serviceAccount } = await this.requireManageableServiceAccount(storage, session.groupIds, input.serviceAccountId);
3236
+ const { serviceAccount } = await this.requireManageableServiceAccount(storage, caller.groupIds, input.serviceAccountId);
3145
3237
  const token = await storage.accessTokens.getById({
3146
3238
  projectId: this.projectId,
3147
3239
  id: input.tokenId
3148
3240
  });
3149
- if (!token || token.kind !== "serviceAccount" || token.subjectType !== "serviceAccount" || token.subjectId !== serviceAccount.id) {
3241
+ if (!token || token.kind !== "serviceAccount" || token.subject.type !== "serviceAccount" || token.subject.id !== serviceAccount.id) {
3150
3242
  throw missingAccessTokenError(input.tokenId, this.projectId);
3151
3243
  }
3152
3244
  const accessToken = await storage.accessTokens.revoke({
@@ -3174,9 +3266,8 @@ class AuthRuntime2 {
3174
3266
  });
3175
3267
  return memberships.map((membership) => membership.groupId);
3176
3268
  }
3177
- async getInvitationOptions(request, options = {}) {
3178
- const session = await this.requireUser(request, options);
3179
- const scope = this.resolveMembershipPolicyScopeForUser(session.groupIds);
3269
+ async getInvitationOptions(caller) {
3270
+ const scope = this.resolveMembershipPolicyScopeForUser(caller.groupIds);
3180
3271
  const inviteScope = scope.operations.invite;
3181
3272
  const groups = this.scopedGroupOptions(inviteScope.groupIds);
3182
3273
  const hasInviteMembershipPolicy = inviteScope.policyIds.length > 0;
@@ -3193,18 +3284,16 @@ class AuthRuntime2 {
3193
3284
  getMembershipCapabilities(input) {
3194
3285
  return membershipCapabilities(this.resolveMembershipPolicyScopeForUser(groupIdsOf(input.callerGroups)));
3195
3286
  }
3196
- async getMembershipOptions(request, options = {}) {
3197
- const session = await this.requireUser(request, options);
3198
- const scope = this.resolveMembershipPolicyScopeForUser(session.groupIds);
3287
+ async getMembershipOptions(caller) {
3288
+ const scope = this.resolveMembershipPolicyScopeForUser(caller.groupIds);
3199
3289
  return {
3200
3290
  groups: this.scopedGroupOptions(scope.operations.assignGroups.groupIds),
3201
3291
  capabilities: membershipCapabilities(scope).holds
3202
3292
  };
3203
3293
  }
3204
- async listMembers(request, input = {}, options = {}) {
3205
- const session = await this.requireUser(request, options);
3294
+ async listMembers(caller, input = {}) {
3206
3295
  const storage = this.requireAuthStorage();
3207
- const scope = this.resolveMembershipPolicyScopeForUser(session.groupIds);
3296
+ const scope = this.resolveMembershipPolicyScopeForUser(caller.groupIds);
3208
3297
  const { limit, offset } = normalizePagination(input);
3209
3298
  const result = await storage.users.list({ projectId: this.projectId, order: input.order });
3210
3299
  const members = [];
@@ -3215,7 +3304,7 @@ class AuthRuntime2 {
3215
3304
  if (!canAssignGroups && !canSuspendScope) {
3216
3305
  continue;
3217
3306
  }
3218
- const isSelf = user.id === session.user.id;
3307
+ const isSelf = user.id === caller.user.id;
3219
3308
  members.push({
3220
3309
  user,
3221
3310
  groupIds,
@@ -3229,10 +3318,9 @@ class AuthRuntime2 {
3229
3318
  const page = paginate(members, { limit, offset });
3230
3319
  return { members: page.page, hasMore: page.hasMore, total: page.total };
3231
3320
  }
3232
- async updateMemberGroups(request, input, options = {}) {
3233
- const session = await this.requireUser(request, options);
3321
+ async updateMemberGroups(caller, input) {
3234
3322
  const storage = this.requireAuthStorage();
3235
- const scope = this.resolveMembershipPolicyScopeForUser(session.groupIds);
3323
+ const scope = this.resolveMembershipPolicyScopeForUser(caller.groupIds);
3236
3324
  const userId = assertNonEmpty3(input.userId, "User id");
3237
3325
  const { user, groupIds: currentGroupIds } = await this.requireManageableMember(storage, scope, "assignGroups", userId);
3238
3326
  const requestedGroupIds = this.resolveMemberGroupIds(input.groupIds);
@@ -3244,7 +3332,7 @@ class AuthRuntime2 {
3244
3332
  const requested = new Set(requestedGroupIds);
3245
3333
  const additions = requestedGroupIds.filter((groupId) => !current.has(groupId));
3246
3334
  const removals = currentGroupIds.filter((groupId) => !requested.has(groupId));
3247
- if (user.id === session.user.id && removals.length > 0) {
3335
+ if (user.id === caller.user.id && removals.length > 0) {
3248
3336
  throw new AuthRuntimeError2("authorization_denied", "[Sixb] The current user cannot remove their own groups.");
3249
3337
  }
3250
3338
  const now = new Date;
@@ -3264,17 +3352,16 @@ class AuthRuntime2 {
3264
3352
  groupId
3265
3353
  });
3266
3354
  }
3267
- this.invalidateUserSessions(user.id);
3355
+ this.sessionCache?.invalidateUser(user.id);
3268
3356
  const groupIds = (await storage.groupMemberships.listForUser({ projectId: this.projectId, userId: user.id })).map((membership) => membership.groupId);
3269
3357
  return { user, groupIds };
3270
3358
  }
3271
- async suspendMember(request, input, options = {}) {
3272
- const session = await this.requireUser(request, options);
3359
+ async suspendMember(caller, input) {
3273
3360
  const storage = this.requireAuthStorage();
3274
- const scope = this.resolveMembershipPolicyScopeForUser(session.groupIds);
3361
+ const scope = this.resolveMembershipPolicyScopeForUser(caller.groupIds);
3275
3362
  const userId = assertNonEmpty3(input.userId, "User id");
3276
3363
  const { user, groupIds } = await this.requireManageableMember(storage, scope, "suspend", userId);
3277
- if (user.id === session.user.id) {
3364
+ if (user.id === caller.user.id) {
3278
3365
  throw new AuthRuntimeError2("authorization_denied", "[Sixb] The current user cannot suspend themselves.");
3279
3366
  }
3280
3367
  const suspended = await storage.suspendUserAndRevokeSessions({
@@ -3282,13 +3369,12 @@ class AuthRuntime2 {
3282
3369
  userId: user.id,
3283
3370
  suspendedAt: new Date
3284
3371
  });
3285
- this.invalidateUserSessions(user.id);
3372
+ this.sessionCache?.invalidateUser(user.id);
3286
3373
  return { user: suspended, groupIds };
3287
3374
  }
3288
- async reactivateMember(request, input, options = {}) {
3289
- const session = await this.requireUser(request, options);
3375
+ async reactivateMember(caller, input) {
3290
3376
  const storage = this.requireAuthStorage();
3291
- const scope = this.resolveMembershipPolicyScopeForUser(session.groupIds);
3377
+ const scope = this.resolveMembershipPolicyScopeForUser(caller.groupIds);
3292
3378
  const userId = assertNonEmpty3(input.userId, "User id");
3293
3379
  const { user, groupIds } = await this.requireManageableMember(storage, scope, "suspend", userId);
3294
3380
  const reactivated = await storage.users.updateStatus({
@@ -3299,8 +3385,37 @@ class AuthRuntime2 {
3299
3385
  });
3300
3386
  return { user: reactivated, groupIds };
3301
3387
  }
3302
- invalidateUserSessions(userId) {
3303
- this.sessionCache?.invalidateUser(userId);
3388
+ async listSessions(caller) {
3389
+ return this.requireAuthStorage().sessions.listActiveByUserId({
3390
+ projectId: this.projectId,
3391
+ userId: caller.user.id,
3392
+ now: new Date
3393
+ });
3394
+ }
3395
+ async revokeSession(caller, sessionId) {
3396
+ const storage = this.requireAuthStorage();
3397
+ const session = await storage.sessions.getById({ projectId: this.projectId, id: sessionId });
3398
+ if (!session || session.userId !== caller.user.id) {
3399
+ return false;
3400
+ }
3401
+ await storage.sessions.revoke({
3402
+ projectId: this.projectId,
3403
+ id: sessionId,
3404
+ revokedAt: new Date
3405
+ });
3406
+ this.sessionCache?.invalidate(sessionId);
3407
+ return true;
3408
+ }
3409
+ async revokeAllSessions(caller) {
3410
+ const revoked = await this.requireAuthStorage().sessions.revokeActiveForUser({
3411
+ projectId: this.projectId,
3412
+ userId: caller.user.id,
3413
+ revokedAt: new Date
3414
+ });
3415
+ for (const session of revoked) {
3416
+ this.sessionCache?.invalidate(session.id);
3417
+ }
3418
+ return revoked.length;
3304
3419
  }
3305
3420
  scopedGroupOptions(groupIds) {
3306
3421
  return this.security.listGroups().filter((group) => groupIds.has(group.id)).map((group) => ({
@@ -3326,26 +3441,24 @@ class AuthRuntime2 {
3326
3441
  }
3327
3442
  return groupIds;
3328
3443
  }
3329
- async invite(request, input, options = {}) {
3330
- const session = await this.requireUser(request, options);
3444
+ async invite(caller, input, destination) {
3331
3445
  const authStorage = this.requireAuthStorage();
3332
3446
  const now = new Date;
3333
3447
  const groupIds = this.resolveInviteGroupIds(input);
3334
- this.assertCanManageInvitationGroups(session.groupIds, groupIds);
3448
+ this.assertCanManageInvitationGroups(caller.groupIds, groupIds);
3335
3449
  const strategy = this.getStrategy();
3336
3450
  if (!isInvitationDeliveryAuthStrategy2(strategy)) {
3337
3451
  throw new AuthRuntimeError2("invalid_auth_config", "[Sixb] The active auth strategy does not support invitations.");
3338
3452
  }
3339
3453
  await this.assertCanInviteRecipient(strategy, authStorage, input.email, now);
3340
- const deliveryAudience = resolveAuthSessionAudience2(options.delivery?.audience ?? options.audience);
3341
- this.assertInvitationApplicationAccess(groupIds, deliveryAudience);
3454
+ this.assertInvitationApplicationAccess(groupIds, destination.audience);
3342
3455
  const invitation = await authStorage.invitations.createOrUpdateActive({
3343
3456
  id: `inv_${randomUUID3()}`,
3344
3457
  projectId: this.projectId,
3345
3458
  email: input.email,
3346
3459
  groupIds,
3347
- createdByPrincipal: session.principal,
3348
- createdBySessionId: session.session.id,
3460
+ createdByPrincipal: caller.principal,
3461
+ createdBySessionId: callerSessionId(caller),
3349
3462
  createdAt: now,
3350
3463
  updatedAt: now,
3351
3464
  expiresAt: resolveInvitationExpiresAt(input.expiresAt, now)
@@ -3356,9 +3469,9 @@ class AuthRuntime2 {
3356
3469
  projectId: this.projectId,
3357
3470
  authStorage,
3358
3471
  invitation,
3359
- audience: deliveryAudience,
3360
- returnTo: options.delivery?.returnTo ?? sanitizeReturnTo(input.returnTo),
3361
- requestOrigin: options.delivery?.requestOrigin ?? new URL(request.url).origin,
3472
+ audience: destination.audience,
3473
+ returnTo: destination.returnTo,
3474
+ requestOrigin: destination.requestOrigin,
3362
3475
  revealLink: input.revealLink,
3363
3476
  now
3364
3477
  });
@@ -3379,8 +3492,7 @@ class AuthRuntime2 {
3379
3492
  }
3380
3493
  return { invitation, delivery };
3381
3494
  }
3382
- async listInvitations(request, input = {}, options = {}) {
3383
- const session = await this.requireUser(request, options);
3495
+ async listInvitations(caller, input = {}) {
3384
3496
  const authStorage = this.requireAuthStorage();
3385
3497
  const { limit, offset } = normalizePagination(input);
3386
3498
  const result = await authStorage.invitations.list({
@@ -3389,7 +3501,7 @@ class AuthRuntime2 {
3389
3501
  statuses: input.statuses,
3390
3502
  order: input.order
3391
3503
  });
3392
- const scope = this.resolveMembershipPolicyScopeForUser(session.groupIds);
3504
+ const scope = this.resolveMembershipPolicyScopeForUser(caller.groupIds);
3393
3505
  const manageable = result.invitations.filter((invitation) => canPerformMembershipOperation(scope, "invite", invitation.groupIds));
3394
3506
  const page = paginate(manageable, { limit, offset });
3395
3507
  return {
@@ -3398,8 +3510,7 @@ class AuthRuntime2 {
3398
3510
  total: page.total
3399
3511
  };
3400
3512
  }
3401
- async revokeInvitation(request, input, options = {}) {
3402
- const session = await this.requireUser(request, options);
3513
+ async revokeInvitation(caller, input) {
3403
3514
  const authStorage = this.requireAuthStorage();
3404
3515
  const invitationId = assertNonEmpty3(input.invitationId, "Invitation id");
3405
3516
  const invitation = await authStorage.invitations.getById({
@@ -3409,7 +3520,7 @@ class AuthRuntime2 {
3409
3520
  if (!invitation) {
3410
3521
  throw new AuthStorageError2("missing_invitation", `[Sixb] Invitation '${invitationId}' not found for project '${this.projectId}'.`);
3411
3522
  }
3412
- this.assertCanManageInvitationGroups(session.groupIds, invitation.groupIds);
3523
+ this.assertCanManageInvitationGroups(caller.groupIds, invitation.groupIds);
3413
3524
  if (invitation.status !== "pending") {
3414
3525
  throw new AuthRuntimeError2("invalid_auth_input", `[Sixb] Invitation '${invitationId}' is already ${invitation.status} and cannot be revoked.`);
3415
3526
  }
@@ -3506,14 +3617,8 @@ class AuthRuntime2 {
3506
3617
  throw new AuthRuntimeError2("authorization_denied", `[Sixb] The current user is not allowed to create or manage invitations for group(s): ${missing.join(", ")}.`);
3507
3618
  }
3508
3619
  }
3509
- function resolveCorrelationId(request) {
3510
- return request.headers.get("x-correlation-id") ?? request.headers.get("x-request-id") ?? randomUUID3();
3511
- }
3512
- function isAuthenticatedUserRequestSession(session) {
3513
- return session.principal.type === "user";
3514
- }
3515
- function resolveRequestIpAddress(request) {
3516
- return request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || request.headers.get("x-real-ip")?.trim() || undefined;
3620
+ function callerSessionId(caller) {
3621
+ return caller.credentialSource === "session" ? caller.session.id : undefined;
3517
3622
  }
3518
3623
  function constrainTokenGroupIds(principalGroupIds, accessToken) {
3519
3624
  if (accessToken.groupIds === undefined) {
@@ -3589,6 +3694,6 @@ var SYSTEM_PRINCIPAL2 = { type: "system", id: "system" };
3589
3694
  function principalsEqual2(left, right) {
3590
3695
  return left.type === right.type && left.id === right.id;
3591
3696
  }
3592
- export { ActionDefinitionError2, ActionEditCommitError2, missingActionMutationMessage, effectsWithoutEditsMessage, assertNonEmpty2, isActionDefinition2, isGlobalActionDefinition2, isObjectActionDefinition2, normalizeActionParams, coerceActionParamsToTyped2, validateActionSubject, resolveObjectActionSubject, PERSONAL_ACCESS_TOKEN_PREFIX2, SERVICE_ACCOUNT_ACCESS_TOKEN_PREFIX2, generateAccessTokenSecret2, hashAccessTokenSecret2, formatAccessTokenValue2, parseAccessTokenValue2, getBearerAccessTokenValue2, createAccessTokenCredential2, CSRF_HEADER_NAME2, generateCsrfToken2, isCsrfExemptMethod2, verifyDoubleSubmitCsrf2, applications2, SecurityValidationError2, isGroupDefinition, isMembershipPolicyDefinition, isRoleDefinition, defineGroup2, defineRole2, defineMembershipPolicy2, every2, ShareDefinitionError2, defineShare2, isShareDefinition, snapshotShareDefinition, can2, SecurityRegistry, AuthStorageError2, MAX_PENDING_DEVICE_AUTHORIZATIONS2, paginate, InMemoryAuthStorage2, generateSessionSecret2, hashSessionSecret2, formatSessionCookieValue2, parseSessionCookieValue2, createSessionCredential2, AuthRuntime2, SYSTEM_PRINCIPAL2, principalsEqual2 };
3697
+ export { ActionDefinitionError2, ActionEditCommitError2, missingActionMutationMessage, effectsWithoutEditsMessage, assertNonEmpty2, isActionDefinition2, isGlobalActionDefinition2, isObjectActionDefinition2, normalizeActionParams, coerceActionParamsToTyped2, validateActionSubject, resolveObjectActionSubject, PERSONAL_ACCESS_TOKEN_PREFIX2, SERVICE_ACCOUNT_ACCESS_TOKEN_PREFIX2, generateAccessTokenSecret2, hashAccessTokenSecret2, formatAccessTokenValue2, parseAccessTokenValue2, getBearerAccessTokenValue2, createAccessTokenCredential2, setRequestClientAddress2, getRequestClientAddress2, CSRF_HEADER_NAME2, generateCsrfToken2, isCsrfExemptMethod2, verifyDoubleSubmitCsrf2, verifyCsrfToken2, applications2, SecurityValidationError2, isGroupDefinition, isMembershipPolicyDefinition, isRoleDefinition, defineGroup2, defineRole2, defineMembershipPolicy2, every2, ShareDefinitionError2, defineShare2, isShareDefinition, snapshotShareDefinition, can2, SecurityRegistry, AuthStorageError2, MAX_PENDING_DEVICE_AUTHORIZATIONS2, paginate, InMemoryAuthStorage2, generateSessionSecret2, hashSessionSecret2, formatSessionCookieValue2, parseSessionCookieValue2, createSessionCredential2, AuthRuntime2, SYSTEM_PRINCIPAL2, principalsEqual2 };
3593
3698
 
3594
- //# debugId=103AE23BF90D263E64756E2164756E21
3699
+ //# debugId=934CBDB22AF498A264756E2164756E21