@codemem/core 0.46.3 → 0.47.0-beta.2

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 (465) hide show
  1. package/dist/address-utils.d.ts.map +1 -1
  2. package/dist/better-sqlite-coordinator-runtime.d.ts +2 -0
  3. package/dist/better-sqlite-coordinator-runtime.d.ts.map +1 -1
  4. package/dist/better-sqlite-coordinator-store.d.ts +109 -5
  5. package/dist/better-sqlite-coordinator-store.d.ts.map +1 -1
  6. package/dist/coordinator-account-change-browser.d.ts +39 -0
  7. package/dist/coordinator-account-change-browser.d.ts.map +1 -0
  8. package/dist/coordinator-account-change-contract.d.ts +4 -0
  9. package/dist/coordinator-account-change-contract.d.ts.map +1 -0
  10. package/dist/coordinator-account-change-http-test-fixtures.d.ts +101 -0
  11. package/dist/coordinator-account-change-http-test-fixtures.d.ts.map +1 -0
  12. package/dist/coordinator-account-change-schema.d.ts +5 -0
  13. package/dist/coordinator-account-change-schema.d.ts.map +1 -0
  14. package/dist/coordinator-account-change.d.ts +100 -0
  15. package/dist/coordinator-account-change.d.ts.map +1 -0
  16. package/dist/coordinator-account-connection-link.d.ts +25 -0
  17. package/dist/coordinator-account-connection-link.d.ts.map +1 -0
  18. package/dist/coordinator-account-connection-schema.d.ts +68 -0
  19. package/dist/coordinator-account-connection-schema.d.ts.map +1 -0
  20. package/dist/coordinator-account-connection-session.d.ts +15 -0
  21. package/dist/coordinator-account-connection-session.d.ts.map +1 -0
  22. package/dist/coordinator-account-connection-storage.d.ts +46 -0
  23. package/dist/coordinator-account-connection-storage.d.ts.map +1 -0
  24. package/dist/coordinator-account-historical-revoke.d.ts +7 -0
  25. package/dist/coordinator-account-historical-revoke.d.ts.map +1 -0
  26. package/dist/coordinator-account-link-receipt.d.ts +20 -0
  27. package/dist/coordinator-account-link-receipt.d.ts.map +1 -0
  28. package/dist/coordinator-account-link-receiver.d.ts +28 -0
  29. package/dist/coordinator-account-link-receiver.d.ts.map +1 -0
  30. package/dist/coordinator-account-link-runtime.d.ts +45 -0
  31. package/dist/coordinator-account-link-runtime.d.ts.map +1 -0
  32. package/dist/coordinator-account-link-signer.d.ts +15 -0
  33. package/dist/coordinator-account-link-signer.d.ts.map +1 -0
  34. package/dist/coordinator-account-link-status-client.d.ts +37 -0
  35. package/dist/coordinator-account-link-status-client.d.ts.map +1 -0
  36. package/dist/coordinator-account-link-status.d.ts +23 -0
  37. package/dist/coordinator-account-link-status.d.ts.map +1 -0
  38. package/dist/coordinator-account-unlink-schema.d.ts +7 -0
  39. package/dist/coordinator-account-unlink-schema.d.ts.map +1 -0
  40. package/dist/coordinator-actions.d.ts +29 -0
  41. package/dist/coordinator-actions.d.ts.map +1 -1
  42. package/dist/coordinator-api.d.ts +21 -1
  43. package/dist/coordinator-api.d.ts.map +1 -1
  44. package/dist/coordinator-auth-account-profile-contract.d.ts +41 -0
  45. package/dist/coordinator-auth-account-profile-contract.d.ts.map +1 -0
  46. package/dist/coordinator-auth-account-profile.d.ts +27 -0
  47. package/dist/coordinator-auth-account-profile.d.ts.map +1 -0
  48. package/dist/coordinator-auth-browser-migration-test-harness.d.ts +18 -0
  49. package/dist/coordinator-auth-browser-migration-test-harness.d.ts.map +1 -0
  50. package/dist/coordinator-auth-browser-owner-purpose-test-harness.d.ts +6 -0
  51. package/dist/coordinator-auth-browser-owner-purpose-test-harness.d.ts.map +1 -0
  52. package/dist/coordinator-auth-browser-proof-test-fixtures.d.ts +25 -0
  53. package/dist/coordinator-auth-browser-proof-test-fixtures.d.ts.map +1 -0
  54. package/dist/coordinator-auth-browser-schema-upgrade.d.ts +6 -0
  55. package/dist/coordinator-auth-browser-schema-upgrade.d.ts.map +1 -0
  56. package/dist/coordinator-auth-browser-style.d.ts +6 -0
  57. package/dist/coordinator-auth-browser-style.d.ts.map +1 -0
  58. package/dist/coordinator-auth-browser-transaction-contract.d.ts +130 -0
  59. package/dist/coordinator-auth-browser-transaction-contract.d.ts.map +1 -0
  60. package/dist/coordinator-auth-browser-transaction-test-fixtures.d.ts +14 -0
  61. package/dist/coordinator-auth-browser-transaction-test-fixtures.d.ts.map +1 -0
  62. package/dist/coordinator-auth-browser-transaction.d.ts +36 -0
  63. package/dist/coordinator-auth-browser-transaction.d.ts.map +1 -0
  64. package/dist/coordinator-auth-browser-view.d.ts +84 -0
  65. package/dist/coordinator-auth-browser-view.d.ts.map +1 -0
  66. package/dist/coordinator-auth-contract.d.ts +71 -0
  67. package/dist/coordinator-auth-contract.d.ts.map +1 -0
  68. package/dist/coordinator-auth-controller-review-route.d.ts +38 -0
  69. package/dist/coordinator-auth-controller-review-route.d.ts.map +1 -0
  70. package/dist/coordinator-auth-controller.d.ts +87 -0
  71. package/dist/coordinator-auth-controller.d.ts.map +1 -0
  72. package/dist/coordinator-auth-device-claim-eligibility.d.ts +43 -0
  73. package/dist/coordinator-auth-device-claim-eligibility.d.ts.map +1 -0
  74. package/dist/coordinator-auth-device-claim-schema.d.ts +116 -0
  75. package/dist/coordinator-auth-device-claim-schema.d.ts.map +1 -0
  76. package/dist/coordinator-auth-historical-migration-test-fixture.d.ts +2 -0
  77. package/dist/coordinator-auth-historical-migration-test-fixture.d.ts.map +1 -0
  78. package/dist/coordinator-auth-historical-store-test-fixture.d.ts +13 -0
  79. package/dist/coordinator-auth-historical-store-test-fixture.d.ts.map +1 -0
  80. package/dist/coordinator-auth-historical-test-fixture.d.ts +48 -0
  81. package/dist/coordinator-auth-historical-test-fixture.d.ts.map +1 -0
  82. package/dist/coordinator-auth-legacy-assignment.d.ts +12 -0
  83. package/dist/coordinator-auth-legacy-assignment.d.ts.map +1 -0
  84. package/dist/coordinator-auth-lifecycle-admission-schema.d.ts +28 -0
  85. package/dist/coordinator-auth-lifecycle-admission-schema.d.ts.map +1 -0
  86. package/dist/coordinator-auth-lifecycle-browser-schema.d.ts +15 -0
  87. package/dist/coordinator-auth-lifecycle-browser-schema.d.ts.map +1 -0
  88. package/dist/coordinator-auth-lifecycle-current-readiness.d.ts +7 -0
  89. package/dist/coordinator-auth-lifecycle-current-readiness.d.ts.map +1 -0
  90. package/dist/coordinator-auth-lifecycle-first-link.d.ts +17 -0
  91. package/dist/coordinator-auth-lifecycle-first-link.d.ts.map +1 -0
  92. package/dist/coordinator-auth-lifecycle-fresh-schema.d.ts +14 -0
  93. package/dist/coordinator-auth-lifecycle-fresh-schema.d.ts.map +1 -0
  94. package/dist/coordinator-auth-lifecycle-predecessor-shapes.d.ts +24 -0
  95. package/dist/coordinator-auth-lifecycle-predecessor-shapes.d.ts.map +1 -0
  96. package/dist/coordinator-auth-lifecycle-predecessor.d.ts +9 -0
  97. package/dist/coordinator-auth-lifecycle-predecessor.d.ts.map +1 -0
  98. package/dist/coordinator-auth-lifecycle-profile-schema.d.ts +13 -0
  99. package/dist/coordinator-auth-lifecycle-profile-schema.d.ts.map +1 -0
  100. package/dist/coordinator-auth-lifecycle-recognition.d.ts +22 -0
  101. package/dist/coordinator-auth-lifecycle-recognition.d.ts.map +1 -0
  102. package/dist/coordinator-auth-lifecycle-schema.d.ts +20 -0
  103. package/dist/coordinator-auth-lifecycle-schema.d.ts.map +1 -0
  104. package/dist/coordinator-auth-lifecycle-upgrade-copy.d.ts +36 -0
  105. package/dist/coordinator-auth-lifecycle-upgrade-copy.d.ts.map +1 -0
  106. package/dist/coordinator-auth-lifecycle-upgrade-sqlite.d.ts +11 -0
  107. package/dist/coordinator-auth-lifecycle-upgrade-sqlite.d.ts.map +1 -0
  108. package/dist/coordinator-auth-lifecycle-upgrade-test-fixture.d.ts +31 -0
  109. package/dist/coordinator-auth-lifecycle-upgrade-test-fixture.d.ts.map +1 -0
  110. package/dist/coordinator-auth-lifecycle-upgrade.d.ts +6 -0
  111. package/dist/coordinator-auth-lifecycle-upgrade.d.ts.map +1 -0
  112. package/dist/coordinator-auth-link-authority-upgrade.d.ts +17 -0
  113. package/dist/coordinator-auth-link-authority-upgrade.d.ts.map +1 -0
  114. package/dist/coordinator-auth-link-authority.d.ts +92 -0
  115. package/dist/coordinator-auth-link-authority.d.ts.map +1 -0
  116. package/dist/coordinator-auth-link-change-schema.d.ts +21 -0
  117. package/dist/coordinator-auth-link-change-schema.d.ts.map +1 -0
  118. package/dist/coordinator-auth-link-contract.d.ts +137 -0
  119. package/dist/coordinator-auth-link-contract.d.ts.map +1 -0
  120. package/dist/coordinator-auth-link-input.d.ts +7 -0
  121. package/dist/coordinator-auth-link-input.d.ts.map +1 -0
  122. package/dist/coordinator-auth-link-legacy-inline-test-fixture.d.ts +2 -0
  123. package/dist/coordinator-auth-link-legacy-inline-test-fixture.d.ts.map +1 -0
  124. package/dist/coordinator-auth-link-liveness.d.ts +8 -0
  125. package/dist/coordinator-auth-link-liveness.d.ts.map +1 -0
  126. package/dist/coordinator-auth-link-maintenance-fixtures.d.ts +14 -0
  127. package/dist/coordinator-auth-link-maintenance-fixtures.d.ts.map +1 -0
  128. package/dist/coordinator-auth-link-profile.d.ts +15 -0
  129. package/dist/coordinator-auth-link-profile.d.ts.map +1 -0
  130. package/dist/coordinator-auth-link-provenance.d.ts +17 -0
  131. package/dist/coordinator-auth-link-provenance.d.ts.map +1 -0
  132. package/dist/coordinator-auth-link-revocation-test-harness.d.ts +19 -0
  133. package/dist/coordinator-auth-link-revocation-test-harness.d.ts.map +1 -0
  134. package/dist/coordinator-auth-link-source.d.ts +15 -0
  135. package/dist/coordinator-auth-link-source.d.ts.map +1 -0
  136. package/dist/coordinator-auth-link-test-fixtures.d.ts +49 -0
  137. package/dist/coordinator-auth-link-test-fixtures.d.ts.map +1 -0
  138. package/dist/coordinator-auth-link.d.ts +91 -0
  139. package/dist/coordinator-auth-link.d.ts.map +1 -0
  140. package/dist/coordinator-auth-loopback.d.ts +11 -0
  141. package/dist/coordinator-auth-loopback.d.ts.map +1 -0
  142. package/dist/coordinator-auth-proof.d.ts +4 -0
  143. package/dist/coordinator-auth-proof.d.ts.map +1 -0
  144. package/dist/coordinator-auth-schema-operator.d.ts +6 -0
  145. package/dist/coordinator-auth-schema-operator.d.ts.map +1 -0
  146. package/dist/coordinator-auth-schema.d.ts +18 -0
  147. package/dist/coordinator-auth-schema.d.ts.map +1 -0
  148. package/dist/coordinator-auth-session-bound-test-fixtures.d.ts +7 -0
  149. package/dist/coordinator-auth-session-bound-test-fixtures.d.ts.map +1 -0
  150. package/dist/coordinator-auth-session-contract.d.ts +104 -0
  151. package/dist/coordinator-auth-session-contract.d.ts.map +1 -0
  152. package/dist/coordinator-auth-session-test-fixtures.d.ts +31 -0
  153. package/dist/coordinator-auth-session-test-fixtures.d.ts.map +1 -0
  154. package/dist/coordinator-auth-session.d.ts +44 -0
  155. package/dist/coordinator-auth-session.d.ts.map +1 -0
  156. package/dist/coordinator-auth-store-test-fixtures.d.ts +26 -0
  157. package/dist/coordinator-auth-store-test-fixtures.d.ts.map +1 -0
  158. package/dist/coordinator-bootstrap-authorization-api-test-harness.d.ts +5 -0
  159. package/dist/coordinator-bootstrap-authorization-api-test-harness.d.ts.map +1 -0
  160. package/dist/coordinator-bootstrap-authorization-test-harness.d.ts +11 -0
  161. package/dist/coordinator-bootstrap-authorization-test-harness.d.ts.map +1 -0
  162. package/dist/coordinator-bootstrap-grant-authorization.d.ts +28 -0
  163. package/dist/coordinator-bootstrap-grant-authorization.d.ts.map +1 -0
  164. package/dist/coordinator-bootstrap-grant-issuance.d.ts +22 -0
  165. package/dist/coordinator-bootstrap-grant-issuance.d.ts.map +1 -0
  166. package/dist/coordinator-bootstrap-revocation-test-harness.d.ts +11 -0
  167. package/dist/coordinator-bootstrap-revocation-test-harness.d.ts.map +1 -0
  168. package/dist/coordinator-browser-account.d.ts +36 -0
  169. package/dist/coordinator-browser-account.d.ts.map +1 -0
  170. package/dist/coordinator-browser-auth-app.d.ts +84 -0
  171. package/dist/coordinator-browser-auth-app.d.ts.map +1 -0
  172. package/dist/coordinator-browser-auth-callback.d.ts +47 -0
  173. package/dist/coordinator-browser-auth-callback.d.ts.map +1 -0
  174. package/dist/coordinator-browser-auth-config.d.ts +32 -0
  175. package/dist/coordinator-browser-auth-config.d.ts.map +1 -0
  176. package/dist/coordinator-browser-credential.d.ts +40 -0
  177. package/dist/coordinator-browser-credential.d.ts.map +1 -0
  178. package/dist/coordinator-browser-csrf.d.ts +19 -0
  179. package/dist/coordinator-browser-csrf.d.ts.map +1 -0
  180. package/dist/coordinator-browser-form-body.d.ts +42 -0
  181. package/dist/coordinator-browser-form-body.d.ts.map +1 -0
  182. package/dist/coordinator-browser-form-guard.d.ts +55 -0
  183. package/dist/coordinator-browser-form-guard.d.ts.map +1 -0
  184. package/dist/coordinator-browser-link-completion.d.ts +32 -0
  185. package/dist/coordinator-browser-link-completion.d.ts.map +1 -0
  186. package/dist/coordinator-browser-link-start.d.ts +39 -0
  187. package/dist/coordinator-browser-link-start.d.ts.map +1 -0
  188. package/dist/coordinator-browser-link.d.ts +36 -0
  189. package/dist/coordinator-browser-link.d.ts.map +1 -0
  190. package/dist/coordinator-browser-request.d.ts +10 -0
  191. package/dist/coordinator-browser-request.d.ts.map +1 -0
  192. package/dist/coordinator-browser-signin-start.d.ts +38 -0
  193. package/dist/coordinator-browser-signin-start.d.ts.map +1 -0
  194. package/dist/coordinator-browser-start-transaction.d.ts +6 -0
  195. package/dist/coordinator-browser-start-transaction.d.ts.map +1 -0
  196. package/dist/coordinator-controller-revocation-test-harness.d.ts +11 -0
  197. package/dist/coordinator-controller-revocation-test-harness.d.ts.map +1 -0
  198. package/dist/coordinator-d1-scope-authorization-test-harness.d.ts +14 -0
  199. package/dist/coordinator-d1-scope-authorization-test-harness.d.ts.map +1 -0
  200. package/dist/coordinator-device-account-change.d.ts +17 -0
  201. package/dist/coordinator-device-account-change.d.ts.map +1 -0
  202. package/dist/coordinator-device-auth-link.d.ts +43 -0
  203. package/dist/coordinator-device-auth-link.d.ts.map +1 -0
  204. package/dist/coordinator-device-local.d.ts +9 -0
  205. package/dist/coordinator-device-local.d.ts.map +1 -0
  206. package/dist/coordinator-device-ownership-schema.d.ts +3 -0
  207. package/dist/coordinator-device-ownership-schema.d.ts.map +1 -0
  208. package/dist/coordinator-device-ownership-test-harness.d.ts +17 -0
  209. package/dist/coordinator-device-ownership-test-harness.d.ts.map +1 -0
  210. package/dist/coordinator-device-revocation-client.d.ts +41 -0
  211. package/dist/coordinator-device-revocation-client.d.ts.map +1 -0
  212. package/dist/coordinator-device-revocation-handler-test-harness.d.ts +4 -0
  213. package/dist/coordinator-device-revocation-handler-test-harness.d.ts.map +1 -0
  214. package/dist/coordinator-device-revocation-handler.d.ts +17 -0
  215. package/dist/coordinator-device-revocation-handler.d.ts.map +1 -0
  216. package/dist/coordinator-device-revocation-route.d.ts +14 -0
  217. package/dist/coordinator-device-revocation-route.d.ts.map +1 -0
  218. package/dist/coordinator-device-revocation-test-harness.d.ts +34 -0
  219. package/dist/coordinator-device-revocation-test-harness.d.ts.map +1 -0
  220. package/dist/coordinator-device-revocation.d.ts +67 -0
  221. package/dist/coordinator-device-revocation.d.ts.map +1 -0
  222. package/dist/coordinator-ed25519-key-id-compat.d.ts +6 -0
  223. package/dist/coordinator-ed25519-key-id-compat.d.ts.map +1 -0
  224. package/dist/coordinator-ed25519-key-id-test-fixtures.d.ts +30 -0
  225. package/dist/coordinator-ed25519-key-id-test-fixtures.d.ts.map +1 -0
  226. package/dist/coordinator-ed25519-key-id.d.ts +21 -0
  227. package/dist/coordinator-ed25519-key-id.d.ts.map +1 -0
  228. package/dist/coordinator-enrollment-revocation-test-harness.d.ts +6 -0
  229. package/dist/coordinator-enrollment-revocation-test-harness.d.ts.map +1 -0
  230. package/dist/coordinator-hono-test-fixtures.d.ts +2 -0
  231. package/dist/coordinator-hono-test-fixtures.d.ts.map +1 -0
  232. package/dist/coordinator-identity-grant-revocation-test-harness.d.ts +11 -0
  233. package/dist/coordinator-identity-grant-revocation-test-harness.d.ts.map +1 -0
  234. package/dist/coordinator-identity-group-grant-client.d.ts +9 -0
  235. package/dist/coordinator-identity-group-grant-client.d.ts.map +1 -0
  236. package/dist/coordinator-identity-group-grant-input-test-harness.d.ts +3 -0
  237. package/dist/coordinator-identity-group-grant-input-test-harness.d.ts.map +1 -0
  238. package/dist/coordinator-identity-group-grant-test-harness.d.ts +17 -0
  239. package/dist/coordinator-identity-group-grant-test-harness.d.ts.map +1 -0
  240. package/dist/coordinator-identity-group-grant.d.ts +51 -0
  241. package/dist/coordinator-identity-group-grant.d.ts.map +1 -0
  242. package/dist/coordinator-invite-review.d.ts +64 -0
  243. package/dist/coordinator-invite-review.d.ts.map +1 -0
  244. package/dist/coordinator-join-review-guards.d.ts +22 -0
  245. package/dist/coordinator-join-review-guards.d.ts.map +1 -0
  246. package/dist/coordinator-join-revocation-test-harness.d.ts +23 -0
  247. package/dist/coordinator-join-revocation-test-harness.d.ts.map +1 -0
  248. package/dist/coordinator-legacy-device-ownership.d.ts +34 -0
  249. package/dist/coordinator-legacy-device-ownership.d.ts.map +1 -0
  250. package/dist/coordinator-oidc-test-fixtures.d.ts +50 -0
  251. package/dist/coordinator-oidc-test-fixtures.d.ts.map +1 -0
  252. package/dist/coordinator-oidc.d.ts +59 -0
  253. package/dist/coordinator-oidc.d.ts.map +1 -0
  254. package/dist/coordinator-owner-attempt-migration-test-harness.d.ts +16 -0
  255. package/dist/coordinator-owner-attempt-migration-test-harness.d.ts.map +1 -0
  256. package/dist/coordinator-owner-enrollment-client.d.ts +29 -0
  257. package/dist/coordinator-owner-enrollment-client.d.ts.map +1 -0
  258. package/dist/coordinator-owner-enrollment-commit-test-fixtures.d.ts +31 -0
  259. package/dist/coordinator-owner-enrollment-commit-test-fixtures.d.ts.map +1 -0
  260. package/dist/coordinator-owner-enrollment-commit.d.ts +23 -0
  261. package/dist/coordinator-owner-enrollment-commit.d.ts.map +1 -0
  262. package/dist/coordinator-owner-enrollment-historical-test-fixture.d.ts +11 -0
  263. package/dist/coordinator-owner-enrollment-historical-test-fixture.d.ts.map +1 -0
  264. package/dist/coordinator-owner-enrollment-http.d.ts +67 -0
  265. package/dist/coordinator-owner-enrollment-http.d.ts.map +1 -0
  266. package/dist/coordinator-owner-enrollment-proof.d.ts +67 -0
  267. package/dist/coordinator-owner-enrollment-proof.d.ts.map +1 -0
  268. package/dist/coordinator-owner-enrollment-qualification-schema.d.ts +107 -0
  269. package/dist/coordinator-owner-enrollment-qualification-schema.d.ts.map +1 -0
  270. package/dist/coordinator-owner-enrollment-qualification-test-harness.d.ts +39 -0
  271. package/dist/coordinator-owner-enrollment-qualification-test-harness.d.ts.map +1 -0
  272. package/dist/coordinator-owner-enrollment-qualification.d.ts +56 -0
  273. package/dist/coordinator-owner-enrollment-qualification.d.ts.map +1 -0
  274. package/dist/coordinator-owner-enrollment-schema.d.ts +7 -0
  275. package/dist/coordinator-owner-enrollment-schema.d.ts.map +1 -0
  276. package/dist/coordinator-owner-enrollment-start-test-fixtures.d.ts +54 -0
  277. package/dist/coordinator-owner-enrollment-start-test-fixtures.d.ts.map +1 -0
  278. package/dist/coordinator-owner-enrollment-test-harness.d.ts +72 -0
  279. package/dist/coordinator-owner-enrollment-test-harness.d.ts.map +1 -0
  280. package/dist/coordinator-owner-profile-adoption.d.ts +34 -0
  281. package/dist/coordinator-owner-profile-adoption.d.ts.map +1 -0
  282. package/dist/coordinator-owner-profile-client-test-harness.d.ts +57 -0
  283. package/dist/coordinator-owner-profile-client-test-harness.d.ts.map +1 -0
  284. package/dist/coordinator-owner-profile-client.d.ts +38 -0
  285. package/dist/coordinator-owner-profile-client.d.ts.map +1 -0
  286. package/dist/coordinator-owner-profile-files.d.ts +62 -0
  287. package/dist/coordinator-owner-profile-files.d.ts.map +1 -0
  288. package/dist/coordinator-owner-qualification-http.d.ts +14 -0
  289. package/dist/coordinator-owner-qualification-http.d.ts.map +1 -0
  290. package/dist/coordinator-owner-qualification-route.d.ts +16 -0
  291. package/dist/coordinator-owner-qualification-route.d.ts.map +1 -0
  292. package/dist/coordinator-owner-review-local.d.ts +35 -0
  293. package/dist/coordinator-owner-review-local.d.ts.map +1 -0
  294. package/dist/coordinator-peer-discovery-revocation-test-harness.d.ts +21 -0
  295. package/dist/coordinator-peer-discovery-revocation-test-harness.d.ts.map +1 -0
  296. package/dist/coordinator-peer-discovery.d.ts +15 -0
  297. package/dist/coordinator-peer-discovery.d.ts.map +1 -0
  298. package/dist/coordinator-project-invite-guards.d.ts +13 -0
  299. package/dist/coordinator-project-invite-guards.d.ts.map +1 -0
  300. package/dist/coordinator-project-revocation-test-harness.d.ts +25 -0
  301. package/dist/coordinator-project-revocation-test-harness.d.ts.map +1 -0
  302. package/dist/coordinator-recipient-revocation-test-harness.d.ts +30 -0
  303. package/dist/coordinator-recipient-revocation-test-harness.d.ts.map +1 -0
  304. package/dist/coordinator-runtime.d.ts +1 -0
  305. package/dist/coordinator-runtime.d.ts.map +1 -1
  306. package/dist/coordinator-scope-authorization-api-test-harness.d.ts +8 -0
  307. package/dist/coordinator-scope-authorization-api-test-harness.d.ts.map +1 -0
  308. package/dist/coordinator-scope-authorization-response.d.ts +10 -0
  309. package/dist/coordinator-scope-authorization-response.d.ts.map +1 -0
  310. package/dist/coordinator-scope-authorization.d.ts +25 -0
  311. package/dist/coordinator-scope-authorization.d.ts.map +1 -0
  312. package/dist/coordinator-store-contract.d.ts +48 -1
  313. package/dist/coordinator-store-contract.d.ts.map +1 -1
  314. package/dist/coordinator-store.d.ts +2 -1
  315. package/dist/coordinator-store.d.ts.map +1 -1
  316. package/dist/d1-coordinator-runtime.d.ts +9 -1
  317. package/dist/d1-coordinator-runtime.d.ts.map +1 -1
  318. package/dist/d1-coordinator-store.d.ts +108 -5
  319. package/dist/d1-coordinator-store.d.ts.map +1 -1
  320. package/dist/db.d.ts.map +1 -1
  321. package/dist/export-import.d.ts +2 -0
  322. package/dist/export-import.d.ts.map +1 -1
  323. package/dist/extraction-tier-routing.d.ts.map +1 -1
  324. package/dist/filters.d.ts +8 -3
  325. package/dist/filters.d.ts.map +1 -1
  326. package/dist/index.d.ts +38 -10
  327. package/dist/index.d.ts.map +1 -1
  328. package/dist/index.js +27773 -22918
  329. package/dist/index.js.map +1 -1
  330. package/dist/ingest-pipeline.d.ts +4 -0
  331. package/dist/ingest-pipeline.d.ts.map +1 -1
  332. package/dist/ingest-xml-parser.d.ts +2 -5
  333. package/dist/ingest-xml-parser.d.ts.map +1 -1
  334. package/dist/ingest-xml-scan.d.ts +30 -0
  335. package/dist/ingest-xml-scan.d.ts.map +1 -0
  336. package/dist/internal/cloudflare-coordinator.d.ts +23 -2
  337. package/dist/internal/cloudflare-coordinator.d.ts.map +1 -1
  338. package/dist/internal/cloudflare-coordinator.js +4109 -372
  339. package/dist/internal/cloudflare-coordinator.js.map +1 -1
  340. package/dist/legacy-recipient-policy-projection.d.ts.map +1 -1
  341. package/dist/maintenance/relink.d.ts.map +1 -1
  342. package/dist/managed-scope-test-fixtures.d.ts +25 -0
  343. package/dist/managed-scope-test-fixtures.d.ts.map +1 -0
  344. package/dist/memory-creation-provenance.d.ts +13 -0
  345. package/dist/memory-creation-provenance.d.ts.map +1 -0
  346. package/dist/memory-local-capture-test-fixtures.d.ts +39 -0
  347. package/dist/memory-local-capture-test-fixtures.d.ts.map +1 -0
  348. package/dist/memory-local-capture.d.ts +29 -0
  349. package/dist/memory-local-capture.d.ts.map +1 -0
  350. package/dist/memory-ownership-recovery.d.ts.map +1 -1
  351. package/dist/memory-retirement-delivery.d.ts.map +1 -1
  352. package/dist/memory-source-identity.d.ts +3 -0
  353. package/dist/memory-source-identity.d.ts.map +1 -1
  354. package/dist/observer-client.d.ts.map +1 -1
  355. package/dist/observer-output.d.ts.map +1 -1
  356. package/dist/opencode-v2-generation.d.ts.map +1 -1
  357. package/dist/owned-recipient-d1-test-harness.d.ts +7 -0
  358. package/dist/owned-recipient-d1-test-harness.d.ts.map +1 -0
  359. package/dist/owner-browser-admission-authority.d.ts +24 -0
  360. package/dist/owner-browser-admission-authority.d.ts.map +1 -0
  361. package/dist/owner-browser-admission-body.d.ts +8 -0
  362. package/dist/owner-browser-admission-body.d.ts.map +1 -0
  363. package/dist/owner-browser-admission.d.ts +30 -0
  364. package/dist/owner-browser-admission.d.ts.map +1 -0
  365. package/dist/owner-enrollment-admission.d.ts +58 -0
  366. package/dist/owner-enrollment-admission.d.ts.map +1 -0
  367. package/dist/owner-enrollment-link-authority.d.ts +26 -0
  368. package/dist/owner-enrollment-link-authority.d.ts.map +1 -0
  369. package/dist/owner-enrollment-owner-pin-test-harness.d.ts +21 -0
  370. package/dist/owner-enrollment-owner-pin-test-harness.d.ts.map +1 -0
  371. package/dist/owner-enrollment-owner-pin.d.ts +14 -0
  372. package/dist/owner-enrollment-owner-pin.d.ts.map +1 -0
  373. package/dist/owner-enrollment-start-xsoRbhG2.js +14318 -0
  374. package/dist/owner-enrollment-start-xsoRbhG2.js.map +1 -0
  375. package/dist/owner-enrollment-start.d.ts +109 -0
  376. package/dist/owner-enrollment-start.d.ts.map +1 -0
  377. package/dist/owner-qualified-consumer-access-test-harness.d.ts +3 -0
  378. package/dist/owner-qualified-consumer-access-test-harness.d.ts.map +1 -0
  379. package/dist/owner-qualified-consumer-adversarial-test-harness.d.ts +5 -0
  380. package/dist/owner-qualified-consumer-adversarial-test-harness.d.ts.map +1 -0
  381. package/dist/owner-qualified-consumer-test-fixture.d.ts +4 -0
  382. package/dist/owner-qualified-consumer-test-fixture.d.ts.map +1 -0
  383. package/dist/owner-qualified-consumer-test-harness.d.ts +69 -0
  384. package/dist/owner-qualified-consumer-test-harness.d.ts.map +1 -0
  385. package/dist/pi-session-search.d.ts +73 -0
  386. package/dist/pi-session-search.d.ts.map +1 -0
  387. package/dist/pi-sessions-import.d.ts +72 -0
  388. package/dist/pi-sessions-import.d.ts.map +1 -0
  389. package/dist/policy-team-device-eligibility.d.ts.map +1 -1
  390. package/dist/project-scope-settings.d.ts +4 -0
  391. package/dist/project-scope-settings.d.ts.map +1 -1
  392. package/dist/{promise-B3UhYSzv.js → promise-BgC-VNzX.js} +436 -214
  393. package/dist/promise-BgC-VNzX.js.map +1 -0
  394. package/dist/{service-contender-9rqn6x4v-pocTjwT1.js → pty-handoff-9rqn6x4v-Dxw6kceQ.js} +2 -2
  395. package/dist/pty-handoff-9rqn6x4v-Dxw6kceQ.js.map +1 -0
  396. package/dist/raw-event-auth-recovery.d.ts +1 -1
  397. package/dist/raw-event-auth-recovery.d.ts.map +1 -1
  398. package/dist/raw-event-flush.d.ts.map +1 -1
  399. package/dist/recipient-policy-deny-overlay.d.ts +9 -0
  400. package/dist/recipient-policy-deny-overlay.d.ts.map +1 -0
  401. package/dist/recipient-policy-reconciliation.d.ts +1 -9
  402. package/dist/recipient-policy-reconciliation.d.ts.map +1 -1
  403. package/dist/ref-queries.d.ts +1 -1
  404. package/dist/ref-queries.d.ts.map +1 -1
  405. package/dist/schema-bootstrap.d.ts.map +1 -1
  406. package/dist/schema.d.ts +160 -0
  407. package/dist/schema.d.ts.map +1 -1
  408. package/dist/scope-membership-cache-test-fixtures.d.ts +19 -0
  409. package/dist/scope-membership-cache-test-fixtures.d.ts.map +1 -0
  410. package/dist/scope-membership-cache.d.ts +15 -2
  411. package/dist/scope-membership-cache.d.ts.map +1 -1
  412. package/dist/scope-membership-evidence.d.ts +17 -0
  413. package/dist/scope-membership-evidence.d.ts.map +1 -0
  414. package/dist/scope-membership-snapshot.d.ts +22 -0
  415. package/dist/scope-membership-snapshot.d.ts.map +1 -0
  416. package/dist/scope-membership-wire.d.ts +4 -0
  417. package/dist/scope-membership-wire.d.ts.map +1 -0
  418. package/dist/scope-resolution.d.ts +15 -37
  419. package/dist/scope-resolution.d.ts.map +1 -1
  420. package/dist/scope-stamping.d.ts +7 -0
  421. package/dist/scope-stamping.d.ts.map +1 -1
  422. package/dist/scope-write-authority-error.d.ts +5 -0
  423. package/dist/scope-write-authority-error.d.ts.map +1 -0
  424. package/dist/search.d.ts +3 -1
  425. package/dist/search.d.ts.map +1 -1
  426. package/dist/session-export-identity-mutation.d.ts +4 -0
  427. package/dist/session-export-identity-mutation.d.ts.map +1 -0
  428. package/dist/session-export-identity.d.ts +7 -0
  429. package/dist/session-export-identity.d.ts.map +1 -0
  430. package/dist/shared-owned-device-enrollment-test-harness.d.ts +33 -0
  431. package/dist/shared-owned-device-enrollment-test-harness.d.ts.map +1 -0
  432. package/dist/shared-owned-join-approval-test-harness.d.ts +9 -0
  433. package/dist/shared-owned-join-approval-test-harness.d.ts.map +1 -0
  434. package/dist/shared-owned-project-invites-test-harness.d.ts +23 -0
  435. package/dist/shared-owned-project-invites-test-harness.d.ts.map +1 -0
  436. package/dist/shared-owned-recipient-invites-test-harness.d.ts +11 -0
  437. package/dist/shared-owned-recipient-invites-test-harness.d.ts.map +1 -0
  438. package/dist/shared-ownership-writer-lifecycle-test-harness.d.ts +19 -0
  439. package/dist/shared-ownership-writer-lifecycle-test-harness.d.ts.map +1 -0
  440. package/dist/store.d.ts +81 -13
  441. package/dist/store.d.ts.map +1 -1
  442. package/dist/sync-bootstrap.d.ts.map +1 -1
  443. package/dist/sync-http-client.d.ts +1 -0
  444. package/dist/sync-http-client.d.ts.map +1 -1
  445. package/dist/sync-identity.d.ts +6 -0
  446. package/dist/sync-identity.d.ts.map +1 -1
  447. package/dist/sync-pass.d.ts.map +1 -1
  448. package/dist/sync-replication.d.ts +6 -3
  449. package/dist/sync-replication.d.ts.map +1 -1
  450. package/dist/sync-scope-protocol.d.ts +6 -0
  451. package/dist/sync-scope-protocol.d.ts.map +1 -1
  452. package/dist/sync-status-test-fixtures.d.ts +21 -0
  453. package/dist/sync-status-test-fixtures.d.ts.map +1 -0
  454. package/dist/test-schema.generated.d.ts +1 -1
  455. package/dist/test-schema.generated.d.ts.map +1 -1
  456. package/dist/vectors.d.ts.map +1 -1
  457. package/dist/wildcard-match.d.ts +9 -0
  458. package/dist/wildcard-match.d.ts.map +1 -0
  459. package/dist/workspace-identity.d.ts +18 -0
  460. package/dist/workspace-identity.d.ts.map +1 -0
  461. package/package.json +5 -4
  462. package/dist/coordinator-api-CdUQtf5l.js +0 -3755
  463. package/dist/coordinator-api-CdUQtf5l.js.map +0 -1
  464. package/dist/promise-B3UhYSzv.js.map +0 -1
  465. package/dist/service-contender-9rqn6x4v-pocTjwT1.js.map +0 -1
@@ -1,3755 +0,0 @@
1
- import { resolve as e } from "node:path";
2
- import { createHash as t } from "node:crypto";
3
- //#region src/project-identity.ts
4
- var n = /^(?:command failed(?:\s|:)|error:\s|fatal:\s|git:\s)/iu, r = /^(?:giterror|git error|git command failed):[^\r\n]*(?:not a git repository|unknown revision or path|no such remote)\b/iu;
5
- function i(e) {
6
- if (typeof e != "string") return !1;
7
- let t = e.trim();
8
- return t ? t.includes("\n") || t.includes("\r") ? !0 : n.test(t) || r.test(t) : !1;
9
- }
10
- function a(e) {
11
- let t = e?.trim();
12
- return !t || i(t) ? null : t;
13
- }
14
- //#endregion
15
- //#region src/scope-resolution.ts
16
- var o = "local-default", s = "legacy-shared-review";
17
- function c(e) {
18
- return e?.trim() || null;
19
- }
20
- function l(e) {
21
- return e.trim().replaceAll("\\", "/").replace(/\/+$/, "") || e.trim();
22
- }
23
- function u(t) {
24
- return l(e(t));
25
- }
26
- function d(e) {
27
- let t = c(e);
28
- return t ? l(t) : null;
29
- }
30
- function f(e) {
31
- let n = [
32
- e.cwd,
33
- e.project,
34
- e.workspaceId
35
- ].map((e) => a(e)).find((e) => e !== null), r = [
36
- e.gitRemote,
37
- e.gitBranch,
38
- e.cwd,
39
- e.project,
40
- e.workspaceId
41
- ].map((e) => typeof e == "string" ? e.trim() : null), o = n ?? "unknown";
42
- return !n && r.some(i) && (o = JSON.stringify(r)), `unmapped:${t("sha256").update(o, "utf8").digest("hex")}`;
43
- }
44
- function p(e) {
45
- let t = a(e.gitRemote), n = a(e.gitBranch), r = a(e.repositoryIdentity), i = a(e.cwd), o = a(e.workspaceId), s = a(e.project);
46
- if (r && !e.branchScoped) return {
47
- value: l(r),
48
- source: "git_repository",
49
- displayProject: s
50
- };
51
- if (t) {
52
- let r = l(t);
53
- return e.branchScoped && n ? {
54
- value: `${r}:${n}`,
55
- source: "git_remote_branch",
56
- displayProject: s
57
- } : {
58
- value: r,
59
- source: "git_remote",
60
- displayProject: s
61
- };
62
- }
63
- return r ? {
64
- value: l(r),
65
- source: "git_repository",
66
- displayProject: s
67
- } : i ? {
68
- value: u(i),
69
- source: "cwd",
70
- displayProject: s
71
- } : o ? {
72
- value: l(o),
73
- source: "workspace_id",
74
- displayProject: s
75
- } : {
76
- value: f(e),
77
- source: "unmapped",
78
- displayProject: s
79
- };
80
- }
81
- function m(e) {
82
- return !/[\\/:]/.test(e);
83
- }
84
- function h(e) {
85
- return e.replace(/[|\\{}()[\]^$+?.*]/g, "\\$&");
86
- }
87
- function g(e) {
88
- return e.replace(/[*?]/g, "").length;
89
- }
90
- function _(e, t) {
91
- let n = l(t);
92
- return !n || m(n) ? !1 : /[*?]/.test(n) ? RegExp(`^${h(n).replaceAll("\\*", ".*").replaceAll("\\?", ".")}$`).test(e) : e === n;
93
- }
94
- function v(e) {
95
- return e.mapping.priority ?? 0;
96
- }
97
- function y(e) {
98
- let t = c(e.mapping.updated_at);
99
- if (!t) return 0;
100
- let n = Date.parse(t);
101
- return Number.isFinite(n) ? n : 0;
102
- }
103
- function ee(e, t) {
104
- return v(t) - v(e) || t.specificity - e.specificity || y(t) - y(e) || (t.mapping.id ?? 0) - (e.mapping.id ?? 0) || e.mapping.scope_id.localeCompare(t.mapping.scope_id);
105
- }
106
- function b(e) {
107
- return e.toSorted(ee)[0] ?? null;
108
- }
109
- function x(e, t) {
110
- let n = [t.value];
111
- if (e.allowRepositoryCwdFallback === !1 || t.source !== "git_repository" && t.source !== "git_remote" && t.source !== "git_remote_branch") return n;
112
- let r = a(e.cwd);
113
- return r && n.push(u(r)), n;
114
- }
115
- function S(e, t) {
116
- let n = [t.value];
117
- if (e.allowRepositoryCwdFallback === !1 || t.source !== "git_repository" && t.source !== "git_remote" && t.source !== "git_remote_branch") return n;
118
- let r = a(e.cwd);
119
- return r && n.push(u(r)), n;
120
- }
121
- function C(e, t) {
122
- for (let n of t) {
123
- let t = b(e.filter((e) => d(e.workspace_identity) === n).map((e) => ({
124
- mapping: e,
125
- matchedPattern: null,
126
- specificity: n.length
127
- })));
128
- if (t) return t;
129
- }
130
- return null;
131
- }
132
- function w(e, t) {
133
- return b(t.flatMap((t) => e.flatMap((e) => {
134
- if (c(e.workspace_identity)) return [];
135
- let n = c(e.project_pattern);
136
- return !n || !_(t, n) ? [] : [{
137
- mapping: e,
138
- matchedPattern: l(n),
139
- specificity: g(n)
140
- }];
141
- })));
142
- }
143
- function T(e, t) {
144
- let n = [...t].map(l), r = /* @__PURE__ */ new Set();
145
- for (let t of e) {
146
- if (c(t.workspace_identity)) continue;
147
- let e = c(t.project_pattern);
148
- !e || !n.some((t) => _(t, e)) || r.add(t.scope_id);
149
- }
150
- return r;
151
- }
152
- function E(e) {
153
- let t = p(e), n = c(e.explicitScopeId);
154
- if (n) return {
155
- scopeId: n,
156
- reason: "explicit_override",
157
- workspaceIdentity: t,
158
- mapping: null,
159
- matchedPattern: null
160
- };
161
- if (t.source === "unmapped") return {
162
- scopeId: e.localDefaultScopeId ?? "local-default",
163
- reason: "local_default",
164
- workspaceIdentity: t,
165
- mapping: null,
166
- matchedPattern: null
167
- };
168
- let r = e.mappings ?? [], i = C(r, x(e, t));
169
- if (i) return {
170
- scopeId: i.mapping.scope_id,
171
- reason: "exact_mapping",
172
- workspaceIdentity: t,
173
- mapping: i.mapping,
174
- matchedPattern: null
175
- };
176
- let a = w(r, S(e, t));
177
- return a ? {
178
- scopeId: a.mapping.scope_id,
179
- reason: "pattern_mapping",
180
- workspaceIdentity: t,
181
- mapping: a.mapping,
182
- matchedPattern: a.matchedPattern
183
- } : {
184
- scopeId: e.localDefaultScopeId ?? "local-default",
185
- reason: "local_default",
186
- workspaceIdentity: t,
187
- mapping: null,
188
- matchedPattern: null
189
- };
190
- }
191
- function te(e, t) {
192
- let n = /* @__PURE__ */ new Set([
193
- "",
194
- o,
195
- s
196
- ]), r = e.prepare("SELECT scope_id\n FROM replication_scopes\n WHERE status = 'active' AND authority_type = 'local'").all();
197
- for (let e of r) e.scope_id != null && n.add(e.scope_id);
198
- let i = e.prepare("SELECT sm.scope_id AS scope_id\n FROM scope_memberships sm\n JOIN replication_scopes rs ON rs.scope_id = sm.scope_id\n WHERE sm.device_id = ?\n AND sm.status = 'active'\n AND rs.status = 'active'\n AND sm.membership_epoch >= rs.membership_epoch").all(t);
199
- for (let e of i) e.scope_id != null && n.add(e.scope_id);
200
- return [...n];
201
- }
202
- function ne(e) {
203
- if (e.devices.length > 500 || e.projects.length > 500 || e.devices.length * e.projects.length > 1e4) throw Error("legacy_team_setup_roster_too_large");
204
- }
205
- function re(e) {
206
- if (e.projectIdentities.size * e.deviceCount > 1e4) throw Error("legacy_team_setup_roster_too_large");
207
- }
208
- function ie(e, t, n) {
209
- if (n.length === 0) return;
210
- let r = [...new Set(t.map((e) => e.deviceId))], i = r.length > 0 ? `WHERE device_id NOT IN (${r.map(() => "?").join(", ")})` : "", a = Number(e.prepare(`SELECT COUNT(*) FROM identity_devices ${i}`).pluck().get(...r) ?? 0);
211
- if ((r.length + a) * n.length > 1e4) throw Error("legacy_team_setup_roster_too_large");
212
- }
213
- function ae(e, t, n, r) {
214
- if (!r) return;
215
- let i = [...new Set(t.map((e) => e.deviceId))], a = i.map(() => "?").join(", "), o = a ? `AND device_id NOT IN (${a})` : "", s = Number(e.prepare(`SELECT COUNT(*) FROM legacy_team_setup_draft_devices
216
- WHERE attempt_id = ? ${o}`).pluck().get(r, ...i) ?? 0), c = t.length + s;
217
- if (c > 500 || c * n.length > 1e4) throw Error("legacy_team_setup_roster_too_large");
218
- }
219
- //#endregion
220
- //#region src/recipient-policy-identifiers.ts
221
- function oe(e, t) {
222
- return e < t ? -1 : +(e > t);
223
- }
224
- var se = /[\p{Cc}\p{Cf}]/u;
225
- function ce(e, t) {
226
- return typeof e == "string" && e.length > 0 && e === e.trim() && e.length <= t && !se.test(e);
227
- }
228
- function le(e) {
229
- return ce(e, 256);
230
- }
231
- function ue(e) {
232
- return ce(e, 2048);
233
- }
234
- var de = "Recipient policy value must be strict JSON data";
235
- function D() {
236
- throw TypeError(de);
237
- }
238
- function fe(e) {
239
- let t = JSON.stringify(e);
240
- return t === void 0 ? D() : t;
241
- }
242
- function pe(e, t) {
243
- if (e === null) return "null";
244
- if (typeof e == "boolean") return e ? "true" : "false";
245
- if (typeof e == "string") return fe(e);
246
- if (typeof e == "number") return !Number.isFinite(e) || Object.is(e, -0) ? D() : String(e);
247
- if (typeof e != "object" || t.has(e)) return D();
248
- t.add(e);
249
- try {
250
- if (Array.isArray(e)) {
251
- if (Object.getPrototypeOf(e) !== Array.prototype) return D();
252
- let n = Reflect.ownKeys(e);
253
- if (n.length !== e.length + 1 || n.some((e) => typeof e != "string")) return D();
254
- let r = [];
255
- for (let n = 0; n < e.length; n += 1) {
256
- let i = Object.getOwnPropertyDescriptor(e, String(n));
257
- if (!i?.enumerable || !("value" in i)) return D();
258
- r.push(pe(i.value, t));
259
- }
260
- return `[${r.join(",")}]`;
261
- }
262
- let n = Object.getPrototypeOf(e);
263
- return n !== Object.prototype && n !== null ? D() : `{${Reflect.ownKeys(e).map((t) => {
264
- if (typeof t != "string") return D();
265
- let n = Object.getOwnPropertyDescriptor(e, t);
266
- return !n?.enumerable || !("value" in n) ? D() : [t, n.value];
267
- }).toSorted(([e], [t]) => oe(e, t)).map(([e, n]) => `${fe(e)}:${pe(n, t)}`).join(",")}}`;
268
- } finally {
269
- t.delete(e);
270
- }
271
- }
272
- function me(e) {
273
- return pe(e, /* @__PURE__ */ new WeakSet());
274
- }
275
- function O(e, n) {
276
- if (e.includes("\0") || !e.isWellFormed()) throw TypeError("Recipient policy digest prefix must be well-formed without NUL");
277
- return `${e}:${t("sha256").update(e, "utf8").update("\0", "utf8").update(me(n), "utf8").digest("hex")}`;
278
- }
279
- function he(e, n) {
280
- return `${e}:${t("sha256").update(me(n), "utf8").digest("hex")}`;
281
- }
282
- var ge = ["team_invite", "coordinator_invite"];
283
- function _e(e, n) {
284
- return `legacy-team-candidate:${t("sha256").update(JSON.stringify([e, n])).digest("hex").slice(0, 32)}`;
285
- }
286
- function ve(e, t) {
287
- return O("legacy-team-project-ref-v1", [e, t]);
288
- }
289
- function ye(e, t) {
290
- return O("legacy-team-canonical-project-ref-v1", [e, t]);
291
- }
292
- function be(e, t) {
293
- return O("legacy-team-device-ref-v1", [e, t]);
294
- }
295
- function xe(e) {
296
- return he("policy-team-v1", e);
297
- }
298
- function Se(e) {
299
- return O("legacy-team-roster-v1", e.map((e) => ({
300
- deviceId: e.deviceId,
301
- fingerprint: e.fingerprint,
302
- enabled: e.enabled,
303
- identityId: e.identityId
304
- })).toSorted((e, t) => oe(e.deviceId, t.deviceId)));
305
- }
306
- //#endregion
307
- //#region src/coordinator-legacy-team-completion.ts
308
- var Ce = 1, we = 50, Te = 500, Ee = 15e5, De = 25 * Ee, Oe = 256, ke = 37661024, Ae = "completion_conflict", je = class extends Error {
309
- code = Ae;
310
- constructor() {
311
- super(Ae), this.name = "CoordinatorLegacyTeamCompletionConflictError";
312
- }
313
- };
314
- function k() {
315
- throw Error("completion_manifest_invalid");
316
- }
317
- function A(e) {
318
- return (!e || typeof e != "object" || Array.isArray(e)) && k(), e;
319
- }
320
- function j(e, t) {
321
- let n = new Set(t);
322
- Object.keys(e).some((e) => !n.has(e)) && k();
323
- }
324
- function Me(e) {
325
- return /^(?:[\\/]{2}|\.{1,2}[\\/]|\/|~[\\/]|[a-z]:[\\/]|file:)/iu.test(e);
326
- }
327
- function M(e) {
328
- return (typeof e != "string" || !e || e !== e.trim() || e.length > Oe || /[\p{Cc}\p{Cf}]/u.test(e) || Me(e)) && k(), e;
329
- }
330
- function N(e) {
331
- let t = M(e);
332
- return /^[a-f0-9]{64}$/u.test(t) || k(), t;
333
- }
334
- function Ne(e) {
335
- typeof e != "string" && k();
336
- let t = e.normalize("NFC").trim();
337
- return (!t || [...t].length > 120 || /[\p{Cc}\p{Cf}]/u.test(t) || Me(t)) && k(), t;
338
- }
339
- function Pe(e) {
340
- (typeof e != "string" || !e) && k();
341
- let t = new Date(e);
342
- return (Number.isNaN(t.getTime()) || t.toISOString() !== e) && k(), e;
343
- }
344
- function Fe(e, t) {
345
- return (!Array.isArray(e) || e.length > t) && k(), e;
346
- }
347
- function Ie(e, t) {
348
- let n = e.toSorted((e, n) => oe(t(e), t(n)));
349
- return n.some((e, r) => r > 0 && t(n[r - 1]) === t(e)) && k(), n;
350
- }
351
- function Le(e) {
352
- return Ie(Fe(e, 50).map(M), (e) => e);
353
- }
354
- function Re(e) {
355
- let t = M(e);
356
- return /^legacy-team-candidate:[a-f0-9]{32}$/u.test(t) || k(), t;
357
- }
358
- function ze(e) {
359
- let t = A(e);
360
- j(t, [
361
- "version",
362
- "coordinator_id",
363
- "candidate_ref",
364
- "candidate_digest",
365
- "team_id",
366
- "team_digest",
367
- "source_digest",
368
- "finish_digest",
369
- "access_delta_digest",
370
- "team",
371
- "memberships",
372
- "device_decisions",
373
- "project_mappings",
374
- "project_recipients",
375
- "completed_at"
376
- ]), t.version !== 1 && k();
377
- let n = A(t.team);
378
- j(n, [
379
- "display_name",
380
- "policy_revision",
381
- "device_eligibility_mode"
382
- ]), n.device_eligibility_mode !== "reviewed_allowlist" && k();
383
- let r = M(t.team_id), i = Ie(Fe(t.memberships, 500).map((e) => {
384
- let t = A(e);
385
- return j(t, ["identity_id", "role"]), t.role !== "member" && k(), {
386
- identity_id: M(t.identity_id),
387
- role: "member"
388
- };
389
- }), (e) => e.identity_id), a = Ie(Fe(t.device_decisions, 500).map((e) => {
390
- let t = A(e);
391
- j(t, [
392
- "device_id",
393
- "key_fingerprint",
394
- "enabled",
395
- "identity_id",
396
- "decision"
397
- ]), t.decision !== "included" && t.decision !== "excluded" && k(), typeof t.enabled != "boolean" && k();
398
- let n = t.identity_id == null ? null : M(t.identity_id);
399
- t.decision === "included" != !!n && k(), t.decision === "included" && !t.enabled && k();
400
- let r = t.decision;
401
- return {
402
- device_id: M(t.device_id),
403
- key_fingerprint: N(t.key_fingerprint),
404
- enabled: t.enabled,
405
- identity_id: n,
406
- decision: r
407
- };
408
- }), (e) => e.device_id);
409
- a.length === 0 && k();
410
- let o = new Set(i.map((e) => e.identity_id)), s = new Set(a.flatMap((e) => e.identity_id ? [e.identity_id] : []));
411
- (o.size !== s.size || [...s].some((e) => !o.has(e))) && k();
412
- let c = Ie(Fe(t.project_mappings, 500).map((e) => {
413
- let t = A(e);
414
- j(t, [
415
- "project_ref",
416
- "resolved_project_ref",
417
- "scope_id"
418
- ]);
419
- let n = M(t.project_ref), r = M(t.resolved_project_ref);
420
- return /^legacy-team-project-ref-v1:[0-9a-f]{64}$/u.test(n) || k(), /^legacy-team-resolved-project-ref-v1:[0-9a-f]{64}$/u.test(r) || k(), {
421
- project_ref: n,
422
- resolved_project_ref: r,
423
- scope_id: M(t.scope_id)
424
- };
425
- }), (e) => e.project_ref), l = /* @__PURE__ */ new Map();
426
- for (let e of c) {
427
- let t = l.get(e.resolved_project_ref);
428
- t && t !== e.scope_id && k(), l.set(e.resolved_project_ref, e.scope_id);
429
- }
430
- let u = Ie(Fe(t.project_recipients, 500).map((e) => {
431
- let t = A(e);
432
- j(t, ["resolved_project_ref", "team_id"]);
433
- let n = M(t.team_id);
434
- n !== r && k();
435
- let i = M(t.resolved_project_ref);
436
- return /^legacy-team-resolved-project-ref-v1:[0-9a-f]{64}$/u.test(i) || k(), {
437
- resolved_project_ref: i,
438
- team_id: n
439
- };
440
- }), (e) => e.resolved_project_ref), d = [...new Set(c.map((e) => e.resolved_project_ref))].toSorted(oe), f = u.map((e) => e.resolved_project_ref);
441
- JSON.stringify(f) !== JSON.stringify(d) && k();
442
- let p = {
443
- version: 1,
444
- coordinator_id: M(t.coordinator_id),
445
- candidate_ref: Re(t.candidate_ref),
446
- candidate_digest: N(t.candidate_digest),
447
- team_id: r,
448
- team_digest: N(t.team_digest),
449
- source_digest: N(t.source_digest),
450
- finish_digest: N(t.finish_digest),
451
- access_delta_digest: N(t.access_delta_digest),
452
- team: {
453
- display_name: Ne(n.display_name),
454
- policy_revision: N(n.policy_revision),
455
- device_eligibility_mode: "reviewed_allowlist"
456
- },
457
- memberships: i,
458
- device_decisions: a,
459
- project_mappings: c,
460
- project_recipients: u,
461
- completed_at: Pe(t.completed_at)
462
- };
463
- return new TextEncoder().encode(JSON.stringify(p)).byteLength > 15e5 && k(), p;
464
- }
465
- function Be(e) {
466
- return JSON.stringify(ze(e));
467
- }
468
- function Ve(e) {
469
- e.team_id !== xe(e.candidate_ref) && k();
470
- }
471
- function He(e, t) {
472
- _e(e.coordinator_id, t) !== e.candidate_ref && k();
473
- }
474
- function Ue(e, t, n) {
475
- He(e, t);
476
- let r = new Set(e.project_mappings.map((e) => e.scope_id));
477
- n.length !== r.size && k();
478
- let i = e.coordinator_id;
479
- for (let e of n) (!e.scope_id || !r.has(e.scope_id) || e.authority_type !== "coordinator" || !e.coordinator_id || e.group_id !== t || e.status !== "active" || e.coordinator_id !== i) && k();
480
- return i;
481
- }
482
- //#endregion
483
- //#region src/coordinator-membership-effects.ts
484
- var We = "scope_membership_effect_conflict", Ge = {
485
- device_not_enrolled: "device must be enrolled and enabled in the scope group.",
486
- scope_group_mismatch: "membership groupId must match the scope groupId.",
487
- scope_inactive: "scope is not active.",
488
- scope_not_found: "scopeId must reference an existing scope."
489
- }, P = class extends Error {
490
- code;
491
- constructor(e) {
492
- super(Ge[e]), this.name = "CoordinatorMembershipError", this.code = e;
493
- }
494
- };
495
- function F(e) {
496
- return e?.trim() || null;
497
- }
498
- function Ke(e) {
499
- let t = F(e);
500
- if (!t) throw Error("effectId is required.");
501
- if (t.length > 512 || /[\p{Cc}\p{Cf}]/u.test(t)) throw Error("effectId is invalid.");
502
- return t;
503
- }
504
- function qe(e) {
505
- return JSON.stringify({
506
- scopeId: F(e.scopeId),
507
- deviceId: F(e.deviceId),
508
- role: F(e.role),
509
- membershipEpoch: e.membershipEpoch ?? null,
510
- coordinatorId: F(e.coordinatorId),
511
- groupId: F(e.groupId),
512
- manifestIssuerDeviceId: F(e.manifestIssuerDeviceId),
513
- manifestHash: F(e.manifestHash),
514
- signedManifestJson: F(e.signedManifestJson),
515
- actorType: F(e.actorType),
516
- actorId: F(e.actorId)
517
- });
518
- }
519
- function Je(e) {
520
- return JSON.stringify({
521
- scopeId: F(e.scopeId),
522
- deviceId: F(e.deviceId),
523
- groupId: F(e.groupId),
524
- membershipEpoch: e.membershipEpoch ?? null,
525
- manifestHash: F(e.manifestHash),
526
- signedManifestJson: F(e.signedManifestJson),
527
- actorType: F(e.actorType),
528
- actorId: F(e.actorId)
529
- });
530
- }
531
- function Ye(e, t, n) {
532
- if (e.action !== t || e.request_json !== n) throw Error(We);
533
- }
534
- function Xe(e) {
535
- if (e.action !== "grant" || e.outcome_applied !== 1 || e.role == null || e.status == null || e.membership_epoch == null || e.updated_at == null) throw Error("scope_membership_effect_receipt_invalid");
536
- return {
537
- scope_id: e.scope_id,
538
- device_id: e.device_id,
539
- role: e.role,
540
- status: e.status,
541
- membership_epoch: e.membership_epoch,
542
- coordinator_id: e.coordinator_id,
543
- group_id: e.group_id,
544
- manifest_issuer_device_id: e.manifest_issuer_device_id,
545
- manifest_hash: e.manifest_hash,
546
- signed_manifest_json: e.signed_manifest_json,
547
- updated_at: e.updated_at
548
- };
549
- }
550
- //#endregion
551
- //#region src/coordinator-store-contract.ts
552
- function Ze(e) {
553
- let t = e.trim(), n = new Date(t);
554
- if (!t || Number.isNaN(n.getTime())) throw Error("expiresAt must be a valid date.");
555
- return n.toISOString();
556
- }
557
- var Qe = /^identity:[A-Za-z0-9_-]{18,24}$/u;
558
- function $e(e) {
559
- return typeof e == "string" && e === e.trim() && Qe.test(e);
560
- }
561
- function et(e) {
562
- return String(e.kind === "team_member" ? e.assigned_identity_id ?? "" : e.target_identity_id ?? "").trim();
563
- }
564
- var tt = "reciprocal_approval_request_changed", nt = class extends Error {
565
- code = tt;
566
- constructor() {
567
- super(tt), this.name = "CoordinatorReciprocalApprovalRequestChangedError";
568
- }
569
- }, rt = 120, it = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/iu, at = /^(?:actor|device|identity|local):\S+$/iu, ot = /^(?:actor|device|identity)[_-][a-z0-9][a-z0-9._:-]{4,}$/iu, st = /^pending[_-]\S+$/iu, ct = /^[a-f0-9]{12,64}$/iu, lt = /^(?=.{1,253}$)(?:(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.){2,}[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?|[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.local)$/iu;
570
- function I(e, t) {
571
- if ([...e].some((e) => /[\p{Cc}\p{Cf}]/u.test(e))) throw Error(`${t}_invalid`);
572
- let n = e.replace(/\s+/gu, " ").trim();
573
- if (!n) throw Error(`${t}_required`);
574
- if ([...n].length > rt) throw Error(`${t}_too_long`);
575
- return n;
576
- }
577
- function L(e) {
578
- if (typeof e != "string") return !1;
579
- let t;
580
- try {
581
- t = I(e, "display_name");
582
- } catch {
583
- return !1;
584
- }
585
- return ![
586
- it,
587
- at,
588
- ot,
589
- st,
590
- ct
591
- ].some((e) => e.test(t));
592
- }
593
- function R(e, t) {
594
- let n = I(e, t);
595
- if (!L(n)) throw Error(`${t}_invalid`);
596
- return n;
597
- }
598
- function ut(e, t) {
599
- let n = I(e, t);
600
- if (!lt.test(n) && !L(n)) throw Error(`${t}_invalid`);
601
- return n;
602
- }
603
- function dt(e) {
604
- let t = String(e ?? "").trim(), n = t.replace(/\.local$/iu, "");
605
- return n ? ut(lt.test(t) ? n : n.replace(/[-_]+/gu, " "), "device_display_name") : null;
606
- }
607
- function ft(e) {
608
- for (let t of [
609
- e.explicitName,
610
- e.osName,
611
- e.coordinatorName
612
- ]) {
613
- let e = String(t ?? "").trim(), n = e.replace(/\.local$/iu, "");
614
- if (lt.test(e)) {
615
- try {
616
- let t = dt(e);
617
- if (t) return t;
618
- } catch {}
619
- continue;
620
- }
621
- if (!(!n || !L(n))) try {
622
- let e = dt(t);
623
- if (e && L(e)) return e;
624
- } catch {}
625
- }
626
- let t = String(e.fallbackSeed ?? "").replace(/[^a-z0-9]/giu, "").slice(0, 6);
627
- return t ? `Codemem device ${t}` : "Codemem device";
628
- }
629
- function pt(e) {
630
- if (!Array.isArray(e) || e.length === 0 || e.length > 100) throw Error("project_summaries_invalid");
631
- return e.map((e) => {
632
- if (!e || typeof e != "object" || Array.isArray(e)) throw Error("project_summaries_invalid");
633
- let t = e;
634
- if (!Number.isSafeInteger(t.existing_memory_count) || Number(t.existing_memory_count) < 0) throw Error("project_summaries_invalid");
635
- return {
636
- display_name: I(String(t.display_name ?? ""), "project_name"),
637
- existing_memory_count: Number(t.existing_memory_count)
638
- };
639
- });
640
- }
641
- //#endregion
642
- //#region src/recipient-reviewed-intent.ts
643
- var mt = 1, z = class extends Error {
644
- code;
645
- constructor(e) {
646
- super(e), this.name = "RecipientReviewedIntentError", this.code = e;
647
- }
648
- }, ht = /[\p{Cc}\p{Cf}]/u, gt = 100, _t = 65536;
649
- function B() {
650
- throw new z("recipient_reviewed_intent_invalid");
651
- }
652
- function V(e) {
653
- return (!e || typeof e != "object" || Array.isArray(e)) && B(), e;
654
- }
655
- function H(e, t) {
656
- Object.keys(e).some((e) => !t.includes(e)) && B();
657
- }
658
- function U(e, t) {
659
- return (typeof e != "string" || !e || e !== e.trim() || e.length > t || ht.test(e)) && B(), e;
660
- }
661
- function vt(e) {
662
- (typeof e != "string" || ht.test(e)) && B();
663
- let t = e.trim().replace(/\s+/gu, " ");
664
- return (!t || t.length > 256) && B(), t;
665
- }
666
- function yt(e) {
667
- typeof e != "string" && B();
668
- try {
669
- return I(e, "identity_display_name");
670
- } catch {
671
- return B();
672
- }
673
- }
674
- function bt(e) {
675
- return (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) && B(), e;
676
- }
677
- function xt(e, t) {
678
- return e < t ? -1 : +(e > t);
679
- }
680
- function St(e) {
681
- return e.kind === "direct" ? "direct" : `team\u0000${e.teamId}`;
682
- }
683
- function Ct(e) {
684
- let t = V(e);
685
- return t.kind === "direct" ? (H(t, ["kind"]), { kind: "direct" }) : (t.kind !== "team" && B(), H(t, [
686
- "kind",
687
- "teamId",
688
- "displayName"
689
- ]), {
690
- kind: "team",
691
- teamId: U(t.teamId, 256),
692
- displayName: vt(t.displayName)
693
- });
694
- }
695
- function wt(e) {
696
- let t = V(e);
697
- H(t, [
698
- "canonicalProjectIdentity",
699
- "displayName",
700
- "existingMemoryCount",
701
- "futureMemoriesShared",
702
- "sources"
703
- ]), (t.futureMemoriesShared !== !0 || !Array.isArray(t.sources) || !t.sources.length) && B();
704
- let n = t.sources.map(Ct).toSorted((e, t) => xt(St(e), St(t)));
705
- return new Set(n.map(St)).size !== n.length && B(), {
706
- canonicalProjectIdentity: U(t.canonicalProjectIdentity, 512),
707
- displayName: vt(t.displayName),
708
- existingMemoryCount: bt(t.existingMemoryCount),
709
- futureMemoriesShared: !0,
710
- sources: n
711
- };
712
- }
713
- function Tt(e) {
714
- let t = V(e);
715
- return H(t, [
716
- "canonicalProjectIdentity",
717
- "displayName",
718
- "existingMemoryCount"
719
- ]), {
720
- canonicalProjectIdentity: U(t.canonicalProjectIdentity, 512),
721
- displayName: vt(t.displayName),
722
- existingMemoryCount: bt(t.existingMemoryCount)
723
- };
724
- }
725
- function Et(e) {
726
- (!Array.isArray(e.projects) || !Array.isArray(e.excludedProjects) || e.projects.length > gt) && B();
727
- let t = e.projects.map(wt).toSorted((e, t) => xt(e.canonicalProjectIdentity, t.canonicalProjectIdentity)), n = e.excludedProjects.map(Tt).toSorted((e, t) => xt(e.canonicalProjectIdentity, t.canonicalProjectIdentity)), r = t.map((e) => e.canonicalProjectIdentity), i = n.map((e) => e.canonicalProjectIdentity);
728
- return (new Set(r).size !== r.length || new Set(i).size !== i.length || i.some((e) => r.includes(e))) && B(), {
729
- projects: t,
730
- excludedProjects: n
731
- };
732
- }
733
- function Dt(e, t) {
734
- if (!(e.journey === "team" && t.kind === "team_member" && e.team.teamId === t.policyTeamId || e.journey === "add_device" && t.kind === "add_device" && e.targetIdentity.identityId === t.targetIdentityId)) throw new z("recipient_invite_intent_mismatch");
735
- }
736
- function Ot(e, t) {
737
- let n = V(e);
738
- n.version !== 1 && B();
739
- let r = Et(n), i;
740
- if (n.journey === "team") {
741
- H(n, [
742
- "version",
743
- "journey",
744
- "team",
745
- "projects",
746
- "excludedProjects"
747
- ]);
748
- let e = V(n.team);
749
- H(e, [
750
- "teamId",
751
- "displayName",
752
- "futureProjectsInherit"
753
- ]), e.futureProjectsInherit !== !0 && B(), i = {
754
- version: 1,
755
- journey: "team",
756
- team: {
757
- teamId: U(e.teamId, 256),
758
- displayName: vt(e.displayName),
759
- futureProjectsInherit: !0
760
- },
761
- ...r
762
- };
763
- } else if (n.journey === "add_device") {
764
- H(n, [
765
- "version",
766
- "journey",
767
- "targetIdentity",
768
- "projects",
769
- "excludedProjects"
770
- ]);
771
- let e = V(n.targetIdentity);
772
- H(e, ["identityId", "displayName"]), i = {
773
- version: 1,
774
- journey: "add_device",
775
- targetIdentity: {
776
- identityId: U(e.identityId, 256),
777
- displayName: yt(e.displayName)
778
- },
779
- ...r
780
- };
781
- } else B();
782
- return t && Dt(i, t), new TextEncoder().encode(W(i)).byteLength > _t && B(), i;
783
- }
784
- function W(e) {
785
- return Array.isArray(e) ? `[${e.map(W).join(",")}]` : e && typeof e == "object" ? `{${Object.entries(e).toSorted(([e], [t]) => xt(e, t)).map(([e, t]) => `${JSON.stringify(e)}:${W(t)}`).join(",")}}` : JSON.stringify(e) ?? "null";
786
- }
787
- function kt(e, t) {
788
- return W(Ot(e, t));
789
- }
790
- async function At(e, t) {
791
- let n = kt(e, t), r = new TextEncoder().encode(`recipient-reviewed-intent-v1\n${n}`), i = await globalThis.crypto.subtle.digest("SHA-256", r);
792
- return Array.from(new Uint8Array(i), (e) => e.toString(16).padStart(2, "0")).join("");
793
- }
794
- async function G(e, t) {
795
- let n = Ot(e, t.target);
796
- if (await At(n) !== t.digest) throw new z("recipient_invite_intent_mismatch");
797
- return n;
798
- }
799
- async function jt(e, t) {
800
- if (!e) throw Error("recipient_invite_review_unavailable");
801
- let n;
802
- try {
803
- n = JSON.parse(e);
804
- } catch {
805
- throw Error("recipient_invite_review_unavailable");
806
- }
807
- try {
808
- let r = Ot(n, t.target);
809
- if (W(r) !== e) throw Error("recipient_invite_review_unavailable");
810
- return await G(r, t);
811
- } catch (e) {
812
- throw e instanceof z && e.code === "recipient_invite_intent_mismatch" || e instanceof Error && e.message === "recipient_invite_review_unavailable" ? e : Error("recipient_invite_review_unavailable");
813
- }
814
- }
815
- //#endregion
816
- //#region src/coordinator-store-input-rules.ts
817
- function Mt(e) {
818
- let t = e.trim();
819
- if (!t) return "";
820
- let n = t.includes("://") ? t : `http://${t}`;
821
- try {
822
- let e = new URL(n);
823
- return !e.hostname || e.port && (Number(e.port) <= 0 || Number(e.port) > 65535) ? "" : e.origin + e.pathname.replace(/\/+$/, "");
824
- } catch {
825
- return "";
826
- }
827
- }
828
- function Nt(e) {
829
- if (!e) return "";
830
- try {
831
- let t = new URL(e), n = t.hostname.toLowerCase();
832
- if ((t.protocol === "http:" || t.protocol === "") && n && t.port && t.pathname === "/") return `${n}:${t.port}`;
833
- } catch {}
834
- return e;
835
- }
836
- function Pt(e, t) {
837
- let n = [], r = /* @__PURE__ */ new Set();
838
- for (let i of [...e, ...t]) {
839
- let e = Mt(i), t = Nt(e);
840
- !e || r.has(t) || (r.add(t), n.push(e));
841
- }
842
- return n;
843
- }
844
- function Ft(e) {
845
- if (!e) return null;
846
- let t = String(e.seedDeviceId ?? "").trim(), n = String(e.expiresAt ?? "").trim(), r = String(e.createdBy ?? "").trim() || null;
847
- if (!t || !n) throw Error("bootstrapGrant.seedDeviceId and expiresAt are required.");
848
- return {
849
- groupId: "",
850
- seedDeviceId: t,
851
- workerDeviceId: "",
852
- expiresAt: n,
853
- createdBy: r
854
- };
855
- }
856
- function It(e) {
857
- let t = String(e.groupId ?? "").trim(), n = String(e.seedDeviceId ?? "").trim(), r = String(e.workerDeviceId ?? "").trim(), i = String(e.expiresAt ?? "").trim(), a = String(e.createdBy ?? "").trim() || null;
858
- if (!t || !n || !r || !i) throw Error("groupId, seedDeviceId, workerDeviceId, and expiresAt are required.");
859
- return {
860
- groupId: t,
861
- seedDeviceId: n,
862
- workerDeviceId: r,
863
- expiresAt: i,
864
- createdBy: a
865
- };
866
- }
867
- function K(e) {
868
- return e?.trim() || null;
869
- }
870
- var Lt = /* @__PURE__ */ new Set([
871
- "legacy_enrollment",
872
- "project_share",
873
- "team_member",
874
- "add_device"
875
- ]);
876
- function Rt(e) {
877
- if (!Lt.has(e.inviteKind)) throw Error("inviteKind is invalid.");
878
- if ([e.policyTeamId, e.targetIdentityId].filter((e) => !!e).some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) throw Error("recipient invite identifier is invalid.");
879
- if (e.reviewedPreviewDigest && !/^[a-f0-9]{64}$/u.test(e.reviewedPreviewDigest)) throw Error("reviewedPreviewDigest must be a SHA-256 digest.");
880
- }
881
- var zt = {
882
- project_share(e, t) {
883
- if (!e) throw Error("project_share invite requires operationId.");
884
- if (t.policyTeamId || t.targetIdentityId || t.reviewedPreviewDigest) throw Error("recipient invite metadata requires a recipient invite kind.");
885
- },
886
- legacy_enrollment(e, t) {
887
- if (e) throw Error("legacy_enrollment invite cannot reference an operation.");
888
- if (t.policyTeamId || t.targetIdentityId || t.reviewedPreviewDigest) throw Error("recipient invite metadata requires a recipient invite kind.");
889
- },
890
- team_member(e, t) {
891
- if (!t.policyTeamId || !t.reviewedPreviewDigest || t.targetIdentityId || e) throw Error("team_member invite metadata is invalid.");
892
- },
893
- add_device(e, t) {
894
- if (!t.targetIdentityId || !t.reviewedPreviewDigest || t.policyTeamId || e) throw Error("add_device invite metadata is invalid.");
895
- }
896
- };
897
- function Bt(e, t) {
898
- zt[t.inviteKind](K(e.operationId), t);
899
- }
900
- function Vt(e) {
901
- if (e.inviteKind === "team_member" && e.policyTeamId && e.reviewedPreviewDigest) return {
902
- target: {
903
- kind: "team_member",
904
- policyTeamId: e.policyTeamId
905
- },
906
- digest: e.reviewedPreviewDigest
907
- };
908
- if (e.inviteKind === "add_device" && e.targetIdentityId && e.reviewedPreviewDigest) return {
909
- target: {
910
- kind: "add_device",
911
- targetIdentityId: e.targetIdentityId
912
- },
913
- digest: e.reviewedPreviewDigest
914
- };
915
- throw Error("recipient invite metadata requires a recipient invite kind.");
916
- }
917
- async function Ht(e) {
918
- let t = {
919
- inviteKind: e.inviteKind ?? (K(e.operationId) ? "project_share" : "legacy_enrollment"),
920
- policyTeamId: K(e.policyTeamId),
921
- targetIdentityId: K(e.targetIdentityId),
922
- reviewedPreviewDigest: K(e.reviewedPreviewDigest)
923
- };
924
- if (Rt(t), Bt(e, t), e.reviewedIntent === void 0 || e.reviewedIntent === null) {
925
- if (t.inviteKind === "team_member" || t.inviteKind === "add_device") throw Error("recipient_invite_review_unavailable");
926
- return {
927
- ...t,
928
- reviewedIntentJson: null
929
- };
930
- }
931
- let n = Vt(t);
932
- return await G(e.reviewedIntent, {
933
- target: n.target,
934
- digest: n.digest
935
- }), {
936
- ...t,
937
- reviewedIntentJson: kt(e.reviewedIntent, n.target)
938
- };
939
- }
940
- async function Ut(e) {
941
- if (e.invite_kind === "team_member") {
942
- if (!e.policy_team_id || !$e(e.assigned_identity_id) || !e.reviewed_preview_digest) throw Error("invite_invalid");
943
- let t = await jt(e.reviewed_intent_json, {
944
- target: {
945
- kind: "team_member",
946
- policyTeamId: e.policy_team_id
947
- },
948
- digest: e.reviewed_preview_digest
949
- });
950
- return {
951
- kind: "team_member",
952
- invite: e,
953
- policy_team_id: e.policy_team_id,
954
- assigned_identity_id: e.assigned_identity_id,
955
- reviewed_preview_digest: e.reviewed_preview_digest,
956
- reviewed_intent: t,
957
- bound: !!e.consumed_at
958
- };
959
- }
960
- if (e.invite_kind === "add_device") {
961
- if (!e.target_identity_id || !e.reviewed_preview_digest) throw Error("invite_invalid");
962
- let t = await jt(e.reviewed_intent_json, {
963
- target: {
964
- kind: "add_device",
965
- targetIdentityId: e.target_identity_id
966
- },
967
- digest: e.reviewed_preview_digest
968
- });
969
- return {
970
- kind: "add_device",
971
- invite: e,
972
- target_identity_id: e.target_identity_id,
973
- reviewed_preview_digest: e.reviewed_preview_digest,
974
- reviewed_intent: t,
975
- bound: !!e.consumed_at
976
- };
977
- }
978
- return null;
979
- }
980
- function Wt(e, t = 0) {
981
- if (e == null) return t;
982
- if (!Number.isFinite(e) || e < 0) throw Error("membershipEpoch must be non-negative.");
983
- return Math.trunc(e);
984
- }
985
- function Gt(e) {
986
- let t = K(e.scopeId), n = K(e.label);
987
- if (!t || !n) throw Error("scopeId and label are required.");
988
- return {
989
- scopeId: t,
990
- label: n,
991
- kind: K(e.kind) ?? "user",
992
- authorityType: K(e.authorityType) ?? "coordinator",
993
- coordinatorId: K(e.coordinatorId),
994
- groupId: K(e.groupId),
995
- manifestIssuerDeviceId: K(e.manifestIssuerDeviceId),
996
- membershipEpoch: Wt(e.membershipEpoch),
997
- manifestHash: K(e.manifestHash),
998
- status: K(e.status) ?? "active"
999
- };
1000
- }
1001
- function Kt(e, t, n) {
1002
- if (e === void 0) return t;
1003
- let r = K(e);
1004
- if (!r) throw Error(`${n} must not be empty.`);
1005
- return r;
1006
- }
1007
- function qt(e, t) {
1008
- return e === void 0 ? t : K(e);
1009
- }
1010
- function Jt(e, t) {
1011
- let n = K(e.scopeId);
1012
- if (!n) throw Error("scopeId is required.");
1013
- let r = e.membershipEpoch == null ? null : Wt(e.membershipEpoch);
1014
- if (r != null && r < t.membership_epoch) throw Error("membershipEpoch must not move backwards.");
1015
- return {
1016
- scopeId: n,
1017
- label: Kt(e.label, t.label, "label"),
1018
- kind: Kt(e.kind, t.kind, "kind"),
1019
- authorityType: Kt(e.authorityType, t.authority_type, "authorityType"),
1020
- coordinatorId: qt(e.coordinatorId, t.coordinator_id),
1021
- groupId: qt(e.groupId, t.group_id),
1022
- manifestIssuerDeviceId: qt(e.manifestIssuerDeviceId, t.manifest_issuer_device_id),
1023
- membershipEpoch: r ?? t.membership_epoch,
1024
- manifestHash: qt(e.manifestHash, t.manifest_hash),
1025
- status: Kt(e.status, t.status, "status")
1026
- };
1027
- }
1028
- function Yt(e, t, n) {
1029
- let r = K(e.scopeId), i = K(e.deviceId);
1030
- if (!r || !i) throw Error("scopeId and deviceId are required.");
1031
- Xt(e, t);
1032
- let a = Zt(e, t, n);
1033
- return {
1034
- scopeId: r,
1035
- deviceId: i,
1036
- role: K(e.role) ?? "member",
1037
- membershipEpoch: a,
1038
- coordinatorId: t?.coordinator_id ?? null,
1039
- groupId: t?.group_id ?? null,
1040
- manifestIssuerDeviceId: K(e.manifestIssuerDeviceId) ?? t?.manifest_issuer_device_id ?? null,
1041
- manifestHash: K(e.manifestHash) ?? t?.manifest_hash ?? null,
1042
- signedManifestJson: K(e.signedManifestJson),
1043
- actorType: K(e.actorType),
1044
- actorId: K(e.actorId)
1045
- };
1046
- }
1047
- function Xt(e, t) {
1048
- if (K(e.coordinatorId) && K(e.coordinatorId) !== t?.coordinator_id) throw Error("membership coordinatorId must match the scope coordinatorId.");
1049
- if (K(e.groupId) && K(e.groupId) !== t?.group_id) throw new P("scope_group_mismatch");
1050
- }
1051
- function Zt(e, t, n) {
1052
- let r = e.membershipEpoch == null ? null : Wt(e.membershipEpoch), i = t?.membership_epoch ?? 0;
1053
- if (r != null && r < i) throw Error("membershipEpoch must not be lower than the scope membershipEpoch.");
1054
- if (r != null && n && r < (n.status === "revoked" ? n.membership_epoch + 1 : n.membership_epoch)) throw Error("membershipEpoch must not move backwards.");
1055
- return r ?? (n ? Math.max(i, n.membership_epoch + +(n.status === "revoked")) : i);
1056
- }
1057
- function Qt(e) {
1058
- return e == null || !Number.isFinite(e) ? 100 : Math.max(1, Math.min(1e3, Math.trunc(e)));
1059
- }
1060
- //#endregion
1061
- //#region src/sync-fingerprint.ts
1062
- function $t(e) {
1063
- return t("sha256").update(e, "utf-8").digest("hex");
1064
- }
1065
- //#endregion
1066
- //#region ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/compose.js
1067
- var en = (e, t, n) => (r, i) => {
1068
- let a = -1;
1069
- return o(0);
1070
- async function o(s) {
1071
- if (s <= a) throw Error("next() called multiple times");
1072
- a = s;
1073
- let c, l = !1, u;
1074
- if (e[s] ? (u = e[s][0][0], r.req.routeIndex = s) : u = s === e.length && i || void 0, u) try {
1075
- c = await u(r, () => o(s + 1));
1076
- } catch (e) {
1077
- if (e instanceof Error && t) r.error = e, c = await t(e, r), l = !0;
1078
- else throw e;
1079
- }
1080
- else r.finalized === !1 && n && (c = await n(r));
1081
- return c && (r.finalized === !1 || l) && (r.res = c), r;
1082
- }
1083
- }, tn = /* @__PURE__ */ Symbol(), nn = (e, t) => new Response(e, { headers: { "Content-Type": t.replace(/^[^;]+/, (e) => e.toLowerCase()) } }).formData(), rn = 32, an = 1e4, on = (e) => "headers" in e, sn = async (e, t = /* @__PURE__ */ Object.create(null)) => {
1084
- let { all: n = !1, dot: r = !1 } = t, i = (on(e) ? e.headers : e.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();
1085
- return i === "multipart/form-data" || i === "application/x-www-form-urlencoded" ? cn(e, {
1086
- all: n,
1087
- dot: r
1088
- }) : {};
1089
- };
1090
- async function cn(e, t) {
1091
- if (!on(e) && e.bodyCache.formData) return ln(await e.bodyCache.formData, t);
1092
- let n = on(e) ? e.headers : e.raw.headers, r = nn(await e.arrayBuffer(), n.get("Content-Type") || "");
1093
- on(e) || (e.bodyCache.formData = r);
1094
- let i = await r;
1095
- return i ? ln(i, t) : {};
1096
- }
1097
- function ln(e, t) {
1098
- let n = /* @__PURE__ */ Object.create(null), r = { count: 0 };
1099
- return e.forEach((e, r) => {
1100
- t.all || r.endsWith("[]") ? un(n, r, e) : n[r] = e;
1101
- }), t.dot && Object.entries(n).forEach(([e, t]) => {
1102
- e.includes(".") && (dn(n, e, t, r), delete n[e]);
1103
- }), n;
1104
- }
1105
- var un = (e, t, n) => {
1106
- e[t] === void 0 ? e[t] = t.endsWith("[]") ? [n] : n : Array.isArray(e[t]) ? e[t].push(n) : e[t] = [e[t], n];
1107
- }, dn = (e, t, n, r) => {
1108
- if (/(?:^|\.)__proto__\./.test(t)) return;
1109
- let i = e, a = t.split(".", rn + 2);
1110
- a.length > rn + 1 && fn(), a.forEach((e, t) => {
1111
- t === a.length - 1 ? i[e] = n : ((!i[e] || typeof i[e] != "object" || Array.isArray(i[e]) || i[e] instanceof File) && (r.count++ >= an && fn(), i[e] = /* @__PURE__ */ Object.create(null)), i = i[e]);
1112
- });
1113
- }, fn = () => {
1114
- throw Error("Nesting limit exceeded");
1115
- }, pn = (e) => {
1116
- let t = e.split("/");
1117
- return t[0] === "" && t.shift(), t;
1118
- }, mn = (e) => {
1119
- let { groups: t, path: n } = hn(e);
1120
- return gn(pn(n), t);
1121
- }, hn = (e) => {
1122
- let t = [];
1123
- return e = e.replace(/\{[^}]+\}/g, (e, n) => {
1124
- let r = `@${n}`;
1125
- return t.push([r, e]), r;
1126
- }), {
1127
- groups: t,
1128
- path: e
1129
- };
1130
- }, gn = (e, t) => {
1131
- for (let n = t.length - 1; n >= 0; n--) {
1132
- let [r] = t[n];
1133
- for (let i = e.length - 1; i >= 0; i--) if (e[i].includes(r)) {
1134
- e[i] = e[i].replace(r, t[n][1]);
1135
- break;
1136
- }
1137
- }
1138
- return e;
1139
- }, _n = {}, vn = (e, t) => {
1140
- if (e === "*") return "*";
1141
- let n = e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
1142
- if (n) {
1143
- let r = `${e}#${t}`;
1144
- return _n[r] || (_n[r] = n[2] ? t && t[0] !== ":" && t[0] !== "*" ? [
1145
- r,
1146
- n[1],
1147
- RegExp(`^${n[2]}(?=/${t})`)
1148
- ] : [
1149
- e,
1150
- n[1],
1151
- RegExp(`^${n[2]}$`)
1152
- ] : [
1153
- e,
1154
- n[1],
1155
- !0
1156
- ]), _n[r];
1157
- }
1158
- return null;
1159
- }, yn = (e, t) => {
1160
- try {
1161
- return t(e);
1162
- } catch {
1163
- return e.replace(/(?:%[0-9A-Fa-f]{2})+/g, (e) => {
1164
- try {
1165
- return t(e);
1166
- } catch {
1167
- return e;
1168
- }
1169
- });
1170
- }
1171
- }, bn = (e) => yn(e, decodeURI), xn = (e) => {
1172
- let t = e.url, n = t.indexOf("/", t.indexOf(":") + 4), r = n;
1173
- for (; r < t.length; r++) {
1174
- let e = t.charCodeAt(r);
1175
- if (e === 37) {
1176
- let e = t.indexOf("?", r), i = t.indexOf("#", r), a = e === -1 ? i === -1 ? void 0 : i : i === -1 ? e : Math.min(e, i), o = t.slice(n, a);
1177
- return bn(o.includes("%25") ? o.replace(/%25/g, "%2525") : o);
1178
- }
1179
- if (e === 63 || e === 35) break;
1180
- }
1181
- return t.slice(n, r);
1182
- }, Sn = (e) => {
1183
- let t = xn(e);
1184
- return t.length > 1 && t.at(-1) === "/" ? t.slice(0, -1) : t;
1185
- }, q = (e, t, ...n) => (n.length && (t = q(t, ...n)), `${e?.[0] === "/" ? "" : "/"}${e}${t === "/" ? "" : `${e?.at(-1) === "/" ? "" : "/"}${t?.[0] === "/" ? t.slice(1) : t}`}`), Cn = (e) => {
1186
- if (e.charCodeAt(e.length - 1) !== 63 || !e.includes(":")) return null;
1187
- let t = e.split("/"), n = [], r = "";
1188
- return t.forEach((e) => {
1189
- if (e !== "" && !/\:/.test(e)) r += "/" + e;
1190
- else if (/\:/.test(e)) {
1191
- if (e.charCodeAt(e.length - 1) === 63) {
1192
- n.length === 0 && r === "" ? n.push("/") : n.push(r);
1193
- let t = e.slice(0, -1);
1194
- r += "/" + t, n.push(r);
1195
- } else r += "/" + e;
1196
- }
1197
- }), n.filter((e, t, n) => n.indexOf(e) === t);
1198
- }, wn = (e) => e.indexOf("%") === -1 ? e : yn(e, kn), Tn = (e) => (e.indexOf("+") !== -1 && (e = e.replace(/\+/g, " ")), wn(e)), En = (e, t, n) => {
1199
- let r = e.indexOf("#", 8);
1200
- r !== -1 && (e = e.slice(0, r));
1201
- let i;
1202
- if (!n && t && t.indexOf("%") === -1 && t.indexOf("+") === -1) {
1203
- let n = e.indexOf("?", 8);
1204
- if (n === -1) return;
1205
- for (e.startsWith(t, n + 1) || (n = e.indexOf(`&${t}`, n + 1)); n !== -1;) {
1206
- let r = e.charCodeAt(n + t.length + 1);
1207
- if (r === 61) {
1208
- let r = n + t.length + 2, i = e.indexOf("&", r);
1209
- return Tn(e.slice(r, i === -1 ? void 0 : i));
1210
- }
1211
- if (r == 38 || isNaN(r)) return "";
1212
- n = e.indexOf(`&${t}`, n + 1);
1213
- }
1214
- if (i = /[%+]/.test(e), !i) return;
1215
- }
1216
- let a = /* @__PURE__ */ Object.create(null);
1217
- i ??= /[%+]/.test(e);
1218
- let o = e.indexOf("?", 8);
1219
- for (; o !== -1;) {
1220
- let t = e.indexOf("&", o + 1), r = e.indexOf("=", o);
1221
- r > t && t !== -1 && (r = -1);
1222
- let s = e.slice(o + 1, r === -1 ? t === -1 ? void 0 : t : r);
1223
- if (i && (s = Tn(s)), o = t, s === "") continue;
1224
- let c;
1225
- r === -1 ? c = "" : (c = e.slice(r + 1, t === -1 ? void 0 : t), i && (c = Tn(c))), n ? (a[s] && Array.isArray(a[s]) || (a[s] = []), a[s].push(c)) : a[s] ??= c;
1226
- }
1227
- return t ? a[t] : a;
1228
- }, Dn = En, On = (e, t) => En(e, t, !0), kn = decodeURIComponent, An = class {
1229
- raw;
1230
- #e;
1231
- #t;
1232
- routeIndex = 0;
1233
- path;
1234
- bodyCache = {};
1235
- constructor(e, t = "/", n = [[]]) {
1236
- this.raw = e, this.path = t, this.#t = n;
1237
- }
1238
- param(e) {
1239
- return e ? this.#n(e) : this.#r();
1240
- }
1241
- #n(e) {
1242
- let t = this.#t[0][this.routeIndex]?.[1][e], n = this.#i(t);
1243
- return n && wn(n);
1244
- }
1245
- #r() {
1246
- let e = {}, t = Object.keys(this.#t[0][this.routeIndex]?.[1] ?? {});
1247
- for (let n of t) {
1248
- let t = this.#i(this.#t[0][this.routeIndex][1][n]);
1249
- t !== void 0 && (e[n] = wn(t));
1250
- }
1251
- return e;
1252
- }
1253
- #i(e) {
1254
- return this.#t[1] ? this.#t[1][e] : e;
1255
- }
1256
- query(e) {
1257
- return Dn(this.url, e);
1258
- }
1259
- queries(e) {
1260
- return On(this.url, e);
1261
- }
1262
- header(e) {
1263
- if (e) return this.raw.headers.get(e) ?? void 0;
1264
- let t = /* @__PURE__ */ Object.create(null);
1265
- return this.raw.headers.forEach((e, n) => {
1266
- t[n] = e;
1267
- }), t;
1268
- }
1269
- async parseBody(e) {
1270
- return sn(this, e);
1271
- }
1272
- #a = (e) => {
1273
- let { bodyCache: t, raw: n } = this, r = t[e];
1274
- if (r) return r;
1275
- for (let n in t) return t[n].then((t) => (n === "json" && (t = JSON.stringify(t)), new Response(t)[e]()));
1276
- return t[e] = n[e]();
1277
- };
1278
- json() {
1279
- return this.#a("text").then((e) => JSON.parse(e));
1280
- }
1281
- text() {
1282
- return this.#a("text");
1283
- }
1284
- arrayBuffer() {
1285
- return this.#a("arrayBuffer");
1286
- }
1287
- bytes() {
1288
- return this.#a("arrayBuffer").then((e) => new Uint8Array(e));
1289
- }
1290
- blob() {
1291
- return this.#a("blob");
1292
- }
1293
- formData() {
1294
- return this.#a("formData");
1295
- }
1296
- addValidatedData(e, t) {
1297
- (this.#e ??= {})[e] = t;
1298
- }
1299
- valid(e) {
1300
- return this.#e?.[e];
1301
- }
1302
- get url() {
1303
- return this.raw.url;
1304
- }
1305
- get method() {
1306
- return this.raw.method;
1307
- }
1308
- get [tn]() {
1309
- return this.#t;
1310
- }
1311
- get matchedRoutes() {
1312
- return this.#t[0].map(([[, e]]) => e);
1313
- }
1314
- get routePath() {
1315
- return this.#t[0].map(([[, e]]) => e)[this.routeIndex].path;
1316
- }
1317
- }, jn = {
1318
- Stringify: 1,
1319
- BeforeStream: 2,
1320
- Stream: 3
1321
- }, Mn = (e, t) => {
1322
- let n = new String(e);
1323
- return n.isEscaped = !0, n.callbacks = t, n;
1324
- }, Nn = async (e, t, n, r, i) => {
1325
- typeof e == "object" && !(e instanceof String) && (e instanceof Promise || (e = e.toString()), e instanceof Promise && (e = await e));
1326
- let a = e.callbacks;
1327
- if (!a?.length) return Promise.resolve(e);
1328
- i ? i[0] += e : i = [e];
1329
- let o = Promise.all(a.map((e) => e({
1330
- phase: t,
1331
- buffer: i,
1332
- context: r
1333
- }))).then((e) => Promise.all(e.filter(Boolean).map((e) => Nn(e, t, !1, r, i))).then(() => i[0]));
1334
- return n ? Mn(await o, a) : o;
1335
- }, Pn = "text/plain; charset=UTF-8", Fn = (e, t) => ({
1336
- "Content-Type": e,
1337
- ...t
1338
- }), J = (e, t) => new Response(e, t), In = class {
1339
- #e;
1340
- #t;
1341
- env = {};
1342
- #n;
1343
- finalized = !1;
1344
- error;
1345
- #r;
1346
- #i;
1347
- #a;
1348
- #o;
1349
- #s;
1350
- #c;
1351
- #l;
1352
- #u;
1353
- #d;
1354
- constructor(e, t) {
1355
- this.#e = e, t && (this.#i = t.executionCtx, this.env = t.env, this.#c = t.notFoundHandler, this.#d = t.path, this.#u = t.matchResult);
1356
- }
1357
- get req() {
1358
- return this.#t ??= new An(this.#e, this.#d, this.#u), this.#t;
1359
- }
1360
- get event() {
1361
- if (this.#i && "respondWith" in this.#i) return this.#i;
1362
- throw Error("This context has no FetchEvent");
1363
- }
1364
- get executionCtx() {
1365
- if (this.#i) return this.#i;
1366
- throw Error("This context has no ExecutionContext");
1367
- }
1368
- get res() {
1369
- return this.#a ||= J(null, { headers: this.#l ??= new Headers() });
1370
- }
1371
- set res(e) {
1372
- if (this.#a && e) {
1373
- e = J(e.body, e);
1374
- for (let [t, n] of this.#a.headers.entries()) if (t !== "content-type") {
1375
- if (t === "set-cookie") {
1376
- let t = this.#a.headers.getSetCookie();
1377
- e.headers.delete("set-cookie");
1378
- for (let n of t) e.headers.append("set-cookie", n);
1379
- } else e.headers.set(t, n);
1380
- }
1381
- }
1382
- this.#a = e, this.finalized = !0;
1383
- }
1384
- render = (...e) => (this.#s ??= (e) => this.html(e), this.#s(...e));
1385
- setLayout = (e) => this.#o = e;
1386
- getLayout = () => this.#o;
1387
- setRenderer = (e) => {
1388
- this.#s = e;
1389
- };
1390
- header = (e, t, n) => {
1391
- this.finalized && (this.#a = J(this.#a.body, this.#a));
1392
- let r = this.#a ? this.#a.headers : this.#l ??= new Headers();
1393
- t === void 0 ? r.delete(e) : n?.append ? r.append(e, t) : r.set(e, t);
1394
- };
1395
- status = (e) => {
1396
- this.#r = e;
1397
- };
1398
- set = (e, t) => {
1399
- this.#n ??= /* @__PURE__ */ new Map(), this.#n.set(e, t);
1400
- };
1401
- get = (e) => this.#n ? this.#n.get(e) : void 0;
1402
- get var() {
1403
- return this.#n ? Object.fromEntries(this.#n) : {};
1404
- }
1405
- #f(e, t, n) {
1406
- let r = this.#a ? new Headers(this.#a.headers) : this.#l;
1407
- if (typeof t == "object" && t.headers) {
1408
- r ??= new Headers();
1409
- for (let [e, n] of new Headers(t.headers)) e === "set-cookie" ? r.append(e, n) : r.set(e, n);
1410
- }
1411
- if (n) {
1412
- if (!r) {
1413
- let e = 0;
1414
- for (let t in n) if (++e > 1 || typeof n[t] != "string") {
1415
- r = new Headers();
1416
- break;
1417
- }
1418
- }
1419
- if (r) for (let e in n) {
1420
- let t = n[e];
1421
- if (typeof t == "string") r.set(e, t);
1422
- else {
1423
- r.delete(e);
1424
- for (let n of t) r.append(e, n);
1425
- }
1426
- }
1427
- }
1428
- return J(e, {
1429
- status: typeof t == "number" ? t : t?.status ?? this.#r,
1430
- headers: r ?? n
1431
- });
1432
- }
1433
- newResponse = (...e) => this.#f(...e);
1434
- body = (e, t, n) => this.#f(e, t, n);
1435
- text = (e, t, n) => !this.#l && !this.#r && !t && !n && !this.finalized ? new Response(e) : this.#f(e, t, Fn(Pn, n));
1436
- json = (e, t, n) => this.#f(JSON.stringify(e), t, Fn("application/json", n));
1437
- html = (e, t, n) => {
1438
- let r = (e) => this.#f(e, t, Fn("text/html; charset=UTF-8", n));
1439
- return typeof e == "object" ? Nn(e, jn.Stringify, !1, {}).then(r) : r(e);
1440
- };
1441
- redirect = (e, t) => {
1442
- let n = String(e);
1443
- return this.header("Location", /[^\x00-\xFF]/.test(n) ? encodeURI(n) : n), this.newResponse(null, t ?? 302);
1444
- };
1445
- notFound = () => (this.#c ??= () => J(), this.#c(this));
1446
- }, Ln = [
1447
- "get",
1448
- "post",
1449
- "put",
1450
- "delete",
1451
- "options",
1452
- "patch",
1453
- "query"
1454
- ], Rn = "Can not add a route since the matcher is already built.", zn = class extends Error {}, Bn = "__COMPOSED_HANDLER", Vn = (e) => e.text("404 Not Found", 404), Hn = (e, t) => {
1455
- if ("getResponse" in e) {
1456
- let n = e.getResponse();
1457
- return t.newResponse(n.body, n);
1458
- }
1459
- return console.error(e), t.text("Internal Server Error", 500);
1460
- }, Un = class e {
1461
- get;
1462
- post;
1463
- put;
1464
- delete;
1465
- options;
1466
- patch;
1467
- query;
1468
- all;
1469
- on;
1470
- use;
1471
- router;
1472
- getPath;
1473
- _basePath = "/";
1474
- #e = "/";
1475
- routes = [];
1476
- constructor(e = {}) {
1477
- [...Ln, "all"].forEach((e) => {
1478
- this[e] = (t, ...n) => (typeof t == "string" ? this.#e = t : this.#r(e, this.#e, t), n.forEach((t) => {
1479
- this.#r(e, this.#e, t);
1480
- }), this);
1481
- }), this.on = (e, t, ...n) => {
1482
- for (let r of [t].flat()) {
1483
- this.#e = r;
1484
- for (let t of [e].flat()) n.map((e) => {
1485
- this.#r(t.toUpperCase(), this.#e, e);
1486
- });
1487
- }
1488
- return this;
1489
- }, this.use = (e, ...t) => (typeof e == "string" ? this.#e = e : (this.#e = "*", t.unshift(e)), t.forEach((e) => {
1490
- this.#r("ALL", this.#e, e);
1491
- }), this);
1492
- let { strict: t, ...n } = e;
1493
- Object.assign(this, n), this.getPath = t ?? !0 ? e.getPath ?? xn : Sn;
1494
- }
1495
- #t() {
1496
- let t = new e({
1497
- router: this.router,
1498
- getPath: this.getPath
1499
- });
1500
- return t.errorHandler = this.errorHandler, t.#n = this.#n, t.routes = this.routes, t;
1501
- }
1502
- #n = Vn;
1503
- errorHandler = Hn;
1504
- route(e, t) {
1505
- let n = this.basePath(e);
1506
- return t.routes.map((e) => {
1507
- let r;
1508
- t.errorHandler === Hn ? r = e.handler : (r = async (n, r) => (await en([], t.errorHandler)(n, () => e.handler(n, r))).res, r[Bn] = e.handler), n.#r(e.method, e.path, r, e.basePath);
1509
- }), this;
1510
- }
1511
- basePath(e) {
1512
- let t = this.#t();
1513
- return t._basePath = q(this._basePath, e), t;
1514
- }
1515
- onError = (e) => (this.errorHandler = e, this);
1516
- notFound = (e) => (this.#n = e, this);
1517
- mount(e, t, n) {
1518
- let r, i;
1519
- n && (typeof n == "function" ? i = n : (i = n.optionHandler, r = n.replaceRequest === !1 ? (e) => e : n.replaceRequest));
1520
- let a = i ? (e) => {
1521
- let t = i(e);
1522
- return Array.isArray(t) ? t : [t];
1523
- } : (e) => {
1524
- let t;
1525
- try {
1526
- t = e.executionCtx;
1527
- } catch {}
1528
- return [e.env, t];
1529
- };
1530
- return r ||= (() => {
1531
- let t = q(this._basePath, e), n = t === "/" ? 0 : t.length;
1532
- return (e) => {
1533
- let t = new URL(e.url);
1534
- return t.pathname = this.getPath(e).slice(n) || "/", new Request(t, e);
1535
- };
1536
- })(), this.#r("ALL", q(e, "*"), async (e, n) => {
1537
- let i = await t(r(e.req.raw), ...a(e));
1538
- if (i) return i;
1539
- await n();
1540
- }), this;
1541
- }
1542
- #r(e, t, n, r) {
1543
- e = e.toUpperCase(), t = q(this._basePath, t);
1544
- let i = {
1545
- basePath: r === void 0 ? this._basePath : q(this._basePath, r),
1546
- path: t,
1547
- method: e,
1548
- handler: n
1549
- };
1550
- this.router.add(e, t, [n, i]), this.routes.push(i);
1551
- }
1552
- #i(e, t) {
1553
- if (e instanceof Error) return this.errorHandler(e, t);
1554
- throw e;
1555
- }
1556
- #a(e, t, n, r) {
1557
- if (r === "HEAD") return (async () => new Response(null, await this.#a(e, t, n, "GET")))();
1558
- let i = this.getPath(e, { env: n }), a = this.router.match(r, i), o = new In(e, {
1559
- path: i,
1560
- matchResult: a,
1561
- env: n,
1562
- executionCtx: t,
1563
- notFoundHandler: this.#n
1564
- });
1565
- if (a[0].length === 1) {
1566
- let e;
1567
- try {
1568
- e = a[0][0][0][0](o, async () => {
1569
- o.res = await this.#n(o);
1570
- });
1571
- } catch (e) {
1572
- return this.#i(e, o);
1573
- }
1574
- return e instanceof Promise ? e.then((e) => e || (o.finalized ? o.res : this.#n(o))).catch((e) => this.#i(e, o)) : e ?? this.#n(o);
1575
- }
1576
- let s = en(a[0], this.errorHandler, this.#n);
1577
- return (async () => {
1578
- try {
1579
- let e = await s(o);
1580
- if (!e.finalized) throw Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
1581
- return e.res;
1582
- } catch (e) {
1583
- return this.#i(e, o);
1584
- }
1585
- })();
1586
- }
1587
- fetch = (e, ...t) => this.#a(e, t[1], t[0], e.method);
1588
- request = (e, t, n, r) => e instanceof Request ? this.fetch(t ? new Request(e, t) : e, n, r) : (e = e.toString(), this.fetch(new Request(/^https?:\/\//.test(e) ? e : `http://localhost${q("/", e)}`, t), n, r));
1589
- fire = () => {
1590
- addEventListener("fetch", (e) => {
1591
- e.respondWith(this.#a(e.request, e, void 0, e.request.method));
1592
- });
1593
- };
1594
- }, Y = () => /* @__PURE__ */ Object.create(null), Wn = [];
1595
- function Gn(e, t) {
1596
- let n = this.buildAllMatchers(), r = ((e, t) => {
1597
- let r = n[e] || n.ALL, i = r[2][t];
1598
- if (i) return i;
1599
- let a = t.match(r[0]);
1600
- if (!a) return [[], Wn];
1601
- let o = a.indexOf("", 1);
1602
- return [r[1][o], a];
1603
- });
1604
- return this.match = r, r(e, t);
1605
- }
1606
- //#endregion
1607
- //#region ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/router/reg-exp-router/node.js
1608
- var Kn = "[^/]+", qn = "(?:|/.*)", Jn = /* @__PURE__ */ Symbol(), Yn = /* @__PURE__ */ new Set(".\\+*[^]$()");
1609
- function Xn(e, t) {
1610
- return e.length === 1 ? t.length === 1 ? e < t ? -1 : 1 : -1 : t.length === 1 ? 1 : e === ".*" || e === "(?:|/.*)" ? t === "(?:|/.*)" ? -1 : 1 : t === ".*" || t === "(?:|/.*)" ? -1 : e === "[^/]+" ? 1 : t === "[^/]+" ? -1 : e.length === t.length ? e < t ? -1 : 1 : t.length - e.length;
1611
- }
1612
- var Zn = class e {
1613
- #e;
1614
- #t;
1615
- #n = Y();
1616
- insert(t, n, r, i, a) {
1617
- let o = this;
1618
- for (let n = 0, a = t.length; n < a; n++) {
1619
- let s = t[n], c = s.length === 1 ? s === "*" ? n === a - 1 ? [
1620
- "",
1621
- "",
1622
- ".*"
1623
- ] : [
1624
- "",
1625
- "",
1626
- Kn
1627
- ] : null : s === "/*" ? [
1628
- "",
1629
- "",
1630
- qn
1631
- ] : s.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/), l;
1632
- if (c) {
1633
- let t = c[1], n = c[2] || "[^/]+";
1634
- if (t && c[2] && (n === ".*" || (n = n.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"), /\((?!\?:)/.test(n)) || n.length === 1 && Yn.has(n))) throw Jn;
1635
- if (l = o.#n[n], !l) {
1636
- if (n !== ".*" && n !== "(?:|/.*)") {
1637
- for (let e in o.#n) if ((n.length > 1 || e.length > 1) && e !== ".*" && e !== "(?:|/.*)") throw Jn;
1638
- }
1639
- l = o.#n[n] = new e();
1640
- }
1641
- t !== "" && (l.#t ??= i.varIndex++, r.push([t, l.#t]));
1642
- } else if (l = o.#n[s], !l) {
1643
- for (let e in o.#n) if (e.length > 1 && e !== ".*" && e !== "(?:|/.*)") throw Jn;
1644
- l = o.#n[s] = new e();
1645
- }
1646
- o = l;
1647
- }
1648
- if (o.#e !== void 0) throw Jn;
1649
- o.#e = a ? -1 : n;
1650
- }
1651
- buildRegExpStr() {
1652
- let e = Object.keys(this.#n).sort(Xn).map((e) => {
1653
- let t = this.#n[e], n = t.buildRegExpStr();
1654
- return n === "" ? "" : (typeof t.#t == "number" ? `(${e})@${t.#t}` : Yn.has(e) ? `\\${e}` : e) + n;
1655
- }).filter(Boolean);
1656
- return typeof this.#e == "number" && this.#e !== -1 && e.unshift(`#${this.#e}`), e.length === 0 ? "" : e.length === 1 ? e[0] : "(?:" + e.join("|") + ")";
1657
- }
1658
- }, Qn = class {
1659
- #e = { varIndex: 0 };
1660
- #t = new Zn();
1661
- #n = 0;
1662
- paths = Y();
1663
- insert(e, t) {
1664
- if (t) {
1665
- this.#t.insert(e.split(""), 0, [], this.#e, !0);
1666
- return;
1667
- }
1668
- let n = [], r = [], i = e;
1669
- for (let e = 0;;) {
1670
- let t = !1;
1671
- if (i = i.replace(/\{[^}]+\}/g, (n) => {
1672
- let i = `@\\${e}`;
1673
- return r[e] = [i, n], e++, t = !0, i;
1674
- }), !t) break;
1675
- }
1676
- let a = i.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
1677
- for (let e = r.length - 1; e >= 0; e--) {
1678
- let [t] = r[e];
1679
- for (let n = a.length - 1; n >= 0; n--) if (a[n].indexOf(t) !== -1) {
1680
- a[n] = a[n].replace(t, r[e][1]);
1681
- break;
1682
- }
1683
- }
1684
- this.#t.insert(a, this.#n, n, this.#e, !1), this.paths[e] = [this.#n++, n];
1685
- }
1686
- buildRegExp() {
1687
- let e = this.#t.buildRegExpStr();
1688
- if (e === "") return [
1689
- /^$/,
1690
- [],
1691
- []
1692
- ];
1693
- let t = 0, n = [], r = [];
1694
- return e = e.replace(/#(\d+)|@(\d+)|\.\*\$/g, (e, i, a) => i === void 0 ? (a === void 0 || (r[Number(a)] = ++t), "") : (n[++t] = Number(i), "$()")), [
1695
- RegExp(`^${e}`),
1696
- n,
1697
- r
1698
- ];
1699
- }
1700
- }, $n = Y();
1701
- function er(e) {
1702
- return $n[e] ??= RegExp(`^${e.replace(/\/:[^/{}]+(?:\{\[\^\/]\+})?(?=[/{]|$)|\/?\*$|([.\\+*[^\]$()?{}|])/g, (e, t) => t ? `\\${t}` : e === "/*" ? qn : e === "*" ? ".*" : `/:${Kn}`)}$`);
1703
- }
1704
- function tr(e, t) {
1705
- for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if (er(n).test(t)) return [...e[n]];
1706
- }
1707
- var nr = class {
1708
- name = "RegExpRouter";
1709
- #e;
1710
- #t;
1711
- #n;
1712
- constructor() {
1713
- this.#e = { ALL: Y() }, this.#t = { ALL: Y() }, this.#n = { ALL: new Qn() };
1714
- }
1715
- #r(e, t) {
1716
- try {
1717
- this.#n[e].insert(t, !/\*|\/:/.test(t));
1718
- } catch (e) {
1719
- throw e === Jn ? new zn(t) : e;
1720
- }
1721
- }
1722
- add(e, t, n) {
1723
- let r = this.#e, i = this.#t;
1724
- if (!r) throw Error(Rn);
1725
- if (!r[e]) {
1726
- this.#n[e] = new Qn();
1727
- for (let t of [r, i]) {
1728
- t[e] = Y();
1729
- for (let n in t.ALL) t[e][n] = [...t.ALL[n]], this.#r(e, n);
1730
- }
1731
- }
1732
- t === "/*" && (t = "*");
1733
- let a = e === "ALL" ? Object.keys(r) : [e];
1734
- if (/\*$/.test(t)) {
1735
- let e = er(t);
1736
- for (let e of a) r[e][t] || (this.#r(e, t), r[e][t] = tr(r[e], t) || tr(r.ALL, t) || []);
1737
- for (let o of [r, i]) for (let r of a) for (let i in o[r]) e.test(i) && o[r][i].push([n, t]);
1738
- return;
1739
- }
1740
- let o = Cn(t) || [t];
1741
- for (let e of o) for (let t of a) i[t][e] || (this.#r(t, e), i[t][e] = tr(r[t], e) || tr(r.ALL, e) || []), i[t][e].push([n, e]);
1742
- }
1743
- match = Gn;
1744
- buildAllMatchers() {
1745
- let e = Y();
1746
- for (let t of Object.keys(this.#t)) e[t] = this.#i(t);
1747
- return this.#e = this.#t = this.#n = void 0, $n = Y(), e;
1748
- }
1749
- #i(e) {
1750
- let t = this.#e[e], n = this.#t[e], r = this.#n[e], i = Y(), a = [], [o, s, c] = r.buildRegExp();
1751
- for (let e of [t, n]) for (let t in e) {
1752
- let n = e[t], o = r.paths[t];
1753
- if (!o) {
1754
- i[t] = [n.map(([e]) => [e, Y()]), Wn];
1755
- continue;
1756
- }
1757
- a[o[0]] = n.map(([e, t]) => [e, r.paths[t][1].reduceRight((e, [t], n) => (e[t] = c[o[1][n][1]], e), Y())]);
1758
- }
1759
- return [
1760
- o,
1761
- s.map((e) => a[e]),
1762
- i
1763
- ];
1764
- }
1765
- }, rr = class {
1766
- name = "SmartRouter";
1767
- #e = [];
1768
- #t = [];
1769
- constructor(e) {
1770
- this.#e = e.routers;
1771
- }
1772
- add(e, t, n) {
1773
- if (!this.#t) throw Error(Rn);
1774
- this.#t.push([
1775
- e,
1776
- t,
1777
- n
1778
- ]);
1779
- }
1780
- match(e, t) {
1781
- if (!this.#t) throw Error("Fatal error");
1782
- let n = this.#e, r = this.#t, i = n.length, a = 0, o;
1783
- for (; a < i; a++) {
1784
- let i = n[a];
1785
- try {
1786
- for (let e = 0, t = r.length; e < t; e++) i.add(...r[e]);
1787
- o = i.match(e, t);
1788
- } catch (e) {
1789
- if (e instanceof zn) continue;
1790
- throw e;
1791
- }
1792
- this.match = i.match.bind(i), this.#e = [i], this.#t = void 0;
1793
- break;
1794
- }
1795
- if (a === i) throw Error("Fatal error");
1796
- return this.name = `SmartRouter + ${this.activeRouter.name}`, o;
1797
- }
1798
- get activeRouter() {
1799
- if (this.#t || this.#e.length !== 1) throw Error("No active router has been determined yet.");
1800
- return this.#e[0];
1801
- }
1802
- }, ir = Y(), ar = 0, or = class e {
1803
- #e = [];
1804
- #t = Y();
1805
- #n = [];
1806
- #r;
1807
- #i = ir;
1808
- insert(t, n, r) {
1809
- let i = this, a = mn(n), o = /* @__PURE__ */ new Set(), s = 0;
1810
- for (let t of a) {
1811
- let n = a[++s], r = vn(t, n) || (n === void 0 && t && t.indexOf("*") === t.length - 1 ? t : null), c = Array.isArray(r), l = c ? r[0] : r || t, u = i.#t[l] ||= new e();
1812
- r && !u.#r && (u.#r = r, i.#n.push(u)), i = u, c && o.add(r[1]);
1813
- }
1814
- i.#e.push({ [t]: {
1815
- handler: r,
1816
- possibleKeys: [...o],
1817
- score: ++ar
1818
- } });
1819
- }
1820
- #a(e, t, n, r, i) {
1821
- for (let a = 0, o = t.#e.length; a < o; a++) {
1822
- let o = t.#e[a], s = o[n] || o.ALL;
1823
- if (s) {
1824
- s.params = Y(), e.push(s);
1825
- for (let e = 0, t = s.possibleKeys.length; e < t; e++) {
1826
- let t = s.possibleKeys[e];
1827
- s.params[t] = i?.[t] && !e ? i[t] : r[t] ?? i?.[t];
1828
- }
1829
- }
1830
- }
1831
- }
1832
- search(e, t) {
1833
- let n = [];
1834
- this.#i = ir;
1835
- let r = [this], i = pn(t), a = [], o = i.length, s = null;
1836
- for (let c = 0; c < o; c++) {
1837
- let l = i[c], u = c === o - 1, d = [];
1838
- for (let f = 0, p = r.length; f < p; f++) {
1839
- let p = r[f], m = p.#t[l];
1840
- m && (m.#i = p.#i, u ? (m.#t["*"] && this.#a(n, m.#t["*"], e, p.#i), this.#a(n, m, e, p.#i)) : d.push(m));
1841
- for (let r of p.#n) {
1842
- let f = r.#r, m = p.#i === ir ? {} : { ...p.#i };
1843
- if (typeof f == "string") {
1844
- (f === "*" || l.startsWith(f.slice(0, -1))) && (this.#a(n, r, e, p.#i), f === "*" && (r.#i = m, d.push(r)));
1845
- continue;
1846
- }
1847
- let [, h, g] = f;
1848
- if (!(!l && g === !0)) {
1849
- if (g !== !0) {
1850
- if (!s) {
1851
- s = [];
1852
- let e = +(t[0] === "/");
1853
- for (let t = 0; t < o; t++) s[t] = e, e += i[t].length + 1;
1854
- }
1855
- let l = t.slice(s[c]), u = g.exec(l);
1856
- if (u) {
1857
- m[h] = u[0], this.#a(n, r, e, p.#i, m), u[0].length === l.length && r.#t["*"] && this.#a(n, r.#t["*"], e, p.#i, m);
1858
- for (let e in r.#t) {
1859
- r.#i = m;
1860
- let e = u[0].match(/\//g)?.length ?? 0;
1861
- (a[e] ||= []).push(r);
1862
- break;
1863
- }
1864
- continue;
1865
- }
1866
- }
1867
- (g === !0 || g.test(l)) && (m[h] = l, u ? (this.#a(n, r, e, m, p.#i), r.#t["*"] && this.#a(n, r.#t["*"], e, m, p.#i)) : (r.#i = m, d.push(r)));
1868
- }
1869
- }
1870
- }
1871
- let f = a.shift();
1872
- r = f ? d.concat(f) : d;
1873
- }
1874
- return n[1] && n.sort((e, t) => e.score - t.score), [n.map(({ handler: e, params: t }) => [e, t])];
1875
- }
1876
- }, sr = class {
1877
- name = "TrieRouter";
1878
- #e = new or();
1879
- add(e, t, n) {
1880
- for (let r of Cn(t) || [t]) this.#e.insert(e, r, n);
1881
- }
1882
- match(e, t) {
1883
- return this.#e.search(e, t);
1884
- }
1885
- }, cr = class extends Un {
1886
- constructor(e = {}) {
1887
- super(e), this.router = e.router ?? new rr({ routers: [new nr(), new sr()] });
1888
- }
1889
- };
1890
- //#endregion
1891
- //#region src/coordinator-invites.ts
1892
- function lr(e) {
1893
- let t = "";
1894
- for (let n of e) t += String.fromCharCode(n);
1895
- return btoa(t);
1896
- }
1897
- function ur(e) {
1898
- let t = atob(e), n = new Uint8Array(t.length);
1899
- for (let e = 0; e < t.length; e += 1) n[e] = t.charCodeAt(e);
1900
- return n;
1901
- }
1902
- function dr(e) {
1903
- return e.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1904
- }
1905
- function fr(e) {
1906
- let t = e.replace(/-/g, "+").replace(/_/g, "/");
1907
- return t + "=".repeat((4 - t.length % 4) % 4);
1908
- }
1909
- function pr(e) {
1910
- let t = JSON.stringify(e);
1911
- return dr(lr(new TextEncoder().encode(t)));
1912
- }
1913
- function mr(e) {
1914
- let t = new TextDecoder().decode(ur(fr(e))), n = JSON.parse(t);
1915
- if (typeof n != "object" || !n) throw Error("invalid invite payload");
1916
- return n;
1917
- }
1918
- function hr(e) {
1919
- return `codemem://join?invite=${encodeURIComponent(e)}`;
1920
- }
1921
- function gr(e) {
1922
- let t = e.trim();
1923
- if (t.startsWith("codemem://")) {
1924
- let e = new URL(t).searchParams.get("invite") ?? "";
1925
- if (!e) throw Error("invite payload missing from link");
1926
- return e;
1927
- }
1928
- return t;
1929
- }
1930
- //#endregion
1931
- //#region src/project-invite-acceptance.ts
1932
- var _r = "pending_setup", vr = "project_sync_enablement_failed", yr = "Invitation was accepted, but sync could not be enabled. Make the codemem config writable, then retry.", br = class extends Error {
1933
- code = vr;
1934
- detail = yr;
1935
- constructor(e) {
1936
- super(yr, e), this.name = "ProjectSyncEnablementError";
1937
- }
1938
- };
1939
- function xr(e) {
1940
- return typeof e == "object" && !!e && "code" in e && e.code === "project_sync_enablement_failed" && "detail" in e && e.detail === "Invitation was accepted, but sync could not be enabled. Make the codemem config writable, then retry.";
1941
- }
1942
- //#endregion
1943
- //#region src/project-share-intent.ts
1944
- var Sr = "existing_and_future";
1945
- function Cr(e) {
1946
- return t("sha256").update(JSON.stringify(e)).digest("hex");
1947
- }
1948
- function wr(e) {
1949
- return Cr({
1950
- v: 1,
1951
- historyPolicy: Sr,
1952
- projects: e.map((e) => ({
1953
- canonicalIdentity: e.canonicalIdentity,
1954
- existingMemoryCount: e.existingMemoryCount
1955
- })).toSorted((e, t) => e.canonicalIdentity.localeCompare(t.canonicalIdentity))
1956
- });
1957
- }
1958
- function Tr(e) {
1959
- return wr(e.map((e) => ({
1960
- canonicalIdentity: e.canonical_identity,
1961
- displayName: e.display_name,
1962
- identitySource: "coordinator_acceptance",
1963
- existingMemoryCount: e.existing_memory_count
1964
- })));
1965
- }
1966
- function Er(e) {
1967
- if (!Array.isArray(e) || e.length === 0 || e.length > 100) throw Error("operation_intent_invalid");
1968
- let t = e.map((e) => {
1969
- if (!e || typeof e != "object" || Array.isArray(e)) throw Error("operation_intent_invalid");
1970
- let t = e;
1971
- if (typeof t.canonical_identity != "string" || typeof t.display_name != "string") throw Error("operation_intent_invalid");
1972
- let n = t.canonical_identity, r = n.trim(), i = t.display_name, a;
1973
- try {
1974
- a = I(i, "project_name");
1975
- } catch {
1976
- throw Error("operation_intent_invalid");
1977
- }
1978
- let o = t.existing_memory_count, s = p({ gitRemote: r }).value;
1979
- if (!r || r !== n || r.length > 2048 || r.startsWith("unmapped:") || s !== r || a !== i || !Number.isSafeInteger(o) || Number(o) < 0 || /[\p{Cc}\p{Cf}]/u.test(r) || /[\p{Cc}\p{Cf}]/u.test(a)) throw Error("operation_intent_invalid");
1980
- return {
1981
- canonical_identity: r,
1982
- display_name: a,
1983
- existing_memory_count: Number(o)
1984
- };
1985
- });
1986
- if (new Set(t.map((e) => e.canonical_identity)).size !== t.length) throw Error("operation_intent_invalid");
1987
- return t.toSorted((e, t) => e.canonical_identity.localeCompare(t.canonical_identity));
1988
- }
1989
- //#endregion
1990
- //#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/clock.js
1991
- function Dr(e) {
1992
- let t = performance.now() * .001, n = Math.floor(t), r = Math.floor(t % 1 * 1e9);
1993
- return e != null && (n -= e[0], r -= e[1], r < 0 && (n--, r += 1e9)), [n, r];
1994
- }
1995
- function Or() {
1996
- let [e, t] = Dr();
1997
- return e * 1e3 + Math.floor(t / 1e6);
1998
- }
1999
- function kr(e) {
2000
- return new Promise((t) => setTimeout(t, e));
2001
- }
2002
- //#endregion
2003
- //#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/TokenBucket.js
2004
- var Ar = class {
2005
- bucketSize;
2006
- tokensPerInterval;
2007
- interval;
2008
- parentBucket;
2009
- content;
2010
- lastDrip;
2011
- constructor({ bucketSize: e, tokensPerInterval: t, interval: n, parentBucket: r }) {
2012
- if (this.bucketSize = e, this.tokensPerInterval = t, typeof n == "string") switch (n) {
2013
- case "sec":
2014
- case "second":
2015
- this.interval = 1e3;
2016
- break;
2017
- case "min":
2018
- case "minute":
2019
- this.interval = 6e4;
2020
- break;
2021
- case "hr":
2022
- case "hour":
2023
- this.interval = 36e5;
2024
- break;
2025
- case "day":
2026
- this.interval = 864e5;
2027
- break;
2028
- default: throw Error("Invalid interval " + n);
2029
- }
2030
- else this.interval = n;
2031
- this.parentBucket = r, this.content = 0, this.lastDrip = Or();
2032
- }
2033
- async removeTokens(e) {
2034
- if (this.bucketSize === 0) return Infinity;
2035
- if (e > this.bucketSize) throw Error(`Requested tokens ${e} exceeds bucket size ${this.bucketSize}`);
2036
- this.drip();
2037
- let t = async () => (await kr(Math.ceil((e - this.content) * (this.interval / this.tokensPerInterval))), this.removeTokens(e));
2038
- if (e > this.content) return t();
2039
- if (this.parentBucket != null) {
2040
- let n = await this.parentBucket.removeTokens(e);
2041
- return e > this.content ? t() : (this.content -= e, Math.min(n, this.content));
2042
- }
2043
- return this.content -= e, this.content;
2044
- }
2045
- tryRemoveTokens(e) {
2046
- return this.bucketSize ? e > this.bucketSize || (this.drip(), e > this.content) || this.parentBucket && !this.parentBucket.tryRemoveTokens(e) ? !1 : (this.content -= e, !0) : !0;
2047
- }
2048
- drip() {
2049
- if (this.tokensPerInterval === 0) {
2050
- let e = this.content;
2051
- return this.content = this.bucketSize, this.content > e;
2052
- }
2053
- let e = Or(), t = Math.max(e - this.lastDrip, 0);
2054
- this.lastDrip = e;
2055
- let n = t * (this.tokensPerInterval / this.interval), r = this.content;
2056
- return this.content = Math.min(this.content + n, this.bucketSize), Math.floor(this.content) > Math.floor(r);
2057
- }
2058
- }, jr = class {
2059
- tokenBucket;
2060
- curIntervalStart;
2061
- tokensThisInterval;
2062
- fireImmediately;
2063
- constructor({ tokensPerInterval: e, interval: t, fireImmediately: n }) {
2064
- this.tokenBucket = new Ar({
2065
- bucketSize: e,
2066
- tokensPerInterval: e,
2067
- interval: t
2068
- }), this.tokenBucket.content = e, this.curIntervalStart = Or(), this.tokensThisInterval = 0, this.fireImmediately = n ?? !1;
2069
- }
2070
- async removeTokens(e) {
2071
- if (e > this.tokenBucket.bucketSize) throw Error(`Requested tokens ${e} exceeds maximum tokens per interval ${this.tokenBucket.bucketSize}`);
2072
- let t = Or();
2073
- if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) {
2074
- if (this.fireImmediately) return -1;
2075
- {
2076
- await kr(Math.ceil(this.curIntervalStart + this.tokenBucket.interval - t));
2077
- let n = await this.tokenBucket.removeTokens(e);
2078
- return this.tokensThisInterval += e, n;
2079
- }
2080
- }
2081
- let n = await this.tokenBucket.removeTokens(e);
2082
- return this.tokensThisInterval += e, n;
2083
- }
2084
- tryRemoveTokens(e) {
2085
- if (e > this.tokenBucket.bucketSize) return !1;
2086
- let t = Or();
2087
- if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) return !1;
2088
- let n = this.tokenBucket.tryRemoveTokens(e);
2089
- return n && (this.tokensThisInterval += e), n;
2090
- }
2091
- getTokensRemaining() {
2092
- return this.tokenBucket.drip(), this.tokenBucket.content;
2093
- }
2094
- };
2095
- //#endregion
2096
- //#region src/request-rate-limit.ts
2097
- function Mr(e = {}) {
2098
- let t = Math.max(1e3, Math.trunc(e.windowMs ?? 6e4)), n = e.now ?? (() => Date.now()), r = /* @__PURE__ */ new Map(), i = 0;
2099
- function a(e) {
2100
- return Math.max(1, Math.ceil(t / Math.max(1, e) / 1e3));
2101
- }
2102
- function o(e) {
2103
- if (r.size < 64 || i % 64 != 0) return;
2104
- let n = e - t * 10;
2105
- for (let [e, t] of r) t.lastUsedAt < n && r.delete(e);
2106
- }
2107
- return { check(e, s) {
2108
- let c = Math.max(1, Math.trunc(s));
2109
- i += 1;
2110
- let l = n();
2111
- o(l);
2112
- let u = `${c}:${e}`, d = r.get(u);
2113
- return d || (d = {
2114
- limiter: new jr({
2115
- tokensPerInterval: c,
2116
- interval: t,
2117
- fireImmediately: !0
2118
- }),
2119
- lastUsedAt: l
2120
- }, r.set(u, d)), d.lastUsedAt = l, d.limiter.tryRemoveTokens(1) ? {
2121
- allowed: !0,
2122
- retryAfterS: 0
2123
- } : {
2124
- allowed: !1,
2125
- retryAfterS: a(c)
2126
- };
2127
- } };
2128
- }
2129
- //#endregion
2130
- //#region src/scope-membership-semantics.ts
2131
- var Nr = "Revocation blocks future sync for this Space. It does not remove data already copied to the revoked device; offline devices, backups, copied databases, malicious peers, or old versions may retain data.";
2132
- function Pr(e) {
2133
- let t = Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null, n = Number.isFinite(e.requiredEpoch) ? Number(e.requiredEpoch) : null;
2134
- return t == null || n == null ? {
2135
- membership_epoch: t,
2136
- required_epoch: n,
2137
- stale: !1,
2138
- reason: "unknown_epoch"
2139
- } : {
2140
- membership_epoch: t,
2141
- required_epoch: n,
2142
- stale: t < n,
2143
- reason: t < n ? "stale_epoch" : "current"
2144
- };
2145
- }
2146
- function Fr(e) {
2147
- return {
2148
- scope_id: e.scopeId,
2149
- device_id: e.deviceId,
2150
- membership_epoch: Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null,
2151
- prevents_future_sync: !0,
2152
- deletes_already_copied_data: !1,
2153
- message: Nr
2154
- };
2155
- }
2156
- //#endregion
2157
- //#region src/sync-auth-constants.ts
2158
- var Ir = 300, Lr = 65536, Rr = Ee + 1024, X = "X-Codemem-Coordinator-Admin", zr = "X-Codemem-Coordinator-Admin-Actor", Br = 120, Vr = 30;
2159
- function Z(e, t) {
2160
- let n = t.adminSecret();
2161
- if (!n) return {
2162
- ok: !1,
2163
- error: "admin_not_configured"
2164
- };
2165
- let r = (e ?? "").trim();
2166
- return r ? r === n ? {
2167
- ok: !0,
2168
- error: "ok"
2169
- } : {
2170
- ok: !1,
2171
- error: "invalid_admin_secret"
2172
- } : {
2173
- ok: !1,
2174
- error: "missing_admin_header"
2175
- };
2176
- }
2177
- function Hr(e) {
2178
- let t = new URL(e);
2179
- return t.search ? `${t.pathname}${t.search}` : t.pathname;
2180
- }
2181
- async function Ur(e, t, n, r) {
2182
- return await e.recordNonce(t, n, r);
2183
- }
2184
- async function Wr(e, t) {
2185
- await e.cleanupNonces(t);
2186
- }
2187
- async function Q(e, t, n, r) {
2188
- let { deviceId: i, signature: a, timestamp: o, nonce: s } = r;
2189
- if (!i || !a || !o || !s) return {
2190
- ok: !1,
2191
- error: "missing_headers",
2192
- enrollment: null
2193
- };
2194
- let c = await e.getEnrollment(r.groupId, i, !0);
2195
- if (!c) return {
2196
- ok: !1,
2197
- error: "unknown_device",
2198
- enrollment: null
2199
- };
2200
- if (c.enabled !== 1) return {
2201
- ok: !1,
2202
- error: "device_disabled",
2203
- enrollment: null
2204
- };
2205
- let l = await e.getGroup(r.groupId);
2206
- if (!l) return {
2207
- ok: !1,
2208
- error: "group_not_found",
2209
- enrollment: null
2210
- };
2211
- if (l.archived_at) return {
2212
- ok: !1,
2213
- error: "group_archived",
2214
- enrollment: null
2215
- };
2216
- let u;
2217
- try {
2218
- u = await n({
2219
- method: r.method,
2220
- pathWithQuery: Hr(r.url),
2221
- bodyBytes: r.body,
2222
- timestamp: o,
2223
- nonce: s,
2224
- signature: a,
2225
- publicKey: String(c.public_key),
2226
- deviceId: i
2227
- });
2228
- } catch {
2229
- return {
2230
- ok: !1,
2231
- error: "signature_verification_error",
2232
- enrollment: null
2233
- };
2234
- }
2235
- if (!u) return {
2236
- ok: !1,
2237
- error: "invalid_signature",
2238
- enrollment: null
2239
- };
2240
- let d = t.now();
2241
- return await Ur(e, i, s, d) ? (await Wr(e, (/* @__PURE__ */ new Date(new Date(d).getTime() - 6e5)).toISOString()), {
2242
- ok: !0,
2243
- error: "ok",
2244
- enrollment: c
2245
- }) : {
2246
- ok: !1,
2247
- error: "nonce_replay",
2248
- enrollment: null
2249
- };
2250
- }
2251
- function $(e) {
2252
- return e === "device_disabled" ? 403 : e === "group_archived" ? 409 : 401;
2253
- }
2254
- function Gr(e) {
2255
- if (!e?.storeFactory || !e.runtime || !e.requestVerifier) throw Error("createCoordinatorApp requires storeFactory, runtime, and requestVerifier.");
2256
- let t = e.runtime, n = e.storeFactory, r = e.requestVerifier, i = e.requestRateLimit ?? {}, a = i.limiter ?? Mr(), o = Math.max(1, Math.trunc(i.readLimit ?? Br)), s = Math.max(1, Math.trunc(i.mutationLimit ?? Vr)), c = Math.max(1, Math.trunc(i.unauthenticatedReadLimit ?? Math.min(20, o))), l = Math.max(1, Math.trunc(i.unauthenticatedMutationLimit ?? Math.min(10, s))), u = new cr(), d = new TextDecoder();
2257
- function f(e, t, n) {
2258
- let r = e.req.method === "GET" || e.req.method === "HEAD" || e.req.method === "OPTIONS", i = a.check(`${e.req.method}:${n ? "auth" : "anon"}:${t}`, n ? r ? o : s : r ? c : l);
2259
- return i.allowed ? null : (e.header("Retry-After", String(i.retryAfterS)), e.json({
2260
- error: "rate_limited",
2261
- retry_after_s: i.retryAfterS
2262
- }, 429));
2263
- }
2264
- async function p(e, t = Lr) {
2265
- let n = Number.parseInt(e.req.header("content-length") ?? "", 10);
2266
- if (Number.isFinite(n) && n > t) return null;
2267
- let r = e.req.raw.body;
2268
- if (!r) return /* @__PURE__ */ new Uint8Array();
2269
- let i = r.getReader(), a = [], o = 0;
2270
- try {
2271
- for (;;) {
2272
- let { done: e, value: n } = await i.read();
2273
- if (e) break;
2274
- if (n) {
2275
- if (o += n.byteLength, o > t) return await i.cancel(), null;
2276
- a.push(n);
2277
- }
2278
- }
2279
- } finally {
2280
- i.releaseLock();
2281
- }
2282
- let s = new Uint8Array(o), c = 0;
2283
- for (let e of a) s.set(e, c), c += e.byteLength;
2284
- return s;
2285
- }
2286
- function m(e) {
2287
- try {
2288
- let t = JSON.parse(d.decode(e));
2289
- return typeof t != "object" || !t || Array.isArray(t) ? null : t;
2290
- } catch {
2291
- return null;
2292
- }
2293
- }
2294
- function h(e, t) {
2295
- let n = e[t];
2296
- return n == null ? null : String(n).trim() || null;
2297
- }
2298
- function g(e) {
2299
- return e?.trim() || null;
2300
- }
2301
- function _(e, t) {
2302
- let n = e[t];
2303
- if (n == null || n === "") return null;
2304
- if (typeof n != "number" && typeof n != "string") return NaN;
2305
- if (typeof n == "string") {
2306
- let e = n.trim();
2307
- if (!e) return NaN;
2308
- let t = Number(e);
2309
- return Number.isFinite(t) ? Math.trunc(t) : NaN;
2310
- }
2311
- let r = n;
2312
- return Number.isFinite(r) ? Math.trunc(r) : NaN;
2313
- }
2314
- function v(e) {
2315
- return [
2316
- "1",
2317
- "true",
2318
- "yes"
2319
- ].includes(String(e ?? "").trim().toLowerCase());
2320
- }
2321
- function y(e) {
2322
- try {
2323
- return Er(JSON.parse(e ?? ""));
2324
- } catch {
2325
- throw Error("operation_intent_invalid");
2326
- }
2327
- }
2328
- function ee(e) {
2329
- let t = String(e.operation_id ?? "").trim(), n = String(e.reviewed_project_set_digest ?? "").trim();
2330
- if (!/^share_[a-f0-9]{40}$/u.test(t) || !/^[a-f0-9]{64}$/u.test(n)) throw Error("operation_intent_invalid");
2331
- let r = y(e.project_intent_json);
2332
- if (Tr(r) !== n) throw Error("operation_intent_invalid");
2333
- return {
2334
- operation_id: t,
2335
- reviewed_project_set_digest: n,
2336
- projects: r
2337
- };
2338
- }
2339
- function b(e) {
2340
- try {
2341
- return pt(JSON.parse(e ?? ""));
2342
- } catch {
2343
- throw Error("operation_intent_invalid");
2344
- }
2345
- }
2346
- async function x(e, t, n) {
2347
- if (!t) return n.json({ error: "group_id_required" }, 400);
2348
- let r = await e.getGroup(t);
2349
- return r ? r.archived_at ? n.json({ error: "group_archived" }, 409) : null : n.json({ error: "group_not_found" }, 404);
2350
- }
2351
- async function S(e, t, n, r) {
2352
- let i = await x(e, t, r);
2353
- if (i) return {
2354
- scope: null,
2355
- response: i
2356
- };
2357
- if (!n) return {
2358
- scope: null,
2359
- response: r.json({ error: "scope_id_required" }, 400)
2360
- };
2361
- let a = (await e.listScopes({
2362
- groupId: t,
2363
- includeInactive: !0
2364
- })).find((e) => e.scope_id === n) ?? null;
2365
- return a ? {
2366
- scope: a,
2367
- response: null
2368
- } : {
2369
- scope: null,
2370
- response: r.json({ error: "scope_not_found" }, 404)
2371
- };
2372
- }
2373
- async function C(e, n, i) {
2374
- let a = await Q(e, t, r, {
2375
- method: i.req.method,
2376
- url: i.req.url,
2377
- groupId: n,
2378
- body: /* @__PURE__ */ new Uint8Array(),
2379
- deviceId: i.req.header("X-Opencode-Device") ?? null,
2380
- signature: i.req.header("X-Opencode-Signature") ?? null,
2381
- timestamp: i.req.header("X-Opencode-Timestamp") ?? null,
2382
- nonce: i.req.header("X-Opencode-Nonce") ?? null
2383
- });
2384
- return !a.ok || !a.enrollment ? {
2385
- auth: a,
2386
- response: f(i, i.req.path, !1) ?? i.json({ error: a.error }, $(a.error))
2387
- } : {
2388
- auth: a,
2389
- response: f(i, String(a.enrollment.device_id), !0)
2390
- };
2391
- }
2392
- function w(e, t) {
2393
- return e.status === "active" && e.membership_epoch >= t.membership_epoch;
2394
- }
2395
- return u.post("/v1/presence", async (e) => {
2396
- let i = await p(e);
2397
- if (i == null) return e.json({ error: "body_too_large" }, 413);
2398
- let a = m(i);
2399
- if (!a) return e.json({ error: "invalid_json" }, 400);
2400
- let o = String(a.group_id ?? "").trim();
2401
- if (!o) return e.json({ error: "group_id_required" }, 400);
2402
- let s = n();
2403
- try {
2404
- let n = await Q(s, t, r, {
2405
- method: e.req.method,
2406
- url: e.req.url,
2407
- groupId: o,
2408
- body: i,
2409
- deviceId: e.req.header("X-Opencode-Device") ?? null,
2410
- signature: e.req.header("X-Opencode-Signature") ?? null,
2411
- timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
2412
- nonce: e.req.header("X-Opencode-Nonce") ?? null
2413
- });
2414
- if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) || e.json({ error: n.error }, $(n.error));
2415
- let c = f(e, String(n.enrollment.device_id), !0);
2416
- if (c) return c;
2417
- if (a.fingerprint && String(a.fingerprint) !== String(n.enrollment.fingerprint)) return e.json({ error: "fingerprint_mismatch" }, 401);
2418
- let l = a.addresses ?? [];
2419
- if (!Array.isArray(l) || !l.every((e) => typeof e == "string")) return e.json({ error: "addresses_must_be_list_of_strings" }, 400);
2420
- let u;
2421
- try {
2422
- if (u = Math.max(1, Number.parseInt(String(a.ttl_s ?? 180), 10)), Number.isNaN(u)) return e.json({ error: "ttl_s_must_be_int" }, 400);
2423
- } catch {
2424
- return e.json({ error: "ttl_s_must_be_int" }, 400);
2425
- }
2426
- let d = await s.upsertPresence({
2427
- groupId: o,
2428
- deviceId: String(n.enrollment.device_id),
2429
- addresses: l,
2430
- ttlS: u,
2431
- capabilities: typeof a.capabilities == "object" && a.capabilities !== null && !Array.isArray(a.capabilities) ? a.capabilities : void 0
2432
- });
2433
- return e.json({
2434
- ok: !0,
2435
- ...d
2436
- });
2437
- } finally {
2438
- await s.close();
2439
- }
2440
- }), u.get("/v1/peers", async (e) => {
2441
- let i = (e.req.query("group_id") ?? "").trim();
2442
- if (!i) return e.json({ error: "group_id_required" }, 400);
2443
- let a = n();
2444
- try {
2445
- let n = await Q(a, t, r, {
2446
- method: e.req.method,
2447
- url: e.req.url,
2448
- groupId: i,
2449
- body: /* @__PURE__ */ new Uint8Array(),
2450
- deviceId: e.req.header("X-Opencode-Device") ?? null,
2451
- signature: e.req.header("X-Opencode-Signature") ?? null,
2452
- timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
2453
- nonce: e.req.header("X-Opencode-Nonce") ?? null
2454
- });
2455
- if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) || e.json({ error: n.error }, $(n.error));
2456
- let o = f(e, String(n.enrollment.device_id), !0);
2457
- if (o) return o;
2458
- let s = await a.listGroupPeers(i, String(n.enrollment.device_id));
2459
- return e.json({ items: s });
2460
- } finally {
2461
- await a.close();
2462
- }
2463
- }), u.get("/v1/scopes", async (e) => {
2464
- let t = (e.req.query("group_id") ?? "").trim();
2465
- if (!t) return e.json({ error: "group_id_required" }, 400);
2466
- let r = n();
2467
- try {
2468
- let { auth: n, response: i } = await C(r, t, e);
2469
- if (i) return i;
2470
- if (!n.enrollment) return e.json({ error: "unknown_device" }, 401);
2471
- let a = await r.listScopes({
2472
- groupId: t,
2473
- includeInactive: !1
2474
- }), o = await r.listDeviceScopeMemberships(String(n.enrollment.device_id), !1), s = new Map(o.map((e) => [e.scope_id, e])), c = a.filter((e) => {
2475
- if (e.status !== "active") return !1;
2476
- let t = s.get(e.scope_id);
2477
- return !!(t && w(t, e));
2478
- });
2479
- return e.json({ items: c });
2480
- } finally {
2481
- await r.close();
2482
- }
2483
- }), u.get("/v1/scopes/:scope_id/members", async (e) => {
2484
- let t = (e.req.query("group_id") ?? "").trim(), r = String(e.req.param("scope_id") ?? "").trim();
2485
- if (!t) return e.json({ error: "group_id_required" }, 400);
2486
- if (!r) return e.json({ error: "scope_id_required" }, 400);
2487
- let i = n();
2488
- try {
2489
- let { auth: n, response: a } = await C(i, t, e);
2490
- if (a) return a;
2491
- if (!n.enrollment) return e.json({ error: "unknown_device" }, 401);
2492
- let o = (await i.listScopes({
2493
- groupId: t,
2494
- includeInactive: !1
2495
- })).find((e) => e.scope_id === r) ?? null;
2496
- if (o?.status !== "active") return e.json({ error: "scope_not_found" }, 404);
2497
- let s = await i.listScopeMemberships(r, !1);
2498
- return s.some((e) => e.device_id === String(n.enrollment?.device_id) && w(e, o)) ? e.json({ items: s.filter((e) => w(e, o)) }) : e.json({ error: "scope_not_authorized" }, 403);
2499
- } finally {
2500
- await i.close();
2501
- }
2502
- }), u.get("/v1/reciprocal-approvals", async (e) => {
2503
- let i = (e.req.query("group_id") ?? "").trim(), a = (e.req.query("direction") ?? "incoming").trim(), o = (e.req.query("status") ?? "pending").trim() || "pending";
2504
- if (!i) return e.json({ error: "group_id_required" }, 400);
2505
- if (!["incoming", "outgoing"].includes(a)) return e.json({ error: "direction_must_be_incoming_or_outgoing" }, 400);
2506
- let s = n();
2507
- try {
2508
- let n = await Q(s, t, r, {
2509
- method: e.req.method,
2510
- url: e.req.url,
2511
- groupId: i,
2512
- body: /* @__PURE__ */ new Uint8Array(),
2513
- deviceId: e.req.header("X-Opencode-Device") ?? null,
2514
- signature: e.req.header("X-Opencode-Signature") ?? null,
2515
- timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
2516
- nonce: e.req.header("X-Opencode-Nonce") ?? null
2517
- });
2518
- if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
2519
- let c = f(e, String(n.enrollment.device_id), !0);
2520
- if (c) return c;
2521
- let l = await s.listReciprocalApprovals({
2522
- groupId: i,
2523
- deviceId: String(n.enrollment.device_id),
2524
- direction: a,
2525
- status: o
2526
- });
2527
- return e.json({ items: l });
2528
- } finally {
2529
- await s.close();
2530
- }
2531
- }), u.post("/v1/reciprocal-approvals", async (e) => {
2532
- let i = await p(e);
2533
- if (i == null) return e.json({ error: "body_too_large" }, 413);
2534
- let a = m(i);
2535
- if (!a) return e.json({ error: "invalid_json" }, 400);
2536
- let o = String(a.group_id ?? "").trim(), s = String(a.requested_device_id ?? "").trim(), c = Object.hasOwn(a, "expected_incoming_request_id") ? String(a.expected_incoming_request_id ?? "").trim() : void 0;
2537
- if (!o || !s) return e.json({ error: "group_id_and_requested_device_id_required" }, 400);
2538
- let l = n();
2539
- try {
2540
- let n = await Q(l, t, r, {
2541
- method: e.req.method,
2542
- url: e.req.url,
2543
- groupId: o,
2544
- body: i,
2545
- deviceId: e.req.header("X-Opencode-Device") ?? null,
2546
- signature: e.req.header("X-Opencode-Signature") ?? null,
2547
- timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
2548
- nonce: e.req.header("X-Opencode-Nonce") ?? null
2549
- });
2550
- if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
2551
- let a = f(e, String(n.enrollment.device_id), !0);
2552
- if (a) return a;
2553
- if (s === String(n.enrollment.device_id)) return e.json({ error: "requested_device_must_differ" }, 400);
2554
- if (!await l.getEnrollment(o, s)) return e.json({ error: "requested_device_not_found" }, 404);
2555
- try {
2556
- let t = await l.createReciprocalApproval({
2557
- groupId: o,
2558
- requestingDeviceId: String(n.enrollment.device_id),
2559
- requestedDeviceId: s,
2560
- ...c === void 0 ? {} : { expectedIncomingRequestId: c }
2561
- });
2562
- return e.json({
2563
- ok: !0,
2564
- request: t
2565
- });
2566
- } catch (t) {
2567
- if (t instanceof nt) return e.json({ error: t.code }, 409);
2568
- throw t;
2569
- }
2570
- } finally {
2571
- await l.close();
2572
- }
2573
- }), u.post("/v1/invites/add-device", async (e) => {
2574
- let i = await p(e);
2575
- if (i == null) return e.json({ error: "body_too_large" }, 413);
2576
- let a = m(i);
2577
- if (!a) return e.json({ error: "invalid_json" }, 400);
2578
- let o = /* @__PURE__ */ new Set([
2579
- "group_id",
2580
- "expires_at",
2581
- "reviewed_preview_digest",
2582
- "reviewed_intent"
2583
- ]);
2584
- if (Object.keys(a).some((e) => !o.has(e))) return e.json({ error: "unexpected_add_device_invite_fields" }, 400);
2585
- let s = String(a.group_id ?? "").trim(), c = String(a.expires_at ?? "").trim(), l = String(a.reviewed_preview_digest ?? "").trim();
2586
- if (!s || !c) return e.json({ error: "group_id_and_expires_at_required" }, 400);
2587
- if (Number.isNaN(new Date(c).getTime())) return e.json({ error: "invalid_expires_at" }, 400);
2588
- if (!/^[a-f0-9]{64}$/u.test(l)) return e.json({ error: "reviewed_preview_digest_invalid" }, 400);
2589
- if (a.reviewed_intent == null) return e.json({ error: "recipient_invite_review_unavailable" }, 400);
2590
- let u = n();
2591
- try {
2592
- let n = await Q(u, t, r, {
2593
- method: e.req.method,
2594
- url: e.req.url,
2595
- groupId: s,
2596
- body: i,
2597
- deviceId: e.req.header("X-Opencode-Device") ?? null,
2598
- signature: e.req.header("X-Opencode-Signature") ?? null,
2599
- timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
2600
- nonce: e.req.header("X-Opencode-Nonce") ?? null
2601
- });
2602
- if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
2603
- let o = f(e, String(n.enrollment.device_id), !0);
2604
- if (o) return o;
2605
- let d = n.enrollment.identity_id;
2606
- if (!d || d !== d.trim() || d.length > 256 || /[\p{Cc}\p{Cf}]/u.test(d)) return e.json({ error: "identity_binding_required" }, 403);
2607
- let p;
2608
- try {
2609
- p = await G(a.reviewed_intent, {
2610
- target: {
2611
- kind: "add_device",
2612
- targetIdentityId: d
2613
- },
2614
- digest: l
2615
- });
2616
- } catch (t) {
2617
- return t instanceof z && t.code === "recipient_invite_intent_mismatch" ? e.json({ error: t.code }, 409) : e.json({ error: "recipient_invite_review_unavailable" }, 400);
2618
- }
2619
- let m = await u.createInvite({
2620
- groupId: s,
2621
- policy: "auto_admit",
2622
- expiresAt: c,
2623
- createdBy: d,
2624
- inviterDeviceId: String(n.enrollment.device_id),
2625
- inviteKind: "add_device",
2626
- targetIdentityId: d,
2627
- reviewedPreviewDigest: l,
2628
- reviewedIntent: p
2629
- }), h = {
2630
- v: 1,
2631
- kind: "add_device",
2632
- coordinator_url: new URL(e.req.url).origin,
2633
- group_id: s,
2634
- policy: m.policy,
2635
- token: String(m.token ?? ""),
2636
- expires_at: m.expires_at,
2637
- team_name: m.team_name_snapshot ?? null,
2638
- target_identity_id: m.target_identity_id ?? void 0,
2639
- inviter_device_id: m.inviter_device_id ?? void 0,
2640
- reviewed_preview_digest: m.reviewed_preview_digest ?? void 0
2641
- }, g = pr(h), { token: _, ...v } = m;
2642
- return e.json({
2643
- ok: !0,
2644
- invite: v,
2645
- payload: h,
2646
- encoded: g,
2647
- link: hr(g)
2648
- });
2649
- } finally {
2650
- await u.close();
2651
- }
2652
- }), u.post("/v1/admin/devices", async (e) => {
2653
- let r = Z(e.req.header(X), t);
2654
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2655
- let i = f(e, "admin", !0);
2656
- if (i) return i;
2657
- let a = await p(e);
2658
- if (a == null) return e.json({ error: "body_too_large" }, 413);
2659
- let o = m(a);
2660
- if (!o) return e.json({ error: "invalid_json" }, 400);
2661
- let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim(), l = String(o.fingerprint ?? "").trim(), u = String(o.public_key ?? "").trim(), d = String(o.display_name ?? "").trim() || null;
2662
- if (!s || !c || !l || !u) return e.json({ error: "group_id_device_id_fingerprint_public_key_required" }, 400);
2663
- if ($t(u) !== l) return e.json({ error: "fingerprint_mismatch" }, 400);
2664
- let h = n();
2665
- try {
2666
- await h.createGroup(s), await h.enrollDevice(s, {
2667
- deviceId: c,
2668
- fingerprint: l,
2669
- publicKey: u,
2670
- displayName: d
2671
- });
2672
- } finally {
2673
- await h.close();
2674
- }
2675
- return e.json({ ok: !0 });
2676
- }), u.get("/v1/admin/groups", async (e) => {
2677
- let r = Z(e.req.header(X), t);
2678
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2679
- let i = f(e, "admin", !0);
2680
- if (i) return i;
2681
- let a = [
2682
- "1",
2683
- "true",
2684
- "yes"
2685
- ].includes((e.req.query("include_archived") ?? "0").trim().toLowerCase()), o = n();
2686
- try {
2687
- return e.json({ items: await o.listGroups(a) });
2688
- } finally {
2689
- await o.close();
2690
- }
2691
- }), u.post("/v1/admin/groups", async (e) => {
2692
- let r = Z(e.req.header(X), t);
2693
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2694
- let i = f(e, "admin", !0);
2695
- if (i) return i;
2696
- let a = await p(e);
2697
- if (a == null) return e.json({ error: "body_too_large" }, 413);
2698
- let o = m(a);
2699
- if (!o) return e.json({ error: "invalid_json" }, 400);
2700
- let s = String(o.group_id ?? "").trim(), c = String(o.display_name ?? "").trim() || null;
2701
- if (!s) return e.json({ error: "group_id_required" }, 400);
2702
- let l = n();
2703
- try {
2704
- return await l.createGroup(s, c), e.json({
2705
- ok: !0,
2706
- group: await l.getGroup(s)
2707
- });
2708
- } finally {
2709
- await l.close();
2710
- }
2711
- }), u.post("/v1/admin/groups/rename", async (e) => {
2712
- let r = Z(e.req.header(X), t);
2713
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2714
- let i = f(e, "admin", !0);
2715
- if (i) return i;
2716
- let a = await p(e);
2717
- if (a == null) return e.json({ error: "body_too_large" }, 413);
2718
- let o = m(a);
2719
- if (!o) return e.json({ error: "invalid_json" }, 400);
2720
- let s = String(o.group_id ?? "").trim(), c = String(o.display_name ?? "").trim();
2721
- if (!s || !c) return e.json({ error: "group_id_and_display_name_required" }, 400);
2722
- let l = n();
2723
- try {
2724
- return await l.renameGroup(s, c) ? e.json({
2725
- ok: !0,
2726
- group: await l.getGroup(s)
2727
- }) : e.json({ error: "group_not_found" }, 404);
2728
- } finally {
2729
- await l.close();
2730
- }
2731
- }), u.post("/v1/admin/groups/archive", async (e) => {
2732
- let r = Z(e.req.header(X), t);
2733
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2734
- let i = f(e, "admin", !0);
2735
- if (i) return i;
2736
- let a = await p(e);
2737
- if (a == null) return e.json({ error: "body_too_large" }, 413);
2738
- let o = m(a);
2739
- if (!o) return e.json({ error: "invalid_json" }, 400);
2740
- let s = String(o.group_id ?? "").trim();
2741
- if (!s) return e.json({ error: "group_id_required" }, 400);
2742
- let c = n();
2743
- try {
2744
- return await c.archiveGroup(s, t.now()) ? e.json({
2745
- ok: !0,
2746
- group: await c.getGroup(s)
2747
- }) : e.json({ error: "group_not_found_or_already_archived" }, 404);
2748
- } finally {
2749
- await c.close();
2750
- }
2751
- }), u.post("/v1/admin/groups/unarchive", async (e) => {
2752
- let r = Z(e.req.header(X), t);
2753
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2754
- let i = f(e, "admin", !0);
2755
- if (i) return i;
2756
- let a = await p(e);
2757
- if (a == null) return e.json({ error: "body_too_large" }, 413);
2758
- let o = m(a);
2759
- if (!o) return e.json({ error: "invalid_json" }, 400);
2760
- let s = String(o.group_id ?? "").trim();
2761
- if (!s) return e.json({ error: "group_id_required" }, 400);
2762
- let c = n();
2763
- try {
2764
- return await c.unarchiveGroup(s) ? e.json({
2765
- ok: !0,
2766
- group: await c.getGroup(s)
2767
- }) : e.json({ error: "group_not_found_or_not_archived" }, 404);
2768
- } finally {
2769
- await c.close();
2770
- }
2771
- }), u.get("/v1/admin/groups/:group_id/scopes", async (e) => {
2772
- let r = Z(e.req.header(X), t);
2773
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2774
- let i = f(e, "admin", !0);
2775
- if (i) return i;
2776
- let a = String(e.req.param("group_id") ?? "").trim(), o = n();
2777
- try {
2778
- let t = await x(o, a, e);
2779
- if (t) return t;
2780
- let n = v(e.req.query("include_inactive"));
2781
- return e.json({ items: await o.listScopes({
2782
- groupId: a,
2783
- includeInactive: n
2784
- }) });
2785
- } finally {
2786
- await o.close();
2787
- }
2788
- }), u.post("/v1/admin/groups/:group_id/scopes", async (e) => {
2789
- let r = Z(e.req.header(X), t);
2790
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2791
- let i = f(e, "admin", !0);
2792
- if (i) return i;
2793
- let a = await p(e);
2794
- if (a == null) return e.json({ error: "body_too_large" }, 413);
2795
- let o = m(a);
2796
- if (!o) return e.json({ error: "invalid_json" }, 400);
2797
- let s = String(e.req.param("group_id") ?? "").trim(), c = h(o, "scope_id"), l = h(o, "label"), u = _(o, "membership_epoch");
2798
- if (!c || !l) return e.json({ error: "scope_id_and_label_required" }, 400);
2799
- if (Number.isNaN(u)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
2800
- let d = n();
2801
- try {
2802
- let t = await x(d, s, e);
2803
- if (t) return t;
2804
- let n = await d.createScope({
2805
- scopeId: c,
2806
- label: l,
2807
- kind: h(o, "kind"),
2808
- authorityType: h(o, "authority_type"),
2809
- coordinatorId: h(o, "coordinator_id"),
2810
- groupId: s,
2811
- manifestIssuerDeviceId: h(o, "manifest_issuer_device_id"),
2812
- membershipEpoch: u,
2813
- manifestHash: h(o, "manifest_hash"),
2814
- status: h(o, "status")
2815
- });
2816
- return e.json({
2817
- ok: !0,
2818
- scope: n
2819
- }, 201);
2820
- } catch (t) {
2821
- return e.json({ error: t instanceof Error ? t.message : String(t) }, 400);
2822
- } finally {
2823
- await d.close();
2824
- }
2825
- }), u.patch("/v1/admin/groups/:group_id/scopes/:scope_id", async (e) => {
2826
- let r = Z(e.req.header(X), t);
2827
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2828
- let i = f(e, "admin", !0);
2829
- if (i) return i;
2830
- let a = await p(e);
2831
- if (a == null) return e.json({ error: "body_too_large" }, 413);
2832
- let o = m(a);
2833
- if (!o) return e.json({ error: "invalid_json" }, 400);
2834
- let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = _(o, "membership_epoch");
2835
- if (!c) return e.json({ error: "scope_id_required" }, 400);
2836
- if (Number.isNaN(l)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
2837
- let u = n();
2838
- try {
2839
- let t = await S(u, s, c, e);
2840
- if (t.response) return t.response;
2841
- let n = await u.updateScope({
2842
- scopeId: c,
2843
- label: o.label === void 0 ? void 0 : h(o, "label"),
2844
- kind: o.kind === void 0 ? void 0 : h(o, "kind"),
2845
- authorityType: o.authority_type === void 0 ? void 0 : h(o, "authority_type"),
2846
- coordinatorId: o.coordinator_id === void 0 ? void 0 : h(o, "coordinator_id"),
2847
- groupId: s,
2848
- manifestIssuerDeviceId: o.manifest_issuer_device_id === void 0 ? void 0 : h(o, "manifest_issuer_device_id"),
2849
- membershipEpoch: l,
2850
- manifestHash: o.manifest_hash === void 0 ? void 0 : h(o, "manifest_hash"),
2851
- status: o.status === void 0 ? void 0 : h(o, "status")
2852
- });
2853
- return n ? e.json({
2854
- ok: !0,
2855
- scope: n
2856
- }) : e.json({ error: "scope_not_found" }, 404);
2857
- } catch (t) {
2858
- return e.json({ error: t instanceof Error ? t.message : String(t) }, 400);
2859
- } finally {
2860
- await u.close();
2861
- }
2862
- }), u.get("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
2863
- let r = Z(e.req.header(X), t);
2864
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2865
- let i = f(e, "admin", !0);
2866
- if (i) return i;
2867
- let a = String(e.req.param("group_id") ?? "").trim(), o = String(e.req.param("scope_id") ?? "").trim(), s = n();
2868
- try {
2869
- let t = await S(s, a, o, e);
2870
- return t.response ? t.response : e.json({ items: await s.listScopeMemberships(o, v(e.req.query("include_revoked"))) });
2871
- } finally {
2872
- await s.close();
2873
- }
2874
- }), u.post("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
2875
- let r = Z(e.req.header(X), t);
2876
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2877
- let i = f(e, "admin", !0);
2878
- if (i) return i;
2879
- let a = await p(e);
2880
- if (a == null) return e.json({ error: "body_too_large" }, 413);
2881
- let o = m(a);
2882
- if (!o) return e.json({ error: "invalid_json" }, 400);
2883
- let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = h(o, "effect_id"), u = h(o, "device_id"), d = _(o, "membership_epoch");
2884
- if (!l) return e.json({ error: "effect_id_required" }, 400);
2885
- if (!u) return e.json({ error: "device_id_required" }, 400);
2886
- if (Number.isNaN(d)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
2887
- let v = n();
2888
- try {
2889
- let t = await S(v, s, c, e);
2890
- if (t.response) return t.response;
2891
- let n = await v.grantScopeMembership({
2892
- effectId: l,
2893
- scopeId: c,
2894
- deviceId: u,
2895
- role: h(o, "role"),
2896
- membershipEpoch: d,
2897
- coordinatorId: h(o, "coordinator_id"),
2898
- groupId: s,
2899
- manifestIssuerDeviceId: h(o, "manifest_issuer_device_id"),
2900
- manifestHash: h(o, "manifest_hash"),
2901
- signedManifestJson: h(o, "signed_manifest_json"),
2902
- actorType: "admin",
2903
- actorId: g(e.req.header(zr))
2904
- });
2905
- return e.json({
2906
- ok: !0,
2907
- membership: n
2908
- }, 201);
2909
- } catch (t) {
2910
- let n = t instanceof Error ? t.message : String(t);
2911
- if (t instanceof P && (t.code === "scope_not_found" || t.code === "scope_group_mismatch")) return e.json({ error: "scope_not_found" }, 404);
2912
- if (t instanceof P && t.code === "device_not_enrolled") return e.json({ error: "device_not_enrolled_for_scope_group" }, 404);
2913
- let r = t instanceof P && t.code === "scope_inactive";
2914
- return e.json({ error: r ? "scope_not_active" : n }, n === "scope_membership_effect_conflict" || r ? 409 : 400);
2915
- } finally {
2916
- await v.close();
2917
- }
2918
- }), u.post("/v1/admin/groups/:group_id/scopes/:scope_id/members/:device_id/revoke", async (e) => {
2919
- let r = Z(e.req.header(X), t);
2920
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2921
- let i = f(e, "admin", !0);
2922
- if (i) return i;
2923
- let a = await p(e);
2924
- if (a == null) return e.json({ error: "body_too_large" }, 413);
2925
- let o = a.byteLength > 0 ? m(a) : {};
2926
- if (!o) return e.json({ error: "invalid_json" }, 400);
2927
- let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = String(e.req.param("device_id") ?? "").trim(), u = h(o, "effect_id"), d = _(o, "membership_epoch");
2928
- if (!u) return e.json({ error: "effect_id_required" }, 400);
2929
- if (!l) return e.json({ error: "device_id_required" }, 400);
2930
- if (Number.isNaN(d)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
2931
- let v = n();
2932
- try {
2933
- let t = await S(v, s, c, e);
2934
- if (t.response) return t.response;
2935
- if (!await v.revokeScopeMembership({
2936
- effectId: u,
2937
- scopeId: c,
2938
- deviceId: l,
2939
- groupId: s,
2940
- membershipEpoch: d,
2941
- manifestHash: h(o, "manifest_hash"),
2942
- signedManifestJson: h(o, "signed_manifest_json"),
2943
- actorType: "admin",
2944
- actorId: g(e.req.header(zr))
2945
- })) return e.json({ error: "membership_not_found" }, 404);
2946
- let n;
2947
- try {
2948
- n = (await v.listScopeMemberships(c, !0)).find((e) => e.device_id === l);
2949
- } catch {
2950
- n = void 0;
2951
- }
2952
- return e.json({
2953
- ok: !0,
2954
- scope_id: c,
2955
- device_id: l,
2956
- revocation: Fr({
2957
- scopeId: c,
2958
- deviceId: l,
2959
- membershipEpoch: n?.membership_epoch ?? d
2960
- })
2961
- });
2962
- } catch (t) {
2963
- let n = t instanceof Error ? t.message : String(t);
2964
- return t instanceof P && t.code === "scope_group_mismatch" ? e.json({ error: "scope_not_found" }, 404) : e.json({ error: n }, n === "scope_membership_effect_conflict" ? 409 : 400);
2965
- } finally {
2966
- await v.close();
2967
- }
2968
- }), u.get("/v1/admin/devices", async (e) => {
2969
- let r = Z(e.req.header(X), t);
2970
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2971
- let i = f(e, "admin", !0);
2972
- if (i) return i;
2973
- let a = (e.req.query("group_id") ?? "").trim();
2974
- if (!a) return e.json({ error: "group_id_required" }, 400);
2975
- let o = [
2976
- "1",
2977
- "true",
2978
- "yes"
2979
- ].includes((e.req.query("include_disabled") ?? "0").trim().toLowerCase()), s = n();
2980
- try {
2981
- return e.json({ items: await s.listEnrolledDevices(a, o) });
2982
- } finally {
2983
- await s.close();
2984
- }
2985
- }), u.post("/v1/admin/devices/rename", async (e) => {
2986
- let r = Z(e.req.header(X), t);
2987
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2988
- let i = f(e, "admin", !0);
2989
- if (i) return i;
2990
- let a = await p(e);
2991
- if (a == null) return e.json({ error: "body_too_large" }, 413);
2992
- let o = m(a);
2993
- if (!o) return e.json({ error: "invalid_json" }, 400);
2994
- let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim(), l = String(o.display_name ?? "").trim();
2995
- if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
2996
- if (!l) return e.json({ error: "display_name_required" }, 400);
2997
- let u;
2998
- try {
2999
- u = R(l, "display_name");
3000
- } catch (t) {
3001
- return e.json({ error: t instanceof Error ? t.message : "display_name_invalid" }, 400);
3002
- }
3003
- let d = n();
3004
- try {
3005
- if (!await d.renameDevice(s, c, u)) return e.json({ error: "device_not_found" }, 404);
3006
- let t = await d.getEnrollment(s, c);
3007
- return e.json({
3008
- ok: !0,
3009
- device: t
3010
- });
3011
- } finally {
3012
- await d.close();
3013
- }
3014
- }), u.post("/v1/admin/devices/disable", async (e) => {
3015
- let r = Z(e.req.header(X), t);
3016
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3017
- let i = f(e, "admin", !0);
3018
- if (i) return i;
3019
- let a = await p(e);
3020
- if (a == null) return e.json({ error: "body_too_large" }, 413);
3021
- let o = m(a);
3022
- if (!o) return e.json({ error: "invalid_json" }, 400);
3023
- let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
3024
- if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
3025
- let l = n();
3026
- try {
3027
- return await l.setDeviceEnabled(s, c, !1) ? e.json({ ok: !0 }) : e.json({ error: "device_not_found" }, 404);
3028
- } finally {
3029
- await l.close();
3030
- }
3031
- }), u.post("/v1/admin/devices/enable", async (e) => {
3032
- let r = Z(e.req.header(X), t);
3033
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3034
- let i = f(e, "admin", !0);
3035
- if (i) return i;
3036
- let a = await p(e);
3037
- if (a == null) return e.json({ error: "body_too_large" }, 413);
3038
- let o = m(a);
3039
- if (!o) return e.json({ error: "invalid_json" }, 400);
3040
- let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
3041
- if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
3042
- let l = n();
3043
- try {
3044
- return await l.setDeviceEnabled(s, c, !0) ? e.json({ ok: !0 }) : e.json({ error: "device_not_found" }, 404);
3045
- } finally {
3046
- await l.close();
3047
- }
3048
- }), u.post("/v1/admin/devices/remove", async (e) => {
3049
- let r = Z(e.req.header(X), t);
3050
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3051
- let i = f(e, "admin", !0);
3052
- if (i) return i;
3053
- let a = await p(e);
3054
- if (a == null) return e.json({ error: "body_too_large" }, 413);
3055
- let o = m(a);
3056
- if (!o) return e.json({ error: "invalid_json" }, 400);
3057
- let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
3058
- if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
3059
- let l = n();
3060
- try {
3061
- return await l.removeDevice(s, c) ? e.json({ ok: !0 }) : e.json({ error: "device_not_found" }, 404);
3062
- } finally {
3063
- await l.close();
3064
- }
3065
- }), u.post("/v1/admin/legacy-team-completions", async (e) => {
3066
- let r = Z(e.req.header(X), t);
3067
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3068
- let i = f(e, "admin", !0);
3069
- if (i) return i;
3070
- let a = await p(e, Rr);
3071
- if (a == null) return e.json({ error: "body_too_large" }, 413);
3072
- let o = m(a);
3073
- if (!o) return e.json({ error: "invalid_json" }, 400);
3074
- if (Object.keys(o).some((e) => e !== "group_id" && e !== "manifest")) return e.json({ error: "completion_manifest_invalid" }, 400);
3075
- let s, c;
3076
- try {
3077
- let e = Le([o.group_id])[0];
3078
- if (!e) throw Error("completion_manifest_invalid");
3079
- s = e, c = ze(o.manifest), Ve(c);
3080
- } catch {
3081
- return e.json({ error: "completion_manifest_invalid" }, 400);
3082
- }
3083
- let l = n();
3084
- try {
3085
- let t = await l.createLegacyTeamCompletion(s, c);
3086
- return e.json({
3087
- ok: !0,
3088
- ...t
3089
- }, t.status === "created" ? 201 : 200);
3090
- } catch (t) {
3091
- if (t instanceof je) return e.json({ error: t.code }, 409);
3092
- let n = t instanceof Error ? t.message : "completion_manifest_invalid";
3093
- if (n === "group_not_found") return e.json({ error: n }, 404);
3094
- if (n === "group_archived" || n === "completion_manifest_unavailable") return e.json({ error: n }, 409);
3095
- if (n === "completion_manifest_invalid") return e.json({ error: n }, 400);
3096
- throw t;
3097
- } finally {
3098
- await l.close();
3099
- }
3100
- }), u.get("/v1/admin/legacy-team-completions", async (e) => {
3101
- let r = Z(e.req.header(X), t);
3102
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3103
- let i = f(e, "admin", !0);
3104
- if (i) return i;
3105
- let a = String(e.req.query("group_id") ?? "").trim(), o;
3106
- try {
3107
- if (Le([a]).length !== 1) throw Error("completion_manifest_invalid");
3108
- o = Re(e.req.query("candidate_ref"));
3109
- } catch {
3110
- return e.json({ error: "group_id_and_candidate_ref_required" }, 400);
3111
- }
3112
- let s = n();
3113
- try {
3114
- let t = await s.getLegacyTeamCompletion(a, o);
3115
- return t ? e.json({ manifest: t }) : e.json({ error: "completion_not_found" }, 404);
3116
- } finally {
3117
- await s.close();
3118
- }
3119
- }), u.post("/v1/admin/legacy-team-completions/query", async (e) => {
3120
- let r = Z(e.req.header(X), t);
3121
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3122
- let i = f(e, "admin", !0);
3123
- if (i) return i;
3124
- let a = await p(e);
3125
- if (a == null) return e.json({ error: "body_too_large" }, 413);
3126
- let o = m(a);
3127
- if (!o || Object.keys(o).some((e) => e !== "group_ids")) return e.json({ error: "completion_query_invalid" }, 400);
3128
- let s;
3129
- try {
3130
- if (s = Le(o.group_ids), s.length === 0) throw Error("completion_query_invalid");
3131
- } catch {
3132
- return e.json({ error: "completion_query_invalid" }, 400);
3133
- }
3134
- let c = n();
3135
- try {
3136
- return e.json({ items: await c.listLegacyTeamCompletions(s) });
3137
- } catch (t) {
3138
- if (t instanceof Error && t.message === "completion_results_too_large") return e.json({ error: t.message }, 413);
3139
- throw t;
3140
- } finally {
3141
- await c.close();
3142
- }
3143
- }), u.post("/v1/admin/invites", async (e) => {
3144
- let r = Z(e.req.header(X), t);
3145
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3146
- let i = f(e, "admin", !0);
3147
- if (i) return i;
3148
- let a = await p(e);
3149
- if (a == null) return e.json({ error: "body_too_large" }, 413);
3150
- let o = m(a);
3151
- if (!o) return e.json({ error: "invalid_json" }, 400);
3152
- let s = String(o.group_id ?? "").trim(), c = String(o.policy ?? "auto_admit").trim(), l = String(o.expires_at ?? "").trim(), u = String(o.created_by ?? "").trim() || null, d = String(o.operation_id ?? "").trim() || null, h = String(o.reviewed_project_set_digest ?? "").trim() || null, g = String(o.inviter_actor_id ?? "").trim() || null, _ = String(o.inviter_display_name ?? "").trim() || null, v = String(o.inviter_device_id ?? "").trim() || null, y = String(o.pending_person_id ?? "").trim() || null, ee = String(o.invite_kind ?? o.kind ?? "").trim(), b = String(o.policy_team_id ?? "").trim() || null, x = String(o.target_identity_id ?? "").trim() || null, S = String(o.reviewed_preview_digest ?? "").trim() || null, C, w = null, T = null;
3153
- if (!s || !["auto_admit", "approval_required"].includes(c) || !l) return e.json({ error: "group_id_policy_and_expires_at_required" }, 400);
3154
- if (Object.hasOwn(o, "assigned_identity_id")) return e.json({ error: "assigned_identity_id_forbidden" }, 400);
3155
- if (Number.isNaN(new Date(l).getTime())) return e.json({ error: "invalid_expires_at" }, 400);
3156
- if (!!d != !!h) return e.json({ error: "operation_intent_reference_incomplete" }, 400);
3157
- let E = ee || (d ? "project_share" : "legacy_enrollment");
3158
- if (![
3159
- "legacy_enrollment",
3160
- "project_share",
3161
- "team_member",
3162
- "add_device"
3163
- ].includes(E)) return e.json({ error: "invite_kind_invalid" }, 400);
3164
- if (E === "project_share" ? !d : d) return e.json({ error: "invite_kind_intent_mismatch" }, 400);
3165
- if (S && !/^[a-f0-9]{64}$/u.test(S)) return e.json({ error: "reviewed_preview_digest_invalid" }, 400);
3166
- if (E === "team_member" && (!b || !S || x) || E === "add_device" && (!x || !S || b) || !["team_member", "add_device"].includes(E) && (b || x || S)) return e.json({ error: "recipient_invite_metadata_invalid" }, 400);
3167
- if ([b, x].filter((e) => !!e).some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) return e.json({ error: "recipient_invite_identifier_invalid" }, 400);
3168
- if (E === "team_member" || E === "add_device") {
3169
- if (o.reviewed_intent == null) return e.json({ error: "recipient_invite_review_unavailable" }, 400);
3170
- try {
3171
- C = await G(o.reviewed_intent, {
3172
- target: E === "team_member" ? {
3173
- kind: "team_member",
3174
- policyTeamId: String(b)
3175
- } : {
3176
- kind: "add_device",
3177
- targetIdentityId: String(x)
3178
- },
3179
- digest: String(S)
3180
- });
3181
- } catch (t) {
3182
- return t instanceof z && t.code === "recipient_invite_intent_mismatch" ? e.json({ error: t.code }, 409) : e.json({ error: "recipient_invite_review_unavailable" }, 400);
3183
- }
3184
- } else if (o.reviewed_intent != null) return e.json({ error: "recipient_invite_metadata_invalid" }, 400);
3185
- if (d && !/^share_[a-f0-9]{40}$/u.test(d) || h && !/^[a-f0-9]{64}$/u.test(h)) return e.json({ error: "operation_intent_reference_invalid" }, 400);
3186
- if (d) {
3187
- if (!g || !_ || !v || !y) return e.json({ error: "project_invite_identity_context_required" }, 400);
3188
- if ([
3189
- g,
3190
- v,
3191
- y
3192
- ].some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) return e.json({ error: "project_invite_identity_context_invalid" }, 400);
3193
- try {
3194
- if (R(_, "inviter_display_name"), w = pt(o.project_summaries), !Array.isArray(o.project_intent) || o.project_intent.length !== w.length || (T = o.project_intent.map((e, t) => {
3195
- let n;
3196
- try {
3197
- n = Er([e])[0];
3198
- } catch {
3199
- throw Error("project_intent_invalid");
3200
- }
3201
- let r = w?.[t];
3202
- if (!n || !r || n.display_name !== r.display_name || n.existing_memory_count !== r.existing_memory_count) throw Error("project_intent_invalid");
3203
- return n;
3204
- }), new Set(T.map((e) => e.canonical_identity)).size !== T.length)) throw Error("project_intent_invalid");
3205
- } catch (t) {
3206
- return e.json({ error: t instanceof Error ? t.message : "project_invite_invalid" }, 400);
3207
- }
3208
- }
3209
- let te = n();
3210
- try {
3211
- let t = await te.getGroup(s);
3212
- if (!t) return e.json({ error: "group_not_found" }, 404);
3213
- if (t.archived_at) return e.json({ error: "group_archived" }, 409);
3214
- let n = await te.createInvite({
3215
- groupId: s,
3216
- policy: c,
3217
- expiresAt: l,
3218
- createdBy: u,
3219
- operationId: d,
3220
- reviewedProjectSetDigest: h,
3221
- inviterActorId: g,
3222
- inviterDisplayName: _,
3223
- inviterDeviceId: v,
3224
- pendingPersonId: y,
3225
- projectSummaries: w,
3226
- projectIntent: T,
3227
- inviteKind: E,
3228
- policyTeamId: b,
3229
- targetIdentityId: x,
3230
- reviewedPreviewDigest: S,
3231
- reviewedIntent: C
3232
- }), r = {
3233
- v: 1,
3234
- kind: n.invite_kind === "team_member" || n.invite_kind === "add_device" ? n.invite_kind : "coordinator_team_invite",
3235
- coordinator_url: String(o.coordinator_url ?? "").trim(),
3236
- group_id: s,
3237
- policy: n.policy,
3238
- token: String(n.token ?? ""),
3239
- expires_at: n.expires_at,
3240
- team_name: n.team_name_snapshot ?? null,
3241
- ...n.operation_id ? {
3242
- operation_id: n.operation_id,
3243
- inviter_name: n.inviter_display_name ?? null,
3244
- project_summaries: w ?? []
3245
- } : {},
3246
- ...n.invite_kind === "team_member" ? {
3247
- policy_team_id: n.policy_team_id ?? void 0,
3248
- assigned_identity_id: n.assigned_identity_id ?? void 0,
3249
- reviewed_preview_digest: n.reviewed_preview_digest ?? void 0
3250
- } : {},
3251
- ...n.invite_kind === "add_device" ? {
3252
- target_identity_id: n.target_identity_id ?? void 0,
3253
- inviter_device_id: n.inviter_device_id ?? void 0,
3254
- reviewed_preview_digest: n.reviewed_preview_digest ?? void 0
3255
- } : {}
3256
- }, i = pr(r), { token: a, ...f } = n;
3257
- return e.json({
3258
- ok: !0,
3259
- invite: f,
3260
- payload: r,
3261
- encoded: i,
3262
- link: hr(i)
3263
- });
3264
- } catch (t) {
3265
- if (t instanceof Error && t.message === "invite_operation_intent_conflict") return e.json({ error: "invite_operation_intent_conflict" }, 409);
3266
- if (t instanceof Error && t.message === "invite_already_bound") return e.json({ error: "invite_already_bound" }, 409);
3267
- throw t;
3268
- } finally {
3269
- await te.close();
3270
- }
3271
- }), u.post("/v1/invites/inspect", async (e) => {
3272
- let r = await p(e);
3273
- if (r == null) return e.json({ error: "body_too_large" }, 413);
3274
- let i = m(r);
3275
- if (!i) return e.json({ error: "invalid_json" }, 400);
3276
- let a = String(i.token ?? "").trim();
3277
- if (!a) return e.json({ error: "invite_invalid" }, 404);
3278
- let o = n();
3279
- try {
3280
- let n = await o.getInviteByTokenForInspection(a);
3281
- if (!n || n.revoked_at) return e.json({ error: "invite_invalid" }, 404);
3282
- if (n.invite_kind === "team_member" || n.invite_kind === "add_device") try {
3283
- let n = await o.inspectRecipientInvite({
3284
- token: a,
3285
- now: t.now()
3286
- });
3287
- return n ? e.json(n.kind === "team_member" ? {
3288
- kind: n.kind,
3289
- policy_team_id: n.policy_team_id,
3290
- assigned_identity_id: n.assigned_identity_id,
3291
- reviewed_preview_digest: n.reviewed_preview_digest,
3292
- reviewed_intent: n.reviewed_intent,
3293
- bound: n.bound
3294
- } : {
3295
- kind: n.kind,
3296
- target_identity_id: n.target_identity_id,
3297
- reviewed_preview_digest: n.reviewed_preview_digest,
3298
- reviewed_intent: n.reviewed_intent,
3299
- bound: n.bound
3300
- }) : e.json({ error: "invite_invalid" }, 404);
3301
- } catch (t) {
3302
- let n = t instanceof Error ? t.message : "invite_invalid", r = n === "invite_expired" ? 410 : n === "invite_invalid" ? 404 : 409;
3303
- return e.json({ error: n }, r);
3304
- }
3305
- let r = !!(n.operation_id || n.reviewed_project_set_digest);
3306
- if (new Date(n.expires_at) <= new Date(t.now()) && (!r || !n.consumed_at)) return e.json({ error: "invite_expired" }, 410);
3307
- if (!n.operation_id) return e.json({
3308
- kind: "legacy_team_invite",
3309
- team_name: n.team_name_snapshot
3310
- });
3311
- if (!n.project_intent_json || !n.project_summaries_json) return e.json({ error: "invite_invalid" }, 404);
3312
- let i;
3313
- try {
3314
- i = b(n.project_summaries_json);
3315
- } catch {
3316
- return e.json({ error: "invite_invalid" }, 409);
3317
- }
3318
- return e.json({
3319
- kind: "project_share_invite",
3320
- operation_id: n.operation_id,
3321
- inviter_name: n.inviter_display_name,
3322
- team_name: n.team_name_snapshot,
3323
- projects: i,
3324
- bound: !!n.consumed_at
3325
- });
3326
- } finally {
3327
- await o.close();
3328
- }
3329
- }), u.get("/v1/admin/invites", async (e) => {
3330
- let r = Z(e.req.header(X), t);
3331
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3332
- let i = f(e, "admin", !0);
3333
- if (i) return i;
3334
- let a = (e.req.query("group_id") ?? "").trim();
3335
- if (!a) return e.json({ error: "group_id_required" }, 400);
3336
- let o = n();
3337
- try {
3338
- let t = (await o.listInvites(a)).map(({ token: e, ...t }) => t);
3339
- return e.json({ items: t });
3340
- } finally {
3341
- await o.close();
3342
- }
3343
- }), u.get("/v1/admin/project-invites/:operationId", async (e) => {
3344
- let r = Z(e.req.header(X), t);
3345
- if (!r.ok) return e.json({ error: r.error }, 401);
3346
- let i = String(e.req.param("operationId") ?? "").trim(), a = String(e.req.query("group_id") ?? "").trim();
3347
- if (!i || !a) return e.json({ error: "operation_id_and_group_id_required" }, 400);
3348
- let o = n();
3349
- try {
3350
- let n = (await o.listInvites(a)).find((e) => e.operation_id === i);
3351
- if (!n) return e.json({ error: "operation_not_found" }, 404);
3352
- let r;
3353
- try {
3354
- r = y(n.project_intent_json);
3355
- } catch {
3356
- return e.json({ error: "operation_intent_invalid" }, 409);
3357
- }
3358
- let s = null;
3359
- if (!n.consumed_at && !n.revoked_at && new Date(n.expires_at) > new Date(t.now()) && n.token && !n.token.startsWith("consumed:")) {
3360
- let t = r.map((e) => ({
3361
- display_name: String(e.display_name ?? ""),
3362
- existing_memory_count: Number(e.existing_memory_count ?? 0)
3363
- }));
3364
- s = hr(pr({
3365
- v: 1,
3366
- kind: "coordinator_team_invite",
3367
- coordinator_url: new URL(e.req.url).origin,
3368
- group_id: n.group_id,
3369
- policy: n.policy,
3370
- token: n.token,
3371
- expires_at: n.expires_at,
3372
- team_name: n.team_name_snapshot,
3373
- operation_id: i,
3374
- inviter_name: n.inviter_display_name ?? null,
3375
- project_summaries: t
3376
- }));
3377
- }
3378
- return e.json({
3379
- operation_id: n.operation_id,
3380
- group_id: n.group_id,
3381
- reviewed_project_set_digest: n.reviewed_project_set_digest,
3382
- state: n.consumed_at ? "accepted" : "waiting_for_acceptance",
3383
- pending_person_id: n.pending_person_id,
3384
- recipient_actor_id: n.recipient_actor_id,
3385
- recipient_display_name: n.recipient_display_name,
3386
- recipient_device_id: n.bound_device_id,
3387
- recipient_device_display_name: n.recipient_device_display_name,
3388
- recipient_public_key: n.bound_public_key,
3389
- recipient_fingerprint: n.bound_fingerprint,
3390
- consumed_at: n.consumed_at,
3391
- bootstrap_grant_id: n.bootstrap_grant_id,
3392
- trust_state: n.trust_state,
3393
- projects: r,
3394
- invite_link: s
3395
- });
3396
- } finally {
3397
- await o.close();
3398
- }
3399
- }), u.get("/v1/admin/bootstrap-grants/:grantId", async (e) => {
3400
- let r = Z(e.req.header(X), t);
3401
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3402
- let i = f(e, "admin", !0);
3403
- if (i) return i;
3404
- let a = String(e.req.param("grantId") ?? "").trim();
3405
- if (!a) return e.json({ error: "grant_id_required" }, 400);
3406
- let o = n();
3407
- try {
3408
- let t = await o.getBootstrapGrant(a);
3409
- if (!t) return e.json({ error: "grant_not_found" }, 404);
3410
- let n = await o.getEnrollment(t.group_id, t.worker_device_id);
3411
- if (!n) return e.json({ error: "worker_enrollment_not_found" }, 404);
3412
- let r = {
3413
- grant: t,
3414
- worker_enrollment: n
3415
- };
3416
- return e.json(r);
3417
- } finally {
3418
- await o.close();
3419
- }
3420
- }), u.get("/v1/bootstrap-grants/:grantId", async (e) => {
3421
- let i = String(e.req.param("grantId") ?? "").trim(), a = String(e.req.query("group_id") ?? "").trim();
3422
- if (!i || !a) return e.json({ error: "grant_id_and_group_id_required" }, 400);
3423
- let o = n();
3424
- try {
3425
- let n = await Q(o, t, r, {
3426
- method: e.req.method,
3427
- url: e.req.url,
3428
- groupId: a,
3429
- body: /* @__PURE__ */ new Uint8Array(),
3430
- deviceId: e.req.header("X-Opencode-Device") ?? null,
3431
- signature: e.req.header("X-Opencode-Signature") ?? null,
3432
- timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
3433
- nonce: e.req.header("X-Opencode-Nonce") ?? null
3434
- });
3435
- if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
3436
- let s = f(e, String(n.enrollment.device_id), !0);
3437
- if (s) return s;
3438
- let c = await o.getBootstrapGrant(i);
3439
- if (!c || c.group_id !== a || c.seed_device_id !== String(n.enrollment.device_id)) return e.json({ error: "grant_not_found" }, 404);
3440
- let l = await o.getEnrollment(a, c.worker_device_id);
3441
- return l ? e.json({
3442
- grant: c,
3443
- worker_enrollment: l
3444
- }) : e.json({ error: "worker_enrollment_not_found" }, 404);
3445
- } finally {
3446
- await o.close();
3447
- }
3448
- }), u.get("/v1/admin/bootstrap-grants", async (e) => {
3449
- let r = Z(e.req.header(X), t);
3450
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3451
- let i = f(e, "admin", !0);
3452
- if (i) return i;
3453
- let a = (e.req.query("group_id") ?? "").trim();
3454
- if (!a) return e.json({ error: "group_id_required" }, 400);
3455
- let o = n();
3456
- try {
3457
- return e.json({ items: await o.listBootstrapGrants(a) });
3458
- } finally {
3459
- await o.close();
3460
- }
3461
- }), u.post("/v1/admin/bootstrap-grants/revoke", async (e) => {
3462
- let r = Z(e.req.header(X), t);
3463
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3464
- let i = f(e, "admin", !0);
3465
- if (i) return i;
3466
- let a = await p(e);
3467
- if (a == null) return e.json({ error: "body_too_large" }, 413);
3468
- let o = m(a);
3469
- if (!o) return e.json({ error: "invalid_json" }, 400);
3470
- let s = String(o.grant_id ?? "").trim();
3471
- if (!s) return e.json({ error: "grant_id_required" }, 400);
3472
- let c = n();
3473
- try {
3474
- return await c.revokeBootstrapGrant(s, t.now()) ? e.json({
3475
- ok: !0,
3476
- grant_id: s
3477
- }) : e.json({ error: "grant_not_found" }, 404);
3478
- } finally {
3479
- await c.close();
3480
- }
3481
- }), u.post("/v1/admin/join-requests/approve", async (e) => Kr(e, !0, {
3482
- createStore: n,
3483
- runtime: t,
3484
- rateLimitedResponse: f
3485
- })), u.post("/v1/admin/join-requests/deny", async (e) => Kr(e, !1, {
3486
- createStore: n,
3487
- runtime: t,
3488
- rateLimitedResponse: f
3489
- })), u.get("/v1/admin/join-requests", async (e) => {
3490
- let r = Z(e.req.header(X), t);
3491
- if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3492
- let i = f(e, "admin", !0);
3493
- if (i) return i;
3494
- let a = (e.req.query("group_id") ?? "").trim();
3495
- if (!a) return e.json({ error: "group_id_required" }, 400);
3496
- let o = n();
3497
- try {
3498
- return e.json({ items: await o.listJoinRequests(a) });
3499
- } finally {
3500
- await o.close();
3501
- }
3502
- }), u.post("/v1/join", async (e) => {
3503
- let r = await p(e);
3504
- if (r == null) return e.json({ error: "body_too_large" }, 413);
3505
- let i = m(r);
3506
- if (!i) return e.json({ error: "invalid_json" }, 400);
3507
- let a = String(i.token ?? "").trim(), o = String(i.device_id ?? "").trim(), s = String(i.fingerprint ?? "").trim(), c = String(i.public_key ?? "").trim(), l = String(i.display_name ?? "").trim() || null, u = String(i.operation_id ?? "").trim(), d = String(i.recipient_actor_id ?? "").trim(), f = String(i.recipient_display_name ?? "").trim(), h = String(i.device_display_name ?? "").trim();
3508
- if (!a || !o || !s || !c) return e.json({ error: "token_device_id_fingerprint_public_key_required" }, 400);
3509
- if ($t(c) !== s) return e.json({ error: "fingerprint_mismatch" }, 400);
3510
- let g = n();
3511
- try {
3512
- let n = await g.getInviteByTokenForInspection(a);
3513
- if (!n) return e.json({ error: "invite_invalid" }, 404);
3514
- let r = !!(n.operation_id || n.reviewed_project_set_digest), p = n.invite_kind === "team_member" || n.invite_kind === "add_device";
3515
- if (n.revoked_at) return e.json({ error: r || p ? "invite_invalid" : "revoked_token" }, 400);
3516
- if (!n.consumed_at && new Date(n.expires_at) <= new Date(t.now())) return e.json({ error: r || p ? "invite_expired" : "expired_token" }, 410);
3517
- if (p) {
3518
- let r = /* @__PURE__ */ new Set([
3519
- "token",
3520
- "invite_kind",
3521
- "kind",
3522
- "identity_id",
3523
- "device_id",
3524
- "public_key",
3525
- "fingerprint",
3526
- "recipient_display_name",
3527
- "device_display_name"
3528
- ]);
3529
- if (Object.keys(i).some((e) => !r.has(e))) return e.json({ error: "unexpected_recipient_invite_fields" }, 400);
3530
- let l = String(i.invite_kind ?? i.kind ?? "").trim(), u = String(i.identity_id ?? "").trim();
3531
- if (!u || l !== n.invite_kind) return e.json({ error: "recipient_invite_binding_required" }, 400);
3532
- if (u.length > 256 || /[\p{Cc}\p{Cf}]/u.test(u)) return e.json({ error: "identity_id_invalid" }, 400);
3533
- let d = null, f = null;
3534
- try {
3535
- if (i.recipient_display_name != null) {
3536
- if (typeof i.recipient_display_name != "string") throw Error("recipient_display_name_invalid");
3537
- d = R(i.recipient_display_name, "recipient_display_name");
3538
- }
3539
- if (i.device_display_name != null) {
3540
- if (typeof i.device_display_name != "string") throw Error("device_display_name_invalid");
3541
- f = ut(i.device_display_name, "device_display_name");
3542
- }
3543
- } catch (t) {
3544
- return e.json({ error: t instanceof Error ? t.message : "recipient_invite_identity_invalid" }, 400);
3545
- }
3546
- if (n.invite_kind === "add_device" && String(n.inviter_device_id ?? "").trim() === o) return e.json({ error: "add_device_invite_self_acceptance_forbidden" }, 409);
3547
- try {
3548
- let r = await g.consumeRecipientInvite({
3549
- token: a,
3550
- inviteKind: n.invite_kind,
3551
- identityId: u,
3552
- deviceId: o,
3553
- publicKey: c,
3554
- fingerprint: s,
3555
- recipientDisplayName: d,
3556
- deviceDisplayName: f,
3557
- now: t.now()
3558
- });
3559
- return e.json({
3560
- ok: !0,
3561
- status: r.status,
3562
- kind: r.invite.invite_kind,
3563
- group_id: r.invite.group_id,
3564
- identity_id: r.invite.recipient_actor_id,
3565
- policy_team_id: r.invite.policy_team_id ?? null,
3566
- target_identity_id: r.invite.target_identity_id ?? null,
3567
- assigned_identity_id: r.invite.assigned_identity_id ?? null,
3568
- bootstrap_grant_id: r.bootstrap_grant?.grant_id ?? null,
3569
- inviter_device: r.bootstrap_grant ? await g.getEnrollment(r.invite.group_id, r.bootstrap_grant.seed_device_id) : null,
3570
- reviewed_preview_digest: r.invite.reviewed_preview_digest,
3571
- reviewed_intent: r.reviewed_intent
3572
- });
3573
- } catch (t) {
3574
- let n = t instanceof Error ? t.message : "invite_invalid", r = n === "invite_expired" ? 410 : n === "invite_invalid" ? 404 : 409;
3575
- return e.json({ error: n }, r);
3576
- }
3577
- }
3578
- if (n.operation_id || n.reviewed_project_set_digest) {
3579
- let r = /* @__PURE__ */ new Set([
3580
- "token",
3581
- "operation_id",
3582
- "device_id",
3583
- "public_key",
3584
- "fingerprint",
3585
- "display_name",
3586
- "recipient_actor_id",
3587
- "recipient_display_name",
3588
- "device_display_name"
3589
- ]);
3590
- if (Object.keys(i).some((e) => !r.has(e))) return e.json({ error: "unexpected_project_invite_fields" }, 400);
3591
- if (!u || !d || !f || !h) return e.json({ error: "project_invite_identity_required" }, 400);
3592
- if (String(n.inviter_device_id ?? "").trim() === o) return e.json({ error: "project_invite_self_acceptance_forbidden" }, 409);
3593
- if (d.length > 256 || /[\p{Cc}\p{Cf}]/u.test(d)) return e.json({ error: "recipient_actor_id_invalid" }, 400);
3594
- let l, p;
3595
- try {
3596
- l = R(f, "recipient_display_name"), p = ut(h, "device_display_name");
3597
- } catch (t) {
3598
- return e.json({ error: t instanceof Error ? t.message : "project_invite_identity_invalid" }, 400);
3599
- }
3600
- let m;
3601
- try {
3602
- m = ee(n);
3603
- } catch {
3604
- return e.json({ error: "operation_intent_invalid" }, 409);
3605
- }
3606
- try {
3607
- let n = await g.consumeProjectInvite({
3608
- token: a,
3609
- operationId: u,
3610
- deviceId: o,
3611
- publicKey: c,
3612
- fingerprint: s,
3613
- recipientActorId: d,
3614
- recipientDisplayName: l,
3615
- deviceDisplayName: p,
3616
- now: t.now()
3617
- });
3618
- return e.json({
3619
- ok: !0,
3620
- status: _r,
3621
- group_id: n.invite.group_id,
3622
- operation_id: n.invite.operation_id,
3623
- trust_state: n.invite.trust_state,
3624
- bootstrap_grant_id: n.bootstrap_grant?.grant_id ?? null,
3625
- inviter_device: n.seed_enrollment ? {
3626
- device_id: n.seed_enrollment.device_id,
3627
- public_key: n.seed_enrollment.public_key,
3628
- fingerprint: n.seed_enrollment.fingerprint,
3629
- display_name: n.seed_enrollment.display_name
3630
- } : null,
3631
- accepted_project_intent: m
3632
- });
3633
- } catch (t) {
3634
- let n = t instanceof Error ? t.message : "invite_invalid", r = n === "invite_expired" ? 410 : n === "invite_invalid" ? 404 : 409;
3635
- return e.json({ error: n }, r);
3636
- }
3637
- }
3638
- if ([
3639
- "operation_id",
3640
- "recipient_actor_id",
3641
- "recipient_display_name",
3642
- "device_display_name"
3643
- ].some((e) => Object.hasOwn(i, e))) return e.json({ error: "unexpected_project_invite_fields" }, 400);
3644
- let m = await g.getGroup(String(n.group_id));
3645
- if (!m) return e.json({ error: "group_not_found" }, 404);
3646
- if (m.archived_at) return e.json({ error: "group_archived" }, 409);
3647
- let _ = String(n.group_id);
3648
- if (await g.getEnrollment(_, o)) return e.json({
3649
- ok: !0,
3650
- status: "already_enrolled",
3651
- group_id: n.group_id,
3652
- policy: n.policy
3653
- });
3654
- let v = String(n.policy);
3655
- if (!["auto_admit", "approval_required"].includes(v)) return e.json({ error: `unknown invite policy: ${v}` }, 400);
3656
- if (v === "approval_required") {
3657
- let t = await g.createJoinRequest({
3658
- groupId: _,
3659
- deviceId: o,
3660
- publicKey: c,
3661
- fingerprint: s,
3662
- displayName: l,
3663
- token: a
3664
- });
3665
- return e.json({
3666
- ok: !0,
3667
- status: "pending",
3668
- group_id: n.group_id,
3669
- policy: n.policy,
3670
- request_id: t.request_id
3671
- });
3672
- }
3673
- return await g.enrollDevice(_, {
3674
- deviceId: o,
3675
- fingerprint: s,
3676
- publicKey: c,
3677
- displayName: l
3678
- }), e.json({
3679
- ok: !0,
3680
- status: "enrolled",
3681
- group_id: n.group_id,
3682
- policy: n.policy
3683
- });
3684
- } finally {
3685
- await g.close();
3686
- }
3687
- }), u;
3688
- }
3689
- async function Kr(e, t, n) {
3690
- let r = Z(e.req.header(X), n.runtime);
3691
- if (!r.ok) return n.rateLimitedResponse(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3692
- let i = n.rateLimitedResponse(e, "admin", !0);
3693
- if (i) return i;
3694
- let a = await (async () => {
3695
- let t = Number.parseInt(e.req.header("content-length") ?? "", 10);
3696
- if (Number.isFinite(t) && t > Lr) return null;
3697
- let n = e.req.raw.body;
3698
- if (!n) return /* @__PURE__ */ new Uint8Array();
3699
- let r = n.getReader(), i = [], a = 0;
3700
- try {
3701
- for (;;) {
3702
- let { done: e, value: t } = await r.read();
3703
- if (e) break;
3704
- if (t) {
3705
- if (a += t.byteLength, a > Lr) return await r.cancel(), null;
3706
- i.push(t);
3707
- }
3708
- }
3709
- } finally {
3710
- r.releaseLock();
3711
- }
3712
- let o = new Uint8Array(a), s = 0;
3713
- for (let e of i) o.set(e, s), s += e.byteLength;
3714
- return o;
3715
- })();
3716
- if (a == null) return e.json({ error: "body_too_large" }, 413);
3717
- let o;
3718
- try {
3719
- let e = new TextDecoder(), t = JSON.parse(e.decode(a));
3720
- o = typeof t == "object" && t && !Array.isArray(t) ? t : null;
3721
- } catch {
3722
- o = null;
3723
- }
3724
- if (!o) return e.json({ error: "invalid_json" }, 400);
3725
- let s = String(o.request_id ?? "").trim(), c = String(o.reviewed_by ?? "").trim() || null, l = String(o.bootstrap_grant_seed_device_id ?? "").trim(), u = String(o.bootstrap_grant_expires_at ?? "").trim();
3726
- if (!s) return e.json({ error: "request_id_required" }, 400);
3727
- let d = [l, u].filter(Boolean).length;
3728
- if (d > 0 && d < 2) return e.json({ error: "bootstrap_grant_seed_device_id_and_expires_at_required_together" }, 400);
3729
- let f = n.createStore();
3730
- try {
3731
- let n = await f.reviewJoinRequest({
3732
- requestId: s,
3733
- approved: t,
3734
- reviewedBy: c,
3735
- bootstrapGrant: t && l && u ? {
3736
- seedDeviceId: l,
3737
- expiresAt: u,
3738
- createdBy: c
3739
- } : null
3740
- });
3741
- return n ? n._no_transition ? e.json({
3742
- error: "request_not_pending",
3743
- status: n.status
3744
- }, 409) : e.json({
3745
- ok: !0,
3746
- request: n
3747
- }) : e.json({ error: "request_not_found" }, 404);
3748
- } finally {
3749
- await f.close();
3750
- }
3751
- }
3752
- //#endregion
3753
- export { Ke as $, Wt as A, ae as At, dt as B, Qt as C, _e as Ct, Yt as D, Se as Dt, Gt as E, ve as Et, jt as F, p as Ft, tt as G, I as H, At as I, E as It, et as J, $e as K, G as L, te as Lt, z as M, ne as Mt, kt as N, s as Nt, Ht as O, O as Ot, Ot as P, o as Pt, Xe as Q, ft as R, T as Rt, Pt as S, he as St, Ft as T, be as Tt, pt as U, R as V, nt as W, Ye as X, P as Y, qe as Z, gr as _, me as _t, Pr as a, we as at, K as b, le as bt, Er as c, je as ct, vr as d, Le as dt, Je as et, yr as f, ze as ft, pr as g, ge as gt, mr as h, Ve as ht, Fr as i, Ee as it, mt as j, ie as jt, Jt as k, re as kt, wr as l, Be as lt, xr as m, Ue as mt, Ir as n, De as nt, Sr as o, Te as ot, br as p, He as pt, Ze as q, Nr as r, ke as rt, Tr as s, Ce as st, Gr as t, Ae as tt, _r as u, Re as ut, hr as v, oe as vt, It as w, ye as wt, Ut as x, ue as xt, $t as y, xe as yt, L as z, a as zt };
3754
-
3755
- //# sourceMappingURL=coordinator-api-CdUQtf5l.js.map