@codemem/core 0.49.1 → 0.50.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 (391) hide show
  1. package/dist/api-types.d.ts +7 -0
  2. package/dist/api-types.d.ts.map +1 -1
  3. package/dist/better-sqlite-coordinator-runtime.d.ts.map +1 -1
  4. package/dist/better-sqlite-coordinator-store.d.ts +56 -3
  5. package/dist/better-sqlite-coordinator-store.d.ts.map +1 -1
  6. package/dist/boundary-readiness-inventory.d.ts +27 -0
  7. package/dist/boundary-readiness-inventory.d.ts.map +1 -0
  8. package/dist/coordinator-account-link-receiver.d.ts +15 -0
  9. package/dist/coordinator-account-link-receiver.d.ts.map +1 -1
  10. package/dist/coordinator-account-link-status-client.d.ts +1 -1
  11. package/dist/coordinator-account-link-status-client.d.ts.map +1 -1
  12. package/dist/coordinator-actions.d.ts +14 -0
  13. package/dist/coordinator-actions.d.ts.map +1 -1
  14. package/dist/coordinator-api.d.ts +7 -0
  15. package/dist/coordinator-api.d.ts.map +1 -1
  16. package/dist/coordinator-auth-historical-store-test-fixture.d.ts.map +1 -1
  17. package/dist/coordinator-auth-link-revocation-test-harness.d.ts.map +1 -1
  18. package/dist/coordinator-auth-schema-stage.d.ts +14 -2
  19. package/dist/coordinator-auth-schema-stage.d.ts.map +1 -1
  20. package/dist/coordinator-block-tombstone-test-harness.d.ts +3 -0
  21. package/dist/coordinator-block-tombstone-test-harness.d.ts.map +1 -0
  22. package/dist/coordinator-bootstrap-authorization-api-test-harness.d.ts.map +1 -1
  23. package/dist/coordinator-bootstrap-authorization-test-harness.d.ts.map +1 -1
  24. package/dist/coordinator-bootstrap-revocation-test-harness.d.ts.map +1 -1
  25. package/dist/coordinator-boundary-readiness-client.d.ts +35 -0
  26. package/dist/coordinator-boundary-readiness-client.d.ts.map +1 -0
  27. package/dist/coordinator-boundary-readiness-route.d.ts +52 -0
  28. package/dist/coordinator-boundary-readiness-route.d.ts.map +1 -0
  29. package/dist/coordinator-boundary-readiness-test-harness.d.ts +15 -0
  30. package/dist/coordinator-boundary-readiness-test-harness.d.ts.map +1 -0
  31. package/dist/coordinator-boundary-readiness.d.ts +161 -0
  32. package/dist/coordinator-boundary-readiness.d.ts.map +1 -0
  33. package/dist/coordinator-browser-auth-app.d.ts +1 -1
  34. package/dist/coordinator-browser-auth-app.d.ts.map +1 -1
  35. package/dist/coordinator-browser-auth-callback.d.ts +2 -1
  36. package/dist/coordinator-browser-auth-callback.d.ts.map +1 -1
  37. package/dist/coordinator-controller-revocation-test-harness.d.ts.map +1 -1
  38. package/dist/coordinator-d1-schema-inventory.d.ts +2 -0
  39. package/dist/coordinator-d1-schema-inventory.d.ts.map +1 -1
  40. package/dist/coordinator-d1-scope-authorization-test-harness.d.ts.map +1 -1
  41. package/dist/coordinator-device-auth-link.d.ts +1 -0
  42. package/dist/coordinator-device-auth-link.d.ts.map +1 -1
  43. package/dist/coordinator-device-rejoin-browser-evidence.d.ts +28 -0
  44. package/dist/coordinator-device-rejoin-browser-evidence.d.ts.map +1 -0
  45. package/dist/coordinator-device-rejoin-browser-transaction-test-harness.d.ts +8 -0
  46. package/dist/coordinator-device-rejoin-browser-transaction-test-harness.d.ts.map +1 -0
  47. package/dist/coordinator-device-rejoin-browser-transaction.d.ts +43 -0
  48. package/dist/coordinator-device-rejoin-browser-transaction.d.ts.map +1 -0
  49. package/dist/coordinator-device-rejoin-browser-view.d.ts +30 -0
  50. package/dist/coordinator-device-rejoin-browser-view.d.ts.map +1 -0
  51. package/dist/coordinator-device-rejoin-browser.d.ts +26 -0
  52. package/dist/coordinator-device-rejoin-browser.d.ts.map +1 -0
  53. package/dist/coordinator-device-rejoin-client-requests.d.ts +70 -0
  54. package/dist/coordinator-device-rejoin-client-requests.d.ts.map +1 -0
  55. package/dist/coordinator-device-rejoin-client.d.ts +15 -0
  56. package/dist/coordinator-device-rejoin-client.d.ts.map +1 -0
  57. package/dist/coordinator-device-rejoin-confirmation-test-harness.d.ts +22 -0
  58. package/dist/coordinator-device-rejoin-confirmation-test-harness.d.ts.map +1 -0
  59. package/dist/coordinator-device-rejoin-confirmation.d.ts +18 -0
  60. package/dist/coordinator-device-rejoin-confirmation.d.ts.map +1 -0
  61. package/dist/coordinator-device-rejoin-destinations-test-harness.d.ts +7 -0
  62. package/dist/coordinator-device-rejoin-destinations-test-harness.d.ts.map +1 -0
  63. package/dist/coordinator-device-rejoin-destinations.d.ts +25 -0
  64. package/dist/coordinator-device-rejoin-destinations.d.ts.map +1 -0
  65. package/dist/coordinator-device-rejoin-display.d.ts +14 -0
  66. package/dist/coordinator-device-rejoin-display.d.ts.map +1 -0
  67. package/dist/coordinator-device-rejoin-event-client.d.ts +30 -0
  68. package/dist/coordinator-device-rejoin-event-client.d.ts.map +1 -0
  69. package/dist/coordinator-device-rejoin-events.d.ts +7 -0
  70. package/dist/coordinator-device-rejoin-events.d.ts.map +1 -0
  71. package/dist/coordinator-device-rejoin-finalize-test-harness.d.ts +14 -0
  72. package/dist/coordinator-device-rejoin-finalize-test-harness.d.ts.map +1 -0
  73. package/dist/coordinator-device-rejoin-finalize.d.ts +36 -0
  74. package/dist/coordinator-device-rejoin-finalize.d.ts.map +1 -0
  75. package/dist/coordinator-device-rejoin-http.d.ts +11 -0
  76. package/dist/coordinator-device-rejoin-http.d.ts.map +1 -0
  77. package/dist/coordinator-device-rejoin-link-evidence-test-harness.d.ts +17 -0
  78. package/dist/coordinator-device-rejoin-link-evidence-test-harness.d.ts.map +1 -0
  79. package/dist/coordinator-device-rejoin-link-evidence.d.ts +29 -0
  80. package/dist/coordinator-device-rejoin-link-evidence.d.ts.map +1 -0
  81. package/dist/coordinator-device-rejoin-link-lineage.d.ts +7 -0
  82. package/dist/coordinator-device-rejoin-link-lineage.d.ts.map +1 -0
  83. package/dist/coordinator-device-rejoin-oidc-pins.d.ts +14 -0
  84. package/dist/coordinator-device-rejoin-oidc-pins.d.ts.map +1 -0
  85. package/dist/coordinator-device-rejoin-proof.d.ts +41 -0
  86. package/dist/coordinator-device-rejoin-proof.d.ts.map +1 -0
  87. package/dist/coordinator-device-rejoin-schema-test-harness.d.ts +8 -0
  88. package/dist/coordinator-device-rejoin-schema-test-harness.d.ts.map +1 -0
  89. package/dist/coordinator-device-rejoin-schema.d.ts +9 -0
  90. package/dist/coordinator-device-rejoin-schema.d.ts.map +1 -0
  91. package/dist/coordinator-device-rejoin-start-evidence-test-harness.d.ts +40 -0
  92. package/dist/coordinator-device-rejoin-start-evidence-test-harness.d.ts.map +1 -0
  93. package/dist/coordinator-device-rejoin-start-evidence.d.ts +25 -0
  94. package/dist/coordinator-device-rejoin-start-evidence.d.ts.map +1 -0
  95. package/dist/coordinator-device-rejoin-start-http.d.ts +12 -0
  96. package/dist/coordinator-device-rejoin-start-http.d.ts.map +1 -0
  97. package/dist/coordinator-device-rejoin-start-input.d.ts +23 -0
  98. package/dist/coordinator-device-rejoin-start-input.d.ts.map +1 -0
  99. package/dist/coordinator-device-rejoin-start-write.d.ts +38 -0
  100. package/dist/coordinator-device-rejoin-start-write.d.ts.map +1 -0
  101. package/dist/coordinator-device-rejoin-status-http.d.ts +10 -0
  102. package/dist/coordinator-device-rejoin-status-http.d.ts.map +1 -0
  103. package/dist/coordinator-device-rejoin-status-live-test-harness.d.ts +33 -0
  104. package/dist/coordinator-device-rejoin-status-live-test-harness.d.ts.map +1 -0
  105. package/dist/coordinator-device-rejoin-status-projection.d.ts +28 -0
  106. package/dist/coordinator-device-rejoin-status-projection.d.ts.map +1 -0
  107. package/dist/coordinator-device-rejoin-status-test-harness.d.ts +8 -0
  108. package/dist/coordinator-device-rejoin-status-test-harness.d.ts.map +1 -0
  109. package/dist/coordinator-device-rejoin-status.d.ts +39 -0
  110. package/dist/coordinator-device-rejoin-status.d.ts.map +1 -0
  111. package/dist/coordinator-device-removal-commands.d.ts +13 -0
  112. package/dist/coordinator-device-removal-commands.d.ts.map +1 -0
  113. package/dist/coordinator-device-removal-commit-test-harness.d.ts +3 -0
  114. package/dist/coordinator-device-removal-commit-test-harness.d.ts.map +1 -0
  115. package/dist/coordinator-device-removal-commit.d.ts +44 -0
  116. package/dist/coordinator-device-removal-commit.d.ts.map +1 -0
  117. package/dist/coordinator-device-removal-dependents-test-harness.d.ts +9 -0
  118. package/dist/coordinator-device-removal-dependents-test-harness.d.ts.map +1 -0
  119. package/dist/coordinator-device-removal-dependents.d.ts +34 -0
  120. package/dist/coordinator-device-removal-dependents.d.ts.map +1 -0
  121. package/dist/coordinator-device-removal-list-test-harness.d.ts +4 -0
  122. package/dist/coordinator-device-removal-list-test-harness.d.ts.map +1 -0
  123. package/dist/coordinator-device-removal-list.d.ts +42 -0
  124. package/dist/coordinator-device-removal-list.d.ts.map +1 -0
  125. package/dist/coordinator-device-removal-preview-test-harness.d.ts +9 -0
  126. package/dist/coordinator-device-removal-preview-test-harness.d.ts.map +1 -0
  127. package/dist/coordinator-device-removal-routes.d.ts +13 -0
  128. package/dist/coordinator-device-removal-routes.d.ts.map +1 -0
  129. package/dist/coordinator-device-removal-target.d.ts +98 -0
  130. package/dist/coordinator-device-removal-target.d.ts.map +1 -0
  131. package/dist/coordinator-device-removal-test-harness.d.ts +70 -0
  132. package/dist/coordinator-device-removal-test-harness.d.ts.map +1 -0
  133. package/dist/coordinator-device-removal-writer-test-harness.d.ts +8 -0
  134. package/dist/coordinator-device-removal-writer-test-harness.d.ts.map +1 -0
  135. package/dist/coordinator-device-removal.d.ts +233 -0
  136. package/dist/coordinator-device-removal.d.ts.map +1 -0
  137. package/dist/coordinator-device-revocation-client.d.ts +2 -0
  138. package/dist/coordinator-device-revocation-client.d.ts.map +1 -1
  139. package/dist/coordinator-device-revocation-handler-test-harness.d.ts.map +1 -1
  140. package/dist/coordinator-device-revocation-handler.d.ts +1 -1
  141. package/dist/coordinator-device-revocation-handler.d.ts.map +1 -1
  142. package/dist/coordinator-device-revocation-route.d.ts.map +1 -1
  143. package/dist/coordinator-device-revocation-test-harness.d.ts.map +1 -1
  144. package/dist/coordinator-device-revocation.d.ts +20 -2
  145. package/dist/coordinator-device-revocation.d.ts.map +1 -1
  146. package/dist/coordinator-enrollment-reconciler.d.ts.map +1 -1
  147. package/dist/coordinator-enrollment-test-fixtures.d.ts +126 -0
  148. package/dist/coordinator-enrollment-test-fixtures.d.ts.map +1 -0
  149. package/dist/coordinator-history-sql-equivalence-test-fixtures.d.ts +1 -1
  150. package/dist/coordinator-history-sql-equivalence-test-fixtures.d.ts.map +1 -1
  151. package/dist/coordinator-identity-grant-revocation-test-harness.d.ts.map +1 -1
  152. package/dist/coordinator-identity-group-grant-test-harness.d.ts.map +1 -1
  153. package/dist/coordinator-invitation-lift-test-harness.d.ts +6 -0
  154. package/dist/coordinator-invitation-lift-test-harness.d.ts.map +1 -0
  155. package/dist/coordinator-invitation-removal.d.ts +71 -0
  156. package/dist/coordinator-invitation-removal.d.ts.map +1 -0
  157. package/dist/coordinator-join-review-guards.d.ts +2 -0
  158. package/dist/coordinator-join-review-guards.d.ts.map +1 -1
  159. package/dist/coordinator-join-revocation-test-harness.d.ts.map +1 -1
  160. package/dist/coordinator-key-id-fill-api-test-harness.d.ts +12 -0
  161. package/dist/coordinator-key-id-fill-api-test-harness.d.ts.map +1 -0
  162. package/dist/coordinator-key-id-fill-api.d.ts +19 -0
  163. package/dist/coordinator-key-id-fill-api.d.ts.map +1 -0
  164. package/dist/coordinator-legacy-device-ownership.d.ts +66 -5
  165. package/dist/coordinator-legacy-device-ownership.d.ts.map +1 -1
  166. package/dist/coordinator-legacy-owner-compatibility.d.ts +3 -0
  167. package/dist/coordinator-legacy-owner-compatibility.d.ts.map +1 -1
  168. package/dist/coordinator-membership-enrollment-test-harness.d.ts +4 -0
  169. package/dist/coordinator-membership-enrollment-test-harness.d.ts.map +1 -0
  170. package/dist/coordinator-membership-enrollment.d.ts +15 -0
  171. package/dist/coordinator-membership-enrollment.d.ts.map +1 -0
  172. package/dist/coordinator-owner-enrollment-commit.d.ts +1 -1
  173. package/dist/coordinator-owner-enrollment-commit.d.ts.map +1 -1
  174. package/dist/coordinator-owner-enrollment-qualification-test-harness.d.ts.map +1 -1
  175. package/dist/coordinator-owner-enrollment-qualification.d.ts +1 -0
  176. package/dist/coordinator-owner-enrollment-qualification.d.ts.map +1 -1
  177. package/dist/coordinator-owner-resolution-review-test-fixtures.d.ts.map +1 -1
  178. package/dist/coordinator-peer-discovery-revocation-test-harness.d.ts.map +1 -1
  179. package/dist/coordinator-peer-removal-api-test-harness.d.ts +29 -0
  180. package/dist/coordinator-peer-removal-api-test-harness.d.ts.map +1 -0
  181. package/dist/coordinator-peer-removal-query-test-harness.d.ts +4 -0
  182. package/dist/coordinator-peer-removal-query-test-harness.d.ts.map +1 -0
  183. package/dist/coordinator-peer-removal-query.d.ts +32 -0
  184. package/dist/coordinator-peer-removal-query.d.ts.map +1 -0
  185. package/dist/coordinator-peer-revocation-route.d.ts +45 -0
  186. package/dist/coordinator-peer-revocation-route.d.ts.map +1 -0
  187. package/dist/coordinator-peer-revocation.d.ts +61 -0
  188. package/dist/coordinator-peer-revocation.d.ts.map +1 -0
  189. package/dist/coordinator-presence-capabilities.d.ts +10 -0
  190. package/dist/coordinator-presence-capabilities.d.ts.map +1 -0
  191. package/dist/coordinator-project-revocation-test-harness.d.ts +1 -1
  192. package/dist/coordinator-project-revocation-test-harness.d.ts.map +1 -1
  193. package/dist/coordinator-recipient-revocation-test-harness.d.ts.map +1 -1
  194. package/dist/coordinator-refresh-lifecycle.d.ts +11 -0
  195. package/dist/coordinator-refresh-lifecycle.d.ts.map +1 -0
  196. package/dist/coordinator-rejoin-discovery.d.ts +16 -0
  197. package/dist/coordinator-rejoin-discovery.d.ts.map +1 -0
  198. package/dist/coordinator-rejoin-timestamp.d.ts +3 -0
  199. package/dist/coordinator-rejoin-timestamp.d.ts.map +1 -0
  200. package/dist/coordinator-removal-notice.d.ts +21 -0
  201. package/dist/coordinator-removal-notice.d.ts.map +1 -0
  202. package/dist/coordinator-removal-progress-listing-test-harness.d.ts +3 -0
  203. package/dist/coordinator-removal-progress-listing-test-harness.d.ts.map +1 -0
  204. package/dist/coordinator-runtime-ChgCIqfx.js +1716 -0
  205. package/dist/coordinator-runtime-ChgCIqfx.js.map +1 -0
  206. package/dist/coordinator-runtime.d.ts +20 -1
  207. package/dist/coordinator-runtime.d.ts.map +1 -1
  208. package/dist/coordinator-scope-authorization-api-test-harness.d.ts.map +1 -1
  209. package/dist/coordinator-store-contract.d.ts +21 -3
  210. package/dist/coordinator-store-contract.d.ts.map +1 -1
  211. package/dist/coordinator-store-test-harness.d.ts.map +1 -1
  212. package/dist/coordinator-sync-config.d.ts +14 -0
  213. package/dist/coordinator-sync-config.d.ts.map +1 -1
  214. package/dist/d1-coordinator-runtime.d.ts +3 -1
  215. package/dist/d1-coordinator-runtime.d.ts.map +1 -1
  216. package/dist/d1-coordinator-store.d.ts +63 -3
  217. package/dist/d1-coordinator-store.d.ts.map +1 -1
  218. package/dist/database-runtime-primitives.d.ts +1 -1
  219. package/dist/db.d.ts.map +1 -1
  220. package/dist/device-identity-binding.d.ts +24 -0
  221. package/dist/device-identity-binding.d.ts.map +1 -1
  222. package/dist/device-identity-inventory.d.ts +19 -1
  223. package/dist/device-identity-inventory.d.ts.map +1 -1
  224. package/dist/device-retirement.d.ts +43 -0
  225. package/dist/device-retirement.d.ts.map +1 -0
  226. package/dist/identity-device-assignment.d.ts +8 -0
  227. package/dist/identity-device-assignment.d.ts.map +1 -1
  228. package/dist/index.d.ts +34 -8
  229. package/dist/index.d.ts.map +1 -1
  230. package/dist/index.js +11908 -10664
  231. package/dist/index.js.map +1 -1
  232. package/dist/ingest-events.d.ts.map +1 -1
  233. package/dist/internal/cloudflare-coordinator.js +2317 -1542
  234. package/dist/internal/cloudflare-coordinator.js.map +1 -1
  235. package/dist/internal/relay-runtime.js +32 -32
  236. package/dist/legacy-pairing-assignment-conversion.d.ts +46 -0
  237. package/dist/legacy-pairing-assignment-conversion.d.ts.map +1 -0
  238. package/dist/legacy-pairing-assignment-state.d.ts +11 -0
  239. package/dist/legacy-pairing-assignment-state.d.ts.map +1 -0
  240. package/dist/legacy-team-setup-completion-manifest.d.ts +41 -0
  241. package/dist/legacy-team-setup-completion-manifest.d.ts.map +1 -1
  242. package/dist/legacy-team-setup-errors.d.ts +3 -2
  243. package/dist/legacy-team-setup-errors.d.ts.map +1 -1
  244. package/dist/local-origin-claim.d.ts +48 -0
  245. package/dist/local-origin-claim.d.ts.map +1 -0
  246. package/dist/maintenance/ai-structured.d.ts +2 -0
  247. package/dist/maintenance/ai-structured.d.ts.map +1 -1
  248. package/dist/observer-config.d.ts.map +1 -1
  249. package/dist/owned-recipient-d1-test-harness.d.ts.map +1 -1
  250. package/dist/owner-enrollment-link-authority.d.ts +1 -0
  251. package/dist/owner-enrollment-link-authority.d.ts.map +1 -1
  252. package/dist/{owner-enrollment-start-BsDwgxAh.js → owner-enrollment-start-CD7R8wy3.js} +5548 -3637
  253. package/dist/owner-enrollment-start-CD7R8wy3.js.map +1 -0
  254. package/dist/pairing-removal.d.ts +58 -0
  255. package/dist/pairing-removal.d.ts.map +1 -0
  256. package/dist/peer-project-filter-change.d.ts +33 -0
  257. package/dist/peer-project-filter-change.d.ts.map +1 -0
  258. package/dist/peer-project-filter-management.d.ts +7 -0
  259. package/dist/peer-project-filter-management.d.ts.map +1 -0
  260. package/dist/peer-project-filter-retention.d.ts +17 -0
  261. package/dist/peer-project-filter-retention.d.ts.map +1 -0
  262. package/dist/peer-removal-check-state.d.ts +24 -0
  263. package/dist/peer-removal-check-state.d.ts.map +1 -0
  264. package/dist/peer-removal.d.ts +34 -0
  265. package/dist/peer-removal.d.ts.map +1 -0
  266. package/dist/peer-traversal-coordinator-attempt-write-test-fixtures.d.ts.map +1 -1
  267. package/dist/peer-traversal-coordinator-decision-test-fixtures.d.ts.map +1 -1
  268. package/dist/pi-hooks.d.ts +1 -5
  269. package/dist/pi-hooks.d.ts.map +1 -1
  270. package/dist/policy-team-device-eligibility.d.ts +10 -0
  271. package/dist/policy-team-device-eligibility.d.ts.map +1 -1
  272. package/dist/project-boundary-migration-hold.d.ts +50 -0
  273. package/dist/project-boundary-migration-hold.d.ts.map +1 -0
  274. package/dist/project-boundary-migration-records.d.ts +46 -0
  275. package/dist/project-boundary-migration-records.d.ts.map +1 -0
  276. package/dist/project-filters-narrowing.d.ts +11 -0
  277. package/dist/project-filters-narrowing.d.ts.map +1 -0
  278. package/dist/project-scope-resume.d.ts +26 -0
  279. package/dist/project-scope-resume.d.ts.map +1 -0
  280. package/dist/project-scope-settings.d.ts +21 -1
  281. package/dist/project-scope-settings.d.ts.map +1 -1
  282. package/dist/project-scope-withdrawal.d.ts +48 -0
  283. package/dist/project-scope-withdrawal.d.ts.map +1 -0
  284. package/dist/project-withdrawal-state.d.ts +36 -0
  285. package/dist/project-withdrawal-state.d.ts.map +1 -0
  286. package/dist/raw-event-flush.d.ts.map +1 -1
  287. package/dist/{recipient-policy-contract-Ca40IBUh.js → recipient-policy-contract-BHxfaQZ2.js} +12 -5
  288. package/dist/recipient-policy-contract-BHxfaQZ2.js.map +1 -0
  289. package/dist/recipient-policy-contract.d.ts +7 -0
  290. package/dist/recipient-policy-contract.d.ts.map +1 -1
  291. package/dist/recipient-policy-contract.js +2 -2
  292. package/dist/recipient-policy-edges.d.ts.map +1 -1
  293. package/dist/recipient-policy-intent.d.ts +1 -0
  294. package/dist/recipient-policy-intent.d.ts.map +1 -1
  295. package/dist/recipient-policy-onboarding.d.ts.map +1 -1
  296. package/dist/recipient-policy-reconciler.d.ts.map +1 -1
  297. package/dist/recipient-policy-reconciliation.d.ts.map +1 -1
  298. package/dist/recipient-policy-team-create.d.ts +22 -0
  299. package/dist/recipient-policy-team-create.d.ts.map +1 -0
  300. package/dist/{relay-health-CeyhVeuq.js → relay-health-B8BpHFaE.js} +14 -14
  301. package/dist/{relay-health-CeyhVeuq.js.map → relay-health-B8BpHFaE.js.map} +1 -1
  302. package/dist/{relay-peer-client-DmZfZebO.js → relay-peer-client-CrFrhN_q.js} +3140 -2687
  303. package/dist/relay-peer-client-CrFrhN_q.js.map +1 -0
  304. package/dist/relay-server-test-fixtures.d.ts.map +1 -1
  305. package/dist/removed-device-local-ids.d.ts +16 -0
  306. package/dist/removed-device-local-ids.d.ts.map +1 -0
  307. package/dist/replication-cursor-orphan-cleanup.d.ts +14 -0
  308. package/dist/replication-cursor-orphan-cleanup.d.ts.map +1 -0
  309. package/dist/retired-device-aliases.d.ts +28 -0
  310. package/dist/retired-device-aliases.d.ts.map +1 -0
  311. package/dist/same-actor-peers.d.ts +5 -1
  312. package/dist/same-actor-peers.d.ts.map +1 -1
  313. package/dist/schema-bootstrap.d.ts +1 -0
  314. package/dist/schema-bootstrap.d.ts.map +1 -1
  315. package/dist/schema.d.ts +4456 -3623
  316. package/dist/schema.d.ts.map +1 -1
  317. package/dist/scope-membership-cache-read.d.ts +28 -1
  318. package/dist/scope-membership-cache-read.d.ts.map +1 -1
  319. package/dist/scope-membership-cache-test-fixtures.d.ts +1 -0
  320. package/dist/scope-membership-cache-test-fixtures.d.ts.map +1 -1
  321. package/dist/scope-membership-cache.d.ts +1 -1
  322. package/dist/scope-membership-cache.d.ts.map +1 -1
  323. package/dist/scope-membership-evidence.d.ts +17 -1
  324. package/dist/scope-membership-evidence.d.ts.map +1 -1
  325. package/dist/{scope-membership-cache-read-B6z47l2W.js → scope-resolution-DXzf4k16.js} +2287 -1613
  326. package/dist/scope-resolution-DXzf4k16.js.map +1 -0
  327. package/dist/semantic-worker-entry.js +1 -1
  328. package/dist/{semantic-worker-job-BLaC4xRY.js → semantic-worker-job-DjfAtX64.js} +3 -3
  329. package/dist/{semantic-worker-job-BLaC4xRY.js.map → semantic-worker-job-DjfAtX64.js.map} +1 -1
  330. package/dist/{semantic-worker-ranking-5-VSzEmx.js → semantic-worker-ranking-CZCemeb4.js} +59 -53
  331. package/dist/semantic-worker-ranking-CZCemeb4.js.map +1 -0
  332. package/dist/share-provisioning.d.ts +4 -0
  333. package/dist/share-provisioning.d.ts.map +1 -1
  334. package/dist/shared-owned-device-enrollment-test-harness.d.ts.map +1 -1
  335. package/dist/shared-owned-project-invites-test-harness.d.ts.map +1 -1
  336. package/dist/shared-owned-recipient-invites-test-harness.d.ts.map +1 -1
  337. package/dist/shared-ownership-writer-lifecycle-test-harness.d.ts.map +1 -1
  338. package/dist/snapshot-cross-scope-reconcile.d.ts +25 -0
  339. package/dist/snapshot-cross-scope-reconcile.d.ts.map +1 -0
  340. package/dist/{sync-auth-constants-BVzVfSmn.js → sync-auth-constants-CifCg69d.js} +4484 -2842
  341. package/dist/sync-auth-constants-CifCg69d.js.map +1 -0
  342. package/dist/sync-bootstrap.d.ts +2 -0
  343. package/dist/sync-bootstrap.d.ts.map +1 -1
  344. package/dist/sync-capability.d.ts +1 -1
  345. package/dist/sync-capability.d.ts.map +1 -1
  346. package/dist/sync-channel-pass.d.ts.map +1 -1
  347. package/dist/sync-channel-progress.d.ts +7 -0
  348. package/dist/sync-channel-progress.d.ts.map +1 -1
  349. package/dist/sync-daemon.d.ts +4 -1
  350. package/dist/sync-daemon.d.ts.map +1 -1
  351. package/dist/sync-pass.d.ts +2 -0
  352. package/dist/sync-pass.d.ts.map +1 -1
  353. package/dist/sync-peer-addresses.d.ts +4 -2
  354. package/dist/sync-peer-addresses.d.ts.map +1 -1
  355. package/dist/sync-reachability-pass-BFTEIkZH.js +2 -0
  356. package/dist/{sync-reachability-pass-Dhn4N2hr.js → sync-reachability-pass-vOvswNNG.js} +3219 -3025
  357. package/dist/sync-reachability-pass-vOvswNNG.js.map +1 -0
  358. package/dist/sync-replication.d.ts +26 -3
  359. package/dist/sync-replication.d.ts.map +1 -1
  360. package/dist/sync-scope-protocol.d.ts.map +1 -1
  361. package/dist/sync-status-test-fixtures.d.ts +1 -1
  362. package/dist/sync-status-test-fixtures.d.ts.map +1 -1
  363. package/dist/test-environment-isolation.d.ts +2 -0
  364. package/dist/test-environment-isolation.d.ts.map +1 -0
  365. package/dist/test-schema.generated.d.ts +1 -1
  366. package/dist/test-schema.generated.d.ts.map +1 -1
  367. package/dist/test-utils.d.ts +7 -0
  368. package/dist/test-utils.d.ts.map +1 -1
  369. package/dist/{validated-vector-index-audit-B64yhEBF.js → validated-vector-index-audit-CFSIbYIn.js} +255 -623
  370. package/dist/validated-vector-index-audit-CFSIbYIn.js.map +1 -0
  371. package/dist/viewer-device-removal-commit.d.ts +56 -0
  372. package/dist/viewer-device-removal-commit.d.ts.map +1 -0
  373. package/dist/viewer-device-removal-evidence.d.ts +17 -0
  374. package/dist/viewer-device-removal-evidence.d.ts.map +1 -0
  375. package/dist/{scope-membership-semantics-B8qXaMqx.js → workspace-identity-C7EPmSZe.js} +121 -49
  376. package/dist/workspace-identity-C7EPmSZe.js.map +1 -0
  377. package/package.json +3 -3
  378. package/dist/coordinator-runtime-CEc6KhBE.js +0 -594
  379. package/dist/coordinator-runtime-CEc6KhBE.js.map +0 -1
  380. package/dist/owner-enrollment-start-BsDwgxAh.js.map +0 -1
  381. package/dist/recipient-policy-contract-Ca40IBUh.js.map +0 -1
  382. package/dist/relay-peer-client-DmZfZebO.js.map +0 -1
  383. package/dist/scope-membership-cache-read-B6z47l2W.js.map +0 -1
  384. package/dist/scope-membership-semantics-B8qXaMqx.js.map +0 -1
  385. package/dist/semantic-worker-ranking-5-VSzEmx.js.map +0 -1
  386. package/dist/sync-auth-constants-BVzVfSmn.js.map +0 -1
  387. package/dist/sync-reachability-pass-C_-w0t6b.js +0 -2
  388. package/dist/sync-reachability-pass-Dhn4N2hr.js.map +0 -1
  389. package/dist/validated-vector-index-audit-B64yhEBF.js.map +0 -1
  390. package/dist/workspace-identity-DI8bBR0Y.js +0 -76
  391. package/dist/workspace-identity-DI8bBR0Y.js.map +0 -1
@@ -0,0 +1,1716 @@
1
+ import { Kt as e, h as t, l as n, nn as r, rn as i, tn as a } from "./scope-resolution-DXzf4k16.js";
2
+ import { _ as o, h as s } from "./workspace-identity-C7EPmSZe.js";
3
+ import { Na as c, V as l, i as u, io as d, lo as f, r as p } from "./sync-auth-constants-CifCg69d.js";
4
+ import { A as m, J as h, M as g, O as ee, T as _, V as te, _ as v, ct as y, ft as ne, g as re, j as b, m as ie, v as ae, y as oe } from "./relay-peer-client-CrFrhN_q.js";
5
+ import { createHash as se } from "node:crypto";
6
+ import { networkInterfaces as ce } from "node:os";
7
+ //#region src/identity-device-assignment.ts
8
+ var x = class extends Error {
9
+ code;
10
+ constructor(e) {
11
+ super(e), this.name = "IdentityDeviceAssignmentError", this.code = e;
12
+ }
13
+ };
14
+ function S() {
15
+ throw new x("team_setup_assignment_changed");
16
+ }
17
+ function le(e) {
18
+ return typeof e == "object" && !!e && "code" in e && e.code === "SQLITE_CONSTRAINT_PRIMARYKEY";
19
+ }
20
+ function ue(e, t) {
21
+ return e.prepare("SELECT identity_id, assignment_version, status\n FROM identity_devices\n WHERE device_id = ?").get(t) ?? null;
22
+ }
23
+ function de(e, t) {
24
+ if (t.kind === "absent") {
25
+ e && S();
26
+ return;
27
+ }
28
+ (e?.status !== "active" || e.identity_id !== t.identityId || e.assignment_version !== t.assignmentVersion) && S();
29
+ }
30
+ function fe(e, t, n) {
31
+ let r = e.prepare("SELECT d.team_id\n FROM policy_team_device_decisions d\n JOIN policy_teams t ON t.team_id = d.team_id\n WHERE d.device_id = ?\n AND d.decision = 'included'\n AND t.device_eligibility_mode = 'reviewed_allowlist'").all(t), i = e.prepare("UPDATE policy_team_device_decisions\n SET decision = 'unresolved', updated_at = ?\n WHERE device_id = ?\n AND decision = 'included'\n AND team_id IN (\n SELECT team_id FROM policy_teams\n WHERE device_eligibility_mode = 'reviewed_allowlist'\n )").run(n, t);
32
+ for (let t of r) e.prepare("UPDATE policy_teams\n SET source_fingerprint = NULL, updated_at = ?\n WHERE team_id = ?").run(n, t.team_id);
33
+ return {
34
+ invalidatedDecisionCount: i.changes,
35
+ invalidatedTeamCount: r.length
36
+ };
37
+ }
38
+ function pe(e, t) {
39
+ if (!e.inTransaction) throw new x("identity_device_assignment_transaction_required");
40
+ let n = ue(e, t.deviceId);
41
+ if (de(n, t.expectation), n?.status === "active" && n?.identity_id === t.targetIdentityId) return {
42
+ assignmentVersion: n.assignment_version,
43
+ changed: !1,
44
+ invalidatedDecisionCount: 0,
45
+ invalidatedTeamCount: 0
46
+ };
47
+ let r = t.now ?? (/* @__PURE__ */ new Date()).toISOString();
48
+ if (n) {
49
+ let n = t.expectation;
50
+ n.kind !== "existing" && S();
51
+ let i = n.identityId !== t.targetIdentityId;
52
+ e.prepare(`UPDATE identity_devices
53
+ SET identity_id = ?, ${i ? "source_fingerprint = NULL," : ""} updated_at = ?
54
+ WHERE device_id = ?
55
+ AND identity_id = ?
56
+ AND assignment_version = ?
57
+ AND status = 'active'`).run(t.targetIdentityId, r, t.deviceId, n.identityId, n.assignmentVersion).changes !== 1 && S();
58
+ } else {
59
+ let n = t.insert;
60
+ if (!n) throw new x("identity_device_assignment_insert_values_required");
61
+ try {
62
+ e.prepare("INSERT INTO identity_devices(\n device_id, identity_id, display_name, status, provenance, revision,\n migration_state, source_fingerprint, idempotency_key, created_at, updated_at\n ) VALUES (?, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?)").run(t.deviceId, t.targetIdentityId, n.displayName, n.provenance, n.revision, n.migrationState, n.sourceFingerprint ?? null, n.idempotencyKey, r, r);
63
+ } catch (e) {
64
+ throw le(e) && S(), e;
65
+ }
66
+ }
67
+ let i = ue(e, t.deviceId);
68
+ return (i?.status !== "active" || i.identity_id !== t.targetIdentityId) && S(), n ? {
69
+ assignmentVersion: i.assignment_version,
70
+ changed: !0,
71
+ ...fe(e, t.deviceId, r)
72
+ } : {
73
+ assignmentVersion: i.assignment_version,
74
+ changed: !0,
75
+ invalidatedDecisionCount: 0,
76
+ invalidatedTeamCount: 0
77
+ };
78
+ }
79
+ //#endregion
80
+ //#region src/coordinator-rejoin-timestamp.ts
81
+ function me(e) {
82
+ return typeof e == "number" && Number.isSafeInteger(e) && e >= 0 && e <= 864e13;
83
+ }
84
+ //#endregion
85
+ //#region src/retired-device-aliases.ts
86
+ function C(e) {
87
+ if (!e) return null;
88
+ let t = o(e);
89
+ return t.kind === "ed25519" ? se("sha256").update(t.blob).digest("hex") : null;
90
+ }
91
+ function he(e) {
92
+ e.exec("CREATE TABLE IF NOT EXISTS retired_device_aliases (\n device_id TEXT PRIMARY KEY,\n kind TEXT NOT NULL CHECK(kind IN ('device_id', 'key')),\n fingerprint TEXT NOT NULL,\n key_id TEXT,\n retired_at TEXT NOT NULL\n )");
93
+ }
94
+ function w(e) {
95
+ if (!e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'retired_device_aliases'").get()) return /* @__PURE__ */ new Map();
96
+ let t = e.prepare("SELECT device_id, kind, fingerprint, key_id FROM retired_device_aliases").all();
97
+ return new Map(t.map((e) => [e.device_id, {
98
+ kind: e.kind,
99
+ fingerprint: e.fingerprint,
100
+ keyId: e.key_id
101
+ }]));
102
+ }
103
+ function T(e, t) {
104
+ if (!e) return !1;
105
+ if (e.kind === "device_id" || !t || !t.publicKey && !t.fingerprint) return !0;
106
+ let n = C(t.publicKey);
107
+ return e.keyId && n ? n === e.keyId : t.fingerprint === e.fingerprint;
108
+ }
109
+ function ge(e, t) {
110
+ he(e);
111
+ let n = e.prepare("INSERT INTO retired_device_aliases(device_id, kind, fingerprint, key_id, retired_at)\n VALUES (?, ?, ?, ?, ?)\n ON CONFLICT(device_id) DO UPDATE SET\n kind = CASE WHEN retired_device_aliases.kind = 'device_id' THEN 'device_id' ELSE excluded.kind END,\n fingerprint = excluded.fingerprint,\n key_id = excluded.key_id,\n retired_at = excluded.retired_at"), r = (/* @__PURE__ */ new Date()).toISOString();
112
+ for (let e of t) n.run(e.deviceId, e.kind, e.fingerprint, e.keyId, r);
113
+ }
114
+ //#endregion
115
+ //#region src/device-identity-inventory.ts
116
+ var _e = 1, ve = 500, E = 2e3;
117
+ function D(e) {
118
+ return typeof e == "string" && e.trim() ? e.trim() : null;
119
+ }
120
+ function O(e, t) {
121
+ if (!e) return {
122
+ value: t,
123
+ conflict: !1
124
+ };
125
+ let n = s(e);
126
+ return t && t !== n ? {
127
+ value: null,
128
+ conflict: !0
129
+ } : {
130
+ value: t ?? n,
131
+ conflict: !1
132
+ };
133
+ }
134
+ function ye(e) {
135
+ let t = O(D(e.publicKey), D(e.fingerprint));
136
+ return {
137
+ deviceId: e.deviceId,
138
+ displayName: e.displayName,
139
+ source: "local_device",
140
+ fingerprint: t.value,
141
+ fingerprintConflict: t.conflict,
142
+ isLocal: !0,
143
+ suggestedIdentityId: null,
144
+ bindingIdentityId: null,
145
+ bindingStatus: null,
146
+ bindingIdentityStatus: null,
147
+ bindingAuthoritative: !1,
148
+ enrollmentEnabled: null,
149
+ pairingProof: !0,
150
+ serviceDevice: !1,
151
+ revoked: !1,
152
+ rejoinedAtMs: null
153
+ };
154
+ }
155
+ function be(e) {
156
+ let t = O(D(e.publicKey), D(e.pinnedFingerprint));
157
+ return {
158
+ deviceId: e.deviceId,
159
+ displayName: e.displayName,
160
+ source: "sync_peer",
161
+ fingerprint: t.value,
162
+ fingerprintConflict: t.conflict,
163
+ isLocal: !1,
164
+ suggestedIdentityId: D(e.suggestedIdentityId),
165
+ bindingIdentityId: null,
166
+ bindingStatus: null,
167
+ bindingIdentityStatus: null,
168
+ bindingAuthoritative: !1,
169
+ enrollmentEnabled: null,
170
+ pairingProof: D(e.trustProvenance) !== "coordinator_policy" || e.claimedLocalActor,
171
+ serviceDevice: !1,
172
+ revoked: e.retired === !0,
173
+ rejoinedAtMs: null
174
+ };
175
+ }
176
+ function xe(e) {
177
+ return {
178
+ deviceId: e.deviceId,
179
+ displayName: e.displayName,
180
+ source: "identity_binding",
181
+ fingerprint: null,
182
+ fingerprintConflict: !1,
183
+ isLocal: !1,
184
+ suggestedIdentityId: null,
185
+ bindingIdentityId: e.identityId,
186
+ bindingStatus: e.status,
187
+ bindingIdentityStatus: e.identityStatus,
188
+ bindingAuthoritative: !0,
189
+ enrollmentEnabled: null,
190
+ pairingProof: !1,
191
+ serviceDevice: !1,
192
+ revoked: e.retired === !0,
193
+ rejoinedAtMs: null
194
+ };
195
+ }
196
+ function Se(e) {
197
+ let t = O(D(e.public_key), D(e.fingerprint));
198
+ return {
199
+ deviceId: e.device_id,
200
+ displayName: D(e.display_name) ?? "",
201
+ source: "coordinator_enrollment",
202
+ fingerprint: t.value,
203
+ fingerprintConflict: t.conflict,
204
+ isLocal: !1,
205
+ suggestedIdentityId: D(e.identity_id),
206
+ bindingIdentityId: null,
207
+ bindingStatus: null,
208
+ bindingIdentityStatus: null,
209
+ bindingAuthoritative: !1,
210
+ enrollmentEnabled: e.enabled === 1,
211
+ pairingProof: !1,
212
+ serviceDevice: e.service_role === "relay_health_probe",
213
+ revoked: e.revoked === !0,
214
+ rejoinedAtMs: e.enabled === 1 && me(e.rejoined_at_ms) ? e.rejoined_at_ms : null
215
+ };
216
+ }
217
+ function Ce(e) {
218
+ return [
219
+ ...e.localDevice ? [ye(e.localDevice)] : [],
220
+ ...e.peers.map(be),
221
+ ...e.bindings.map(xe),
222
+ ...e.coordinator.availability === "available" ? e.coordinator.enrollments.map(Se) : []
223
+ ].filter((e) => D(e.deviceId) != null);
224
+ }
225
+ function we(e) {
226
+ let t = e.map((e, t) => t), n = (e) => {
227
+ let r = t[e] ?? e;
228
+ return r === e ? e : (t[e] = n(r), t[e] ?? e);
229
+ }, r = (e, r) => {
230
+ let i = n(e), a = n(r);
231
+ i !== a && (t[a] = i);
232
+ }, i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
233
+ e.forEach((e, t) => {
234
+ let n = i.get(e.deviceId);
235
+ if (n == null ? i.set(e.deviceId, t) : r(t, n), !e.fingerprint || e.fingerprintConflict) return;
236
+ let o = a.get(e.fingerprint);
237
+ o == null ? a.set(e.fingerprint, t) : r(t, o);
238
+ });
239
+ let o = /* @__PURE__ */ new Map();
240
+ return e.forEach((e, t) => {
241
+ let r = n(t);
242
+ o.set(r, [...o.get(r) ?? [], e]);
243
+ }), [...o.values()];
244
+ }
245
+ var k = [
246
+ "local_device",
247
+ "identity_binding",
248
+ "sync_peer",
249
+ "coordinator_enrollment"
250
+ ];
251
+ function Te(e, t) {
252
+ return e.find((e) => e.source === t) ?? null;
253
+ }
254
+ function Ee(e) {
255
+ for (let t of k) {
256
+ let n = e.filter((e) => e.source === t && e.displayName.length > 0 && !["Canonical device", "Unnamed device"].includes(e.displayName)).toSorted((e, t) => e.deviceId.localeCompare(t.deviceId) || e.displayName.localeCompare(t.displayName))[0];
257
+ if (n) return n.displayName;
258
+ }
259
+ return "Unnamed device";
260
+ }
261
+ function De(e) {
262
+ return e.some((e) => e.serviceDevice) ? e.every((e) => e.source === "coordinator_enrollment" ? e.serviceDevice : e.source === "sync_peer" && !e.pairingProof) : !1;
263
+ }
264
+ function Oe(e, t) {
265
+ if (e.some((e) => e.revoked)) return "retired";
266
+ if (t.conflicted) return "conflicted";
267
+ if (De(e)) return "service";
268
+ if (t.activeBindings.length > 0) return "configured";
269
+ let n = e.some((e) => e.pairingProof);
270
+ return e.some((e) => e.source === "coordinator_enrollment" || e.source === "sync_peer" && !e.pairingProof) && !n ? "pairing_required" : "setup_required";
271
+ }
272
+ function ke(e, t, n) {
273
+ return e === "service" || e === "retired" || t.length > 0 ? null : n.size === 1 ? [...n][0] ?? null : null;
274
+ }
275
+ function Ae(e) {
276
+ return e.source === "identity_binding" && e.bindingAuthoritative && e.bindingStatus !== "active" && e.bindingStatus !== "removed";
277
+ }
278
+ function je(e) {
279
+ return e.flatMap((e) => e.rejoinedAtMs === null ? [] : [{
280
+ deviceId: e.deviceId,
281
+ rejoinedAtMs: e.rejoinedAtMs
282
+ }]).toSorted((e, t) => t.rejoinedAtMs - e.rejoinedAtMs || e.deviceId.localeCompare(t.deviceId))[0] ?? null;
283
+ }
284
+ function Me(e, t) {
285
+ if (e.isLocal || [
286
+ "retired",
287
+ "service",
288
+ "conflicted"
289
+ ].includes(e.state)) return e;
290
+ let n = je(t);
291
+ return n ? {
292
+ ...e,
293
+ rejoin: n
294
+ } : e;
295
+ }
296
+ function Ne(e) {
297
+ return new Set(e.flatMap((e) => e.fingerprint && !e.fingerprintConflict ? [e.fingerprint] : []));
298
+ }
299
+ function Pe(e) {
300
+ let t = [...new Set(e.map((e) => e.deviceId))].toSorted(), n = Ne(e), r = e.filter((e) => e.source === "identity_binding" && e.bindingAuthoritative && e.bindingStatus === "active"), i = new Set(r.flatMap((e) => e.bindingIdentityId ? [e.bindingIdentityId] : [])), a = new Set(e.flatMap((e) => e.suggestedIdentityId ? [e.suggestedIdentityId] : [])), o = [
301
+ e.some((e) => e.fingerprintConflict) ? "fingerprint_invalid" : null,
302
+ n.size > 1 ? "fingerprint_conflict" : null,
303
+ i.size > 1 ? "identity_binding_conflict" : null,
304
+ e.some((e) => e.source === "identity_binding" && e.bindingAuthoritative && e.bindingStatus === "active" && e.bindingIdentityStatus !== "active") ? "identity_inactive" : null,
305
+ e.some(Ae) ? "identity_binding_revoked" : null,
306
+ e.some((e) => e.source === "coordinator_enrollment" && e.enrollmentEnabled === !1) ? "coordinator_enrollment_disabled" : null
307
+ ].filter((e) => e != null), s = Oe(e, {
308
+ conflicted: o.length > 0,
309
+ activeBindings: r
310
+ }), c = k.map((t) => Te(e, t)).find((e) => e != null), l = k.filter((t) => e.some((e) => e.source === t));
311
+ return Me({
312
+ version: 1,
313
+ deviceId: c?.deviceId ?? t[0] ?? "",
314
+ evidenceDeviceIds: t,
315
+ displayName: Ee(e),
316
+ state: s,
317
+ identityId: s === "configured" && i.size === 1 ? [...i][0] ?? null : null,
318
+ suggestedIdentityId: ke(s, r, a),
319
+ validatedFingerprint: n.size === 1 ? [...n][0] ?? null : null,
320
+ isLocal: e.some((e) => e.isLocal),
321
+ sources: l,
322
+ conflictCodes: [...new Set(o)].toSorted()
323
+ }, e);
324
+ }
325
+ function Fe(e, t = {}) {
326
+ let n = Math.max(1, Math.min(t.limit ?? 500, 2e3)), r = we(Ce(e)).map(Pe).toSorted((e, t) => Number(t.isLocal) - Number(e.isLocal) || e.displayName.localeCompare(t.displayName) || e.deviceId.localeCompare(t.deviceId));
327
+ return {
328
+ version: 1,
329
+ items: r.slice(0, n),
330
+ coordinatorEvidence: {
331
+ availability: e.coordinator.availability,
332
+ safeErrorCode: e.coordinator.safeErrorCode
333
+ },
334
+ truncated: e.localEvidenceTruncated === !0 || r.length > n
335
+ };
336
+ }
337
+ function Ie(e) {
338
+ let t = D(e.display_name) ?? "";
339
+ return e.provenance === "coordinator_enrollment" && t === "Enrolled device" || ["managed_exact_project", "review_resolution"].includes(String(e.provenance)) && t === "Peer device" ? "" : t;
340
+ }
341
+ function Le(e, t) {
342
+ let n = String(e.device_id ?? "");
343
+ return {
344
+ deviceId: n,
345
+ displayName: Ie(e),
346
+ identityId: String(e.identity_id ?? ""),
347
+ status: String(e.status ?? ""),
348
+ identityStatus: D(e.identity_status),
349
+ retired: t(n)
350
+ };
351
+ }
352
+ function Re(e, t) {
353
+ return e.slice(0, 2001).map((e) => Le(e, t)).filter((e) => e.status !== "removed" || e.retired);
354
+ }
355
+ function ze(e, t) {
356
+ let n = w(e), r = new Map(t.map((e) => [e.deviceId, {
357
+ publicKey: e.publicKey,
358
+ fingerprint: e.pinnedFingerprint
359
+ }]));
360
+ return (e) => T(n.get(e), r.get(e) ?? null);
361
+ }
362
+ function Be(e, t) {
363
+ let n = e.prepare("SELECT device_id, public_key, fingerprint FROM sync_device\n WHERE device_id = ? LIMIT 1").get(t.localDeviceId), r = e.prepare("SELECT peer_device_id, name, public_key, pinned_fingerprint, actor_id,\n trust_provenance, claimed_local_actor\n FROM sync_peers ORDER BY peer_device_id LIMIT ?").all(2001), i = r.slice(0, E).map((e) => {
364
+ let t = e;
365
+ return {
366
+ deviceId: String(t.peer_device_id ?? ""),
367
+ displayName: D(t.name) ?? "",
368
+ publicKey: D(t.public_key),
369
+ pinnedFingerprint: D(t.pinned_fingerprint),
370
+ suggestedIdentityId: D(t.actor_id),
371
+ trustProvenance: D(t.trust_provenance),
372
+ claimedLocalActor: t.claimed_local_actor === 1
373
+ };
374
+ }), a = e.prepare("SELECT device.device_id, device.display_name, device.identity_id, device.status, device.provenance,\n actor.status AS identity_status\n FROM identity_devices device\n LEFT JOIN actors actor ON actor.actor_id = device.identity_id\n ORDER BY CASE\n WHEN device.device_id = ? THEN 0\n WHEN device.device_id IN (\n SELECT peer_device_id FROM sync_peers ORDER BY peer_device_id LIMIT ?\n ) THEN 1\n ELSE 2\n END, device.device_id LIMIT ?").all(t.localDeviceId, E, 2002), o = ze(e, i), s = Re(a, o);
375
+ return {
376
+ localDevice: n ? {
377
+ deviceId: n.device_id,
378
+ displayName: D(t.localDisplayName) ?? "",
379
+ publicKey: n.public_key,
380
+ fingerprint: n.fingerprint
381
+ } : null,
382
+ peers: i.map((e) => ({
383
+ ...e,
384
+ retired: o(e.deviceId)
385
+ })),
386
+ bindings: s,
387
+ coordinator: t.coordinator,
388
+ localEvidenceTruncated: r.length > E || a.length > 2001
389
+ };
390
+ }
391
+ function A(e, t, n = {}) {
392
+ return Fe(Be(e, t), n);
393
+ }
394
+ //#endregion
395
+ //#region src/recipient-policy-actor-eligibility.ts
396
+ function Ve(e) {
397
+ return e?.status === "active" && e.mergedIntoActorId === null;
398
+ }
399
+ function He(e, t) {
400
+ let n = e.prepare("SELECT is_local, status, merged_into_actor_id FROM actors WHERE actor_id = ? LIMIT 1").get(t);
401
+ return n ? {
402
+ isLocal: n.is_local === 1,
403
+ status: n.status,
404
+ mergedIntoActorId: n.merged_into_actor_id
405
+ } : null;
406
+ }
407
+ function j(e, t) {
408
+ return Ve(He(e, t));
409
+ }
410
+ function M(e, t) {
411
+ let n = He(e, t);
412
+ return n?.isLocal === !0 && Ve(n);
413
+ }
414
+ function Ue(e) {
415
+ return e.prepare("SELECT actor_id FROM actors WHERE status = 'active' AND merged_into_actor_id IS NULL ORDER BY actor_id").pluck().all();
416
+ }
417
+ function We(e, t) {
418
+ let n = [...new Set(t)];
419
+ return n.length === 0 ? [] : e.prepare(`SELECT actor_id FROM actors
420
+ WHERE actor_id IN (${n.map(() => "?").join(", ")})
421
+ AND status = 'active' AND merged_into_actor_id IS NULL
422
+ ORDER BY actor_id`).pluck().all(...n);
423
+ }
424
+ function Ge(e, t, n) {
425
+ return M(e, t) ? t : n !== t && M(e, n) ? n : e.prepare("SELECT actor_id FROM actors\n WHERE is_local = 1 AND status = 'active' AND merged_into_actor_id IS NULL\n ORDER BY actor_id LIMIT 1").pluck().get() ?? null;
426
+ }
427
+ //#endregion
428
+ //#region src/device-identity-binding.ts
429
+ var Ke = 1, qe = 100, N = class extends Error {
430
+ status;
431
+ errorCode;
432
+ constructor(e, t) {
433
+ super(t), this.status = e, this.errorCode = t;
434
+ }
435
+ }, Je = d, P = f;
436
+ function Ye(e) {
437
+ return Je({ bindings: e.bindings.map((e) => ({
438
+ deviceId: e.deviceId,
439
+ targetIdentityId: e.targetIdentityId,
440
+ confirmed: e.confirmed,
441
+ allowRebind: e.allowRebind === !0
442
+ })) });
443
+ }
444
+ function F(e, t) {
445
+ return {
446
+ version: 1,
447
+ status: e,
448
+ reviewedInventoryDigest: "",
449
+ errorCode: t,
450
+ outcomes: [],
451
+ writeCount: 0
452
+ };
453
+ }
454
+ function Xe(e) {
455
+ return typeof e?.deviceId == "string" && e.deviceId.trim() === e.deviceId && e.deviceId.length > 0 && typeof e.targetIdentityId == "string" && e.targetIdentityId.trim() === e.targetIdentityId && e.targetIdentityId.length > 0 && e.confirmed === !0 && (e.allowRebind === void 0 || typeof e.allowRebind == "boolean");
456
+ }
457
+ function Ze(e, t, n) {
458
+ return e.state === "service" ? F("conflict", "device_service_role") : e.state === "retired" ? F("conflict", "device_retired") : e.state === "pairing_required" ? F("conflict", "device_pairing_required") : e.state === "conflicted" ? F("conflict", "device_evidence_conflict") : e.state === "configured" && e.identityId !== t.targetIdentityId ? t.allowRebind === !0 ? {
459
+ deviceId: n,
460
+ displayName: e.displayName,
461
+ targetIdentityId: t.targetIdentityId,
462
+ previousIdentityId: e.identityId,
463
+ action: "rebind",
464
+ isLocal: e.isLocal
465
+ } : F("conflict", "device_rebind_confirmation_required") : {
466
+ deviceId: n,
467
+ displayName: e.displayName,
468
+ targetIdentityId: t.targetIdentityId,
469
+ previousIdentityId: e.identityId,
470
+ action: e.state === "configured" ? "unchanged" : "bind",
471
+ isLocal: e.isLocal
472
+ };
473
+ }
474
+ function Qe(e) {
475
+ return {
476
+ deviceId: e.deviceId,
477
+ evidenceDeviceIds: e.evidenceDeviceIds,
478
+ state: e.state,
479
+ identityId: e.identityId,
480
+ validatedFingerprint: e.validatedFingerprint,
481
+ isLocal: e.isLocal,
482
+ sources: e.sources,
483
+ conflictCodes: e.conflictCodes
484
+ };
485
+ }
486
+ function $e(e, t) {
487
+ let n = e.prepare("SELECT status, updated_at FROM identity_devices WHERE device_id = ? AND status = 'removed'");
488
+ return [...new Set(t.flatMap((e) => e.evidenceDeviceIds))].toSorted().flatMap((e) => {
489
+ let t = n.get(e);
490
+ return t ? [{
491
+ deviceId: e,
492
+ status: t.status,
493
+ endedAt: t.updated_at
494
+ }] : [];
495
+ });
496
+ }
497
+ function et(e, t) {
498
+ let n = $e(e, t.selectedItems);
499
+ return P("device-identity-binding-preview-v1", {
500
+ selectedItems: t.selectedItems.map(Qe),
501
+ coordinatorAvailability: t.inventory.coordinatorEvidence.availability,
502
+ inventoryTruncated: t.inventory.truncated,
503
+ request: JSON.parse(Ye(t.request)),
504
+ ...n.length > 0 ? { endedBindings: n } : {}
505
+ });
506
+ }
507
+ function I(e, t, n) {
508
+ if (!n || !Array.isArray(n.bindings) || n.bindings.length === 0 || n.bindings.length > qe || n.bindings.some((e) => !Xe(e))) return F("invalid", "binding_request_invalid");
509
+ let r = n.bindings.map((e) => e.deviceId);
510
+ if (new Set(r).size !== r.length) return F("invalid", "duplicate_device_id");
511
+ let i = A(e, t);
512
+ if (i.truncated) return F("conflict", "device_inventory_truncated");
513
+ let a = new Map(i.items.map((e) => [e.deviceId, e])), o = [];
514
+ for (let e of n.bindings) {
515
+ let t = a.get(e.deviceId);
516
+ if (!t) return F("not_found", "device_not_found");
517
+ o.push(t);
518
+ }
519
+ if (i.coordinatorEvidence.availability !== "available" && !(i.coordinatorEvidence.safeErrorCode === "coordinator_not_configured" && o.every((e) => e.isLocal))) return F("conflict", "device_inventory_incomplete");
520
+ let s = [];
521
+ for (let [t, r] of n.bindings.entries()) {
522
+ if (!j(e, r.targetIdentityId)) return F("not_found", "target_identity_unavailable");
523
+ let n = o[t];
524
+ if (!n) return F("not_found", "device_not_found");
525
+ let i = n.deviceId;
526
+ if (n.state === "configured") {
527
+ let t = n.evidenceDeviceIds.filter((t) => L(e, t)?.status === "active");
528
+ if (t.length !== 1) return F("conflict", "device_evidence_conflict");
529
+ i = t[0] ?? n.deviceId;
530
+ }
531
+ let a = Ze(n, r, i);
532
+ if ("status" in a) return a;
533
+ s.push(a);
534
+ }
535
+ return {
536
+ version: 1,
537
+ status: "ready",
538
+ reviewedInventoryDigest: et(e, {
539
+ selectedItems: o,
540
+ inventory: i,
541
+ request: n
542
+ }),
543
+ errorCode: null,
544
+ outcomes: s,
545
+ writeCount: s.filter((e) => e.action !== "unchanged").length
546
+ };
547
+ }
548
+ function L(e, t) {
549
+ return e.prepare("SELECT identity_id, status, assignment_version FROM identity_devices\n WHERE device_id = ?").get(t);
550
+ }
551
+ function tt(e, t, n, r, i) {
552
+ let a = e.prepare("SELECT request_json, outcomes_json, write_count\n FROM device_identity_binding_commits WHERE commit_digest = ?").get(n);
553
+ if (!a) return null;
554
+ if (a.request_json !== r) return {
555
+ ...F("conflict", "binding_commit_conflict"),
556
+ status: "conflict",
557
+ reviewedInventoryDigest: i.reviewedInventoryDigest,
558
+ idempotent: !1
559
+ };
560
+ let o = JSON.parse(a.outcomes_json);
561
+ if (!o.every((t) => {
562
+ let n = L(e, t.deviceId);
563
+ return n?.status === "active" && n.identity_id === t.targetIdentityId && j(e, t.targetIdentityId);
564
+ })) return {
565
+ version: 1,
566
+ status: "stale",
567
+ reviewedInventoryDigest: i.reviewedInventoryDigest,
568
+ errorCode: "binding_retry_stale",
569
+ outcomes: [],
570
+ writeCount: 0,
571
+ idempotent: !1
572
+ };
573
+ let s = I(e, t, i);
574
+ return s.status === "invalid" || s.status === "not_found" || s.status === "conflict" ? {
575
+ ...s,
576
+ status: s.status,
577
+ reviewedInventoryDigest: i.reviewedInventoryDigest,
578
+ idempotent: !1
579
+ } : s.outcomes.some((e) => e.action !== "unchanged") ? {
580
+ version: 1,
581
+ status: "stale",
582
+ reviewedInventoryDigest: i.reviewedInventoryDigest,
583
+ errorCode: "binding_retry_stale",
584
+ outcomes: [],
585
+ writeCount: 0,
586
+ idempotent: !1
587
+ } : {
588
+ version: 1,
589
+ status: "applied",
590
+ reviewedInventoryDigest: i.reviewedInventoryDigest,
591
+ errorCode: null,
592
+ outcomes: o,
593
+ writeCount: 0,
594
+ idempotent: !0
595
+ };
596
+ }
597
+ function nt(e, t) {
598
+ if (!e.inTransaction) throw Error("binding_reactivation_transaction_required");
599
+ let n = L(e, t.deviceId);
600
+ if (n?.status !== "removed") return null;
601
+ e.prepare("UPDATE identity_devices SET identity_id = ?, display_name = ?, status = 'active',\n provenance = ?, revision = ?, migration_state = ?, source_fingerprint = ?,\n idempotency_key = ?, updated_at = ?\n WHERE device_id = ? AND status = 'removed'").run(t.targetIdentityId, t.displayName, t.provenance, t.revision, t.migrationState, t.sourceFingerprint, t.idempotencyKey, t.now, t.deviceId), n.identity_id !== t.targetIdentityId && fe(e, t.deviceId, t.now);
602
+ let r = L(e, t.deviceId)?.assignment_version ?? 0;
603
+ return R(e, [n.identity_id, t.targetIdentityId], t.now), {
604
+ assignmentVersion: r,
605
+ previousIdentityId: n.identity_id
606
+ };
607
+ }
608
+ function rt(e, t, n, r) {
609
+ if (n && n.status !== "removed") throw new N("conflict", "binding_write_conflict");
610
+ if (n) {
611
+ if (!nt(e, {
612
+ deviceId: t.deviceId,
613
+ targetIdentityId: t.targetIdentityId,
614
+ displayName: t.displayName,
615
+ provenance: "user_confirmed_identity_setup",
616
+ revision: r.revision,
617
+ migrationState: "user_managed",
618
+ sourceFingerprint: r.commitDigest,
619
+ idempotencyKey: r.idempotencyKey,
620
+ now: r.now
621
+ })) throw new N("stale", "binding_write_stale");
622
+ return;
623
+ }
624
+ e.prepare("INSERT INTO identity_devices(\n device_id, identity_id, display_name, status, provenance, revision, migration_state,\n source_fingerprint, idempotency_key, created_at, updated_at\n ) VALUES (?, ?, ?, 'active', 'user_confirmed_identity_setup', ?, 'user_managed', ?, ?, ?, ?)").run(t.deviceId, t.targetIdentityId, t.displayName, r.revision, r.commitDigest, r.idempotencyKey, r.now, r.now);
625
+ }
626
+ function it(e, t, n, r, i) {
627
+ let a = L(e, r.deviceId);
628
+ if (r.action === "rebind" && (a?.status !== "active" || a.identity_id !== r.previousIdentityId)) throw new N("stale", "binding_rebind_stale");
629
+ if (r.action === "unchanged" && (a?.status !== "active" || a.identity_id !== r.targetIdentityId)) throw new N("stale", "binding_unchanged_stale");
630
+ let o = P("device-identity-binding-revision-v1", [n, r.deviceId]), s = P("device-identity-binding-row-v1", [n, r.deviceId]);
631
+ if (r.action === "rebind") {
632
+ if (e.prepare("UPDATE identity_devices SET identity_id = ?, status = 'active',\n provenance = 'user_confirmed_identity_setup', revision = ?, migration_state = 'user_managed',\n source_fingerprint = ?, idempotency_key = ?, updated_at = ?\n WHERE device_id = ? AND identity_id = ? AND status = 'active'").run(r.targetIdentityId, o, n, s, i, r.deviceId, r.previousIdentityId).changes !== 1) throw new N("stale", "binding_rebind_stale");
633
+ } else r.action === "bind" && rt(e, r, a, {
634
+ revision: o,
635
+ commitDigest: n,
636
+ idempotencyKey: s,
637
+ now: i
638
+ });
639
+ let c = L(e, r.deviceId);
640
+ if (c?.status !== "active" || c.identity_id !== r.targetIdentityId) throw new N("stale", "binding_write_stale");
641
+ e.prepare("INSERT INTO device_identity_binding_audit(\n event_id, commit_digest, device_id, previous_identity_id, target_identity_id,\n action, previous_assignment_version, resulting_assignment_version,\n decided_by_identity_id, decided_by_device_id, created_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").run(P("device-identity-binding-event-v1", [n, r.deviceId]), n, r.deviceId, a?.identity_id ?? null, r.targetIdentityId, r.action, a?.assignment_version ?? null, c.assignment_version, t.localActorId, t.localDeviceId, i);
642
+ }
643
+ function R(e, t, n) {
644
+ let r = e.prepare("SELECT DISTINCT recipient.canonical_project_identity\n FROM project_recipients recipient\n WHERE recipient.status = 'active'\n AND (\n (recipient.recipient_kind = 'identity' AND recipient.recipient_id = ?)\n OR (recipient.recipient_kind = 'team' AND recipient.recipient_id IN (\n SELECT membership.team_id\n FROM policy_team_memberships membership\n JOIN policy_teams team ON team.team_id = membership.team_id\n WHERE membership.identity_id = ? AND team.status = 'active'\n AND (\n (team.device_eligibility_mode = 'person_all_devices' AND membership.status = 'active')\n OR (team.device_eligibility_mode = 'reviewed_allowlist'\n AND membership.status = 'reviewed_active')\n )\n ))\n )"), i = /* @__PURE__ */ new Set();
645
+ for (let e of new Set(t)) for (let t of r.pluck().all(e, e)) i.add(t);
646
+ at(e, i, n);
647
+ }
648
+ function at(e, t, n) {
649
+ let r = [...t];
650
+ if (r.length === 0) return;
651
+ let i = te(e), a = new Set(r.map((e) => g(i, e))), o = e.prepare("SELECT canonical_project_identity FROM recipient_policy_authority_states").pluck().all(), s = e.prepare("UPDATE recipient_policy_authority_states\n SET last_attempt_at = NULL, wake_epoch = wake_epoch + 1\n WHERE canonical_project_identity = ?");
652
+ for (let e of o) {
653
+ let t = g(i, e);
654
+ a.has(t) && s.run(e);
655
+ }
656
+ }
657
+ function ot(e, t, n) {
658
+ let r = /* @__PURE__ */ new Set();
659
+ for (let e of t) e.action !== "unchanged" && (e.previousIdentityId && r.add(e.previousIdentityId), r.add(e.targetIdentityId));
660
+ R(e, r, n);
661
+ }
662
+ function st(e, t, n, r) {
663
+ if (typeof r.reviewedInventoryDigest != "string" || !r.reviewedInventoryDigest) return {
664
+ ...F("invalid", "reviewed_inventory_digest_required"),
665
+ status: "invalid",
666
+ idempotent: !1
667
+ };
668
+ let i = Ye(r), a = P("device-identity-binding-commit-v1", {
669
+ request: JSON.parse(i),
670
+ reviewedInventoryDigest: r.reviewedInventoryDigest
671
+ }), o = tt(e, n, a, i, r);
672
+ if (o) return o;
673
+ let s = I(e, n, r);
674
+ if (s.status !== "ready") return {
675
+ ...s,
676
+ status: s.status,
677
+ idempotent: !1
678
+ };
679
+ if (s.reviewedInventoryDigest !== r.reviewedInventoryDigest) return {
680
+ ...s,
681
+ status: "stale",
682
+ errorCode: "binding_evidence_stale",
683
+ writeCount: 0,
684
+ idempotent: !1
685
+ };
686
+ if (!M(e, t.localActorId)) return {
687
+ ...s,
688
+ status: "invalid",
689
+ errorCode: "deciding_identity_unavailable",
690
+ writeCount: 0,
691
+ idempotent: !1
692
+ };
693
+ let c = (t.now ?? (() => (/* @__PURE__ */ new Date()).toISOString()))();
694
+ e.prepare("INSERT INTO device_identity_binding_commits(\n commit_digest, reviewed_inventory_digest, request_json, outcomes_json, write_count,\n decided_by_identity_id, decided_by_device_id, created_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)").run(a, r.reviewedInventoryDigest, i, Je(s.outcomes), s.writeCount, t.localActorId, t.localDeviceId, c);
695
+ for (let n of s.outcomes) it(e, t, a, n, c);
696
+ return ot(e, s.outcomes, c), {
697
+ ...s,
698
+ status: "applied",
699
+ idempotent: !1
700
+ };
701
+ }
702
+ function ct(e, t, n, r) {
703
+ try {
704
+ return e.transaction(() => st(e, t, n, r)).immediate();
705
+ } catch (e) {
706
+ if (e instanceof N) return {
707
+ version: 1,
708
+ status: e.status,
709
+ reviewedInventoryDigest: r.reviewedInventoryDigest ?? "",
710
+ errorCode: e.errorCode,
711
+ outcomes: [],
712
+ writeCount: 0,
713
+ idempotent: !1
714
+ };
715
+ if ((e && typeof e == "object" && "code" in e ? String(e.code ?? "") : "").startsWith("SQLITE_CONSTRAINT")) return {
716
+ ...F("conflict", "binding_commit_conflict"),
717
+ status: "conflict",
718
+ reviewedInventoryDigest: r.reviewedInventoryDigest ?? "",
719
+ idempotent: !1
720
+ };
721
+ throw e;
722
+ }
723
+ }
724
+ //#endregion
725
+ //#region src/coordinator-peer-revocation.ts
726
+ var lt = 25, ut = class extends Error {
727
+ status;
728
+ constructor(e) {
729
+ super(`peer revocation check failed (${e})`), this.status = e;
730
+ }
731
+ };
732
+ function dt(e) {
733
+ if (typeof e == "string" && e.trim() !== "") return e.length <= 4096 && !e.includes("\0") ? e : void 0;
734
+ }
735
+ function ft(e, t) {
736
+ let n = dt(t);
737
+ return n === void 0 ? { device_id: e } : {
738
+ device_id: e,
739
+ public_key: n
740
+ };
741
+ }
742
+ function pt(e, t) {
743
+ let n = e.prepare("SELECT peer_device_id, public_key FROM sync_peers\n WHERE peer_device_id IS NOT ? ORDER BY peer_device_id").all(t), r = new Map(n.map((e) => [e.peer_device_id, e.public_key])), i = e.prepare("SELECT device_id FROM identity_devices\n WHERE status = 'active' AND device_id IS NOT ? ORDER BY device_id").pluck().all(t), a = [...r.keys(), ...i.filter((e) => !r.has(e))], o = a.filter((e) => c(e)).map((e) => ft(e, r.get(e)));
744
+ return {
745
+ entries: o,
746
+ omitted: o.length !== a.length
747
+ };
748
+ }
749
+ function mt(e, t) {
750
+ return e.filter((e) => typeof e == "string" && t.has(e));
751
+ }
752
+ function ht(e, t) {
753
+ let { version: n, revoked: r, removed: i, enrolled: a, removal_seq: o } = e ?? {};
754
+ if (n !== 1 || !Array.isArray(r) || !Array.isArray(i) || !Array.isArray(a) || !Number.isSafeInteger(o) || o < 0) throw Error("peer_revocation_response_invalid");
755
+ let s = new Set(t.map((e) => e.device_id)), c = mt(r, s);
756
+ return {
757
+ revoked: c,
758
+ removed: mt(i, s).filter((e) => !c.includes(e)),
759
+ enrolled: mt(a, s),
760
+ removalSeq: o
761
+ };
762
+ }
763
+ async function gt(e, t, n, r) {
764
+ let i = { peers: r }, a = Buffer.from(JSON.stringify(i), "utf8"), o = `${m(t.syncCoordinatorUrl)}/v1/peers/revocations?group_id=${encodeURIComponent(n.groupId)}`, s = h({
765
+ deviceId: n.localDeviceId,
766
+ dbPath: e.dbPath,
767
+ method: "POST",
768
+ url: o,
769
+ bodyBytes: a,
770
+ keysDir: n.keysDir
771
+ }), [c, l] = await b("POST", o, {
772
+ headers: s,
773
+ body: i,
774
+ bodyBytes: a,
775
+ timeoutS: Math.max(1, t.syncCoordinatorTimeoutS)
776
+ });
777
+ if (c === 403 && l?.error === "device_removed" && n.removedFromGroups?.push(n.groupId), c !== 200) throw new ut(c);
778
+ return ht(l, r);
779
+ }
780
+ function _t(e) {
781
+ return e instanceof ut ? e.status === 404 ? "unsupported" : e.status !== 401 && e.status !== 403 && e.status !== 409 ? "failed" : "refused" : "failed";
782
+ }
783
+ async function vt(e, t, n, r, i) {
784
+ for (let a of t.syncCoordinatorGroups) try {
785
+ return {
786
+ kind: "answered",
787
+ groupId: a,
788
+ reply: await gt(e, t, {
789
+ ...n,
790
+ groupId: a,
791
+ removedFromGroups: i
792
+ }, r)
793
+ };
794
+ } catch (e) {
795
+ let t = _t(e);
796
+ if (t === "failed") throw e;
797
+ if (t === "unsupported") return { kind: "unsupported" };
798
+ }
799
+ return { kind: "refused" };
800
+ }
801
+ function yt(e) {
802
+ if (e.length === 0) return [[]];
803
+ let t = [];
804
+ for (let n = 0; n < e.length; n += lt) t.push(e.slice(n, n + lt));
805
+ return t;
806
+ }
807
+ function z(e, t, n = []) {
808
+ return {
809
+ status: e,
810
+ revoked: [],
811
+ removed: [],
812
+ enrolled: [],
813
+ removalSeq: null,
814
+ generation: t,
815
+ removedFromGroups: n
816
+ };
817
+ }
818
+ async function bt(e, t, n) {
819
+ let { entries: i, omitted: a, generation: o } = e.db.transaction(() => ({
820
+ ...pt(e.db, n.localDeviceId),
821
+ generation: r(e.db)?.generation ?? null
822
+ }))(), s = [];
823
+ try {
824
+ let [r = [], ...c] = yt(i), l = await vt(e, t, n, r, s);
825
+ if (l.kind === "unsupported") return z("unsupported", o, s);
826
+ if (l.kind === "refused") return z("failed", o, s);
827
+ let u = [l.reply], d = {
828
+ ...n,
829
+ groupId: l.groupId,
830
+ removedFromGroups: s
831
+ };
832
+ for (let n of c) u.push(await gt(e, t, d, n));
833
+ return {
834
+ status: "checked",
835
+ revoked: u.flatMap((e) => e.revoked),
836
+ removed: u.flatMap((e) => e.removed),
837
+ enrolled: u.flatMap((e) => e.enrolled),
838
+ removalSeq: a ? null : Math.min(...u.map((e) => e.removalSeq)),
839
+ generation: o,
840
+ removedFromGroups: []
841
+ };
842
+ } catch {
843
+ return z("failed", o, s);
844
+ }
845
+ }
846
+ async function xt(e, t, n) {
847
+ let r = n.publicKey !== void 0 && dt(n.publicKey) === void 0;
848
+ if (!c(n.deviceId) || r) return { answered: !1 };
849
+ let i = ft(n.deviceId, n.publicKey);
850
+ try {
851
+ let r = await vt(e, t, n, [i]);
852
+ return r.kind === "answered" ? {
853
+ answered: !0,
854
+ enrolled: r.reply.enrolled.includes(n.deviceId),
855
+ removed: r.reply.removed.includes(n.deviceId),
856
+ revoked: r.reply.revoked.includes(n.deviceId)
857
+ } : { answered: !1 };
858
+ } catch {
859
+ return { answered: !1 };
860
+ }
861
+ }
862
+ //#endregion
863
+ //#region src/coordinator-removal-notice.ts
864
+ var B = "sync_coordinator_device_removed";
865
+ function St(e) {
866
+ return e.prepare("SELECT 1 FROM sqlite_schema WHERE type = 'table' AND name = ?").get(B) !== void 0;
867
+ }
868
+ function Ct(e, t) {
869
+ t.groupIds.length !== 0 && e.transaction(() => {
870
+ e.exec(`CREATE TABLE IF NOT EXISTS ${B} (
871
+ coordinator_id TEXT NOT NULL,
872
+ group_id TEXT NOT NULL,
873
+ noticed_at TEXT NOT NULL,
874
+ PRIMARY KEY (coordinator_id, group_id)
875
+ )`);
876
+ let n = e.prepare(`INSERT OR IGNORE INTO ${B}(coordinator_id, group_id, noticed_at) VALUES (?, ?, ?)`), r = t.now ?? (/* @__PURE__ */ new Date()).toISOString();
877
+ for (let e of t.groupIds) n.run(t.coordinatorId, e, r);
878
+ }).immediate();
879
+ }
880
+ function wt(e, t) {
881
+ St(e) && e.prepare(`DELETE FROM ${B} WHERE coordinator_id = ?`).run(t);
882
+ }
883
+ function Tt(e, t) {
884
+ if (!St(e)) return {
885
+ removed: !1,
886
+ removedFromGroups: []
887
+ };
888
+ let n = new Set(e.prepare(`SELECT group_id FROM ${B} WHERE coordinator_id = ?`).pluck().all(t.coordinatorId)), r = t.groupIds.filter((e) => n.has(e));
889
+ return {
890
+ removed: t.groupIds.length > 0 && r.length === t.groupIds.length,
891
+ removedFromGroups: r
892
+ };
893
+ }
894
+ //#endregion
895
+ //#region src/memory-retirement-trust.ts
896
+ function Et(e) {
897
+ return !!(e?.public_key && e.pinned_fingerprint && s(e.public_key) === e.pinned_fingerprint);
898
+ }
899
+ function V(e, t) {
900
+ if (!e.inTransaction) throw Error("retirement_trust_transaction_required");
901
+ let n = e.prepare("SELECT public_key, pinned_fingerprint FROM sync_peers WHERE peer_device_id = ?").get(t.peerDeviceId);
902
+ Et(n) && e.prepare("INSERT OR IGNORE INTO memory_retirement_peer_trust\n (local_device_id, peer_device_id, public_key, pinned_fingerprint) VALUES (?, ?, ?, ?)").run(t.localDeviceId, t.peerDeviceId, n.public_key, n.pinned_fingerprint);
903
+ }
904
+ //#endregion
905
+ //#region src/pairing-removal.ts
906
+ function Dt(e, t) {
907
+ let n = e.prepare("SELECT public_key, pinned_fingerprint FROM sync_peers WHERE peer_device_id = ?").get(t);
908
+ return !n?.public_key || !n.pinned_fingerprint || s(n.public_key) !== n.pinned_fingerprint ? [] : [{
909
+ deviceId: t,
910
+ kind: "key",
911
+ fingerprint: n.pinned_fingerprint,
912
+ keyId: C(n.public_key)
913
+ }];
914
+ }
915
+ function Ot(e, t) {
916
+ return e.prepare("DELETE FROM sync_peers WHERE peer_device_id = ?").run(t).changes;
917
+ }
918
+ function kt(e, t) {
919
+ return e.prepare("DELETE FROM sync_peers\n WHERE peer_device_id = ? AND claimed_local_actor = 0\n AND actor_id IS NULL AND pending_bootstrap_grant_id IS NULL\n AND trust_provenance = 'coordinator_policy'\n AND discovered_via_coordinator_id = ? AND discovered_via_group_id = ?").run(t.deviceId, t.coordinatorId, t.groupId).changes;
920
+ }
921
+ function At(t, n) {
922
+ return {
923
+ replicationCursors: t.prepare("DELETE FROM replication_cursors WHERE peer_device_id = ?").run(n).changes,
924
+ replicationCursorsV2: t.prepare("DELETE FROM replication_cursors_v2 WHERE peer_device_id = ?").run(n).changes,
925
+ syncChannelProgress: e(t, n)
926
+ };
927
+ }
928
+ function jt(e, t, n) {
929
+ return e.prepare("UPDATE identity_devices SET status = 'removed', updated_at = ?\n WHERE device_id = ? AND status = 'active' RETURNING identity_id").get(n, t)?.identity_id ?? null;
930
+ }
931
+ function Mt(e, t) {
932
+ e.syncPeers += t.syncPeers, e.replicationCursors += t.replicationCursors, e.replicationCursorsV2 += t.replicationCursorsV2, e.syncChannelProgress += t.syncChannelProgress;
933
+ }
934
+ function Nt(e, t, n) {
935
+ let r = Ft();
936
+ for (let i of n) {
937
+ V(e, {
938
+ localDeviceId: t,
939
+ peerDeviceId: i.deviceId
940
+ });
941
+ let n = kt(e, i);
942
+ n !== 0 && Mt(r, {
943
+ syncPeers: n,
944
+ ...At(e, i.deviceId)
945
+ });
946
+ }
947
+ return r;
948
+ }
949
+ function Pt(e, n) {
950
+ let r = Ft(), i = [...new Set(n.deviceIds)];
951
+ n.reason === "revoked" && ge(e, n.retiredAliases ?? i.flatMap((t) => Dt(e, t)));
952
+ let a = (/* @__PURE__ */ new Date()).toISOString(), o = /* @__PURE__ */ new Set();
953
+ n.reason !== "disconnect" && t(e, i.filter((e) => e !== n.localDeviceId));
954
+ for (let t of i) {
955
+ if (V(e, {
956
+ localDeviceId: n.localDeviceId,
957
+ peerDeviceId: t
958
+ }), Mt(r, {
959
+ syncPeers: Ot(e, t),
960
+ ...At(e, t)
961
+ }), n.reason === "disconnect" || t === n.localDeviceId) continue;
962
+ let i = jt(e, t, a);
963
+ i && (r.identityDevices += 1, o.add(i));
964
+ }
965
+ return o.size === 0 || R(e, o, a), r;
966
+ }
967
+ function Ft() {
968
+ return {
969
+ syncPeers: 0,
970
+ replicationCursors: 0,
971
+ replicationCursorsV2: 0,
972
+ syncChannelProgress: 0,
973
+ identityDevices: 0
974
+ };
975
+ }
976
+ function H(e, t) {
977
+ return e.transaction(() => t.reason === "policy" ? Nt(e, t.localDeviceId, t.pairings) : Pt(e, t)).immediate();
978
+ }
979
+ //#endregion
980
+ //#region src/device-retirement.ts
981
+ var It = /* @__PURE__ */ new Set(["fingerprint_conflict", "fingerprint_invalid"]);
982
+ function Lt(e, t) {
983
+ let n = e.prepare("SELECT device_id, public_key, fingerprint FROM sync_device").all(), [r] = n;
984
+ return n.length !== 1 || !r || r.device_id !== t || !r.public_key || r.fingerprint !== s(r.public_key) ? null : C(r.public_key);
985
+ }
986
+ function Rt(e, t) {
987
+ let n = A(e, {
988
+ localDeviceId: t.localDeviceId,
989
+ coordinator: {
990
+ availability: "available",
991
+ safeErrorCode: null,
992
+ enrollments: t.enrollments
993
+ }
994
+ }, { limit: 2e3 });
995
+ return n.truncated ? "device_evidence_incomplete" : n.items.find((e) => e.evidenceDeviceIds.includes(t.deviceId)) ?? "device_not_enrolled";
996
+ }
997
+ function zt(e) {
998
+ return e.isLocal ? "cannot_retire_this_device" : e.state === "retired" ? "device_already_retired" : e.conflictCodes.some((e) => It.has(e)) || !e.validatedFingerprint ? "device_enrollment_conflict" : null;
999
+ }
1000
+ function Bt(e) {
1001
+ return e.prepare("SELECT peer_device_id, public_key, pinned_fingerprint FROM sync_peers WHERE public_key IS NOT NULL").all().map((e) => ({
1002
+ deviceId: e.peer_device_id,
1003
+ publicKey: e.public_key,
1004
+ fingerprint: e.pinned_fingerprint?.trim() || null
1005
+ }));
1006
+ }
1007
+ function Vt(e, t, n, r) {
1008
+ return [...t.enrollments.map((e) => ({
1009
+ deviceId: e.device_id,
1010
+ publicKey: e.public_key
1011
+ })), ...Bt(e)].filter((e) => !n.has(e.deviceId)).some((e) => C(e.publicKey) === r);
1012
+ }
1013
+ function Ht(e, t) {
1014
+ let n = w(e), r = new Map(Bt(e).map((e) => [e.deviceId, e]));
1015
+ return t.some((e) => T(n.get(e), r.get(e) ?? null));
1016
+ }
1017
+ function Ut(e, t, n) {
1018
+ return e.enrollments.filter((e) => t.evidenceDeviceIds.includes(e.device_id) && e.fingerprint === n).toSorted((e, t) => e.group_id.localeCompare(t.group_id) || e.device_id.localeCompare(t.device_id))[0];
1019
+ }
1020
+ function Wt(e, t) {
1021
+ let n = Lt(e, t.localDeviceId);
1022
+ if (!n) return "local_identity_unverified";
1023
+ if (t.deviceId === t.localDeviceId) return "cannot_retire_this_device";
1024
+ let r = Rt(e, t);
1025
+ if (typeof r == "string") return r;
1026
+ let i = zt(r);
1027
+ if (i) return i;
1028
+ if (Ht(e, r.evidenceDeviceIds)) return "device_already_retired";
1029
+ let a = r.validatedFingerprint, o = Ut(t, r, a);
1030
+ if (!o) return "device_not_enrolled";
1031
+ let s = C(o.public_key);
1032
+ return s ? s === n ? "cannot_retire_this_device" : Vt(e, t, new Set(r.evidenceDeviceIds), s) ? "device_enrollment_conflict" : {
1033
+ aliasDeviceIds: r.evidenceDeviceIds.filter((e) => e !== t.localDeviceId),
1034
+ displayName: r.displayName,
1035
+ fingerprint: a,
1036
+ keyId: s,
1037
+ groupId: o.group_id,
1038
+ enrollmentDeviceId: o.device_id
1039
+ } : "device_key_unrecognized";
1040
+ }
1041
+ function Gt(e, t, n) {
1042
+ let r = n.filter((e) => e !== t);
1043
+ return r.length === 0 ? 0 : H(e, {
1044
+ localDeviceId: t,
1045
+ reason: "revoked",
1046
+ deviceIds: r
1047
+ }).syncPeers;
1048
+ }
1049
+ function Kt(e, t, n) {
1050
+ let r = e.prepare("SELECT public_key, pinned_fingerprint FROM sync_peers WHERE peer_device_id = ?").get(t);
1051
+ return !r || T({
1052
+ kind: "key",
1053
+ fingerprint: n.fingerprint,
1054
+ keyId: n.keyId
1055
+ }, {
1056
+ publicKey: r.public_key,
1057
+ fingerprint: r.pinned_fingerprint
1058
+ });
1059
+ }
1060
+ function qt(e, t, n) {
1061
+ return e.transaction(() => {
1062
+ let r = n.aliasDeviceIds.filter((r) => r !== t && (r === n.enrollmentDeviceId || Kt(e, r, n)));
1063
+ return H(e, {
1064
+ localDeviceId: t,
1065
+ reason: "revoked",
1066
+ deviceIds: r,
1067
+ retiredAliases: r.map((e) => ({
1068
+ deviceId: e,
1069
+ kind: e === n.enrollmentDeviceId ? "device_id" : "key",
1070
+ fingerprint: n.fingerprint,
1071
+ keyId: n.keyId
1072
+ }))
1073
+ }).syncPeers;
1074
+ }).immediate();
1075
+ }
1076
+ //#endregion
1077
+ //#region src/coordinator-runtime.ts
1078
+ function U(e) {
1079
+ return typeof e == "string" ? e.trim() : "";
1080
+ }
1081
+ function Jt(e, t) {
1082
+ let n = [], r = /* @__PURE__ */ new Set();
1083
+ for (let i of [...e, ...t]) {
1084
+ let e = i.trim();
1085
+ !e || r.has(e) || (r.add(e), n.push(e));
1086
+ }
1087
+ return n;
1088
+ }
1089
+ function Yt(e, t) {
1090
+ let n = Date.parse(U(e)), r = Date.parse(U(t));
1091
+ return Number.isFinite(n) ? Number.isFinite(r) && r < n ? t : e : Number.isFinite(r) ? t : e;
1092
+ }
1093
+ var W = /* @__PURE__ */ new Map(), G = /* @__PURE__ */ new Map(), K = /* @__PURE__ */ new Map(), Xt = 3e4;
1094
+ function Zt(e, t) {
1095
+ let n = e + Xt;
1096
+ for (let r of t) {
1097
+ if (r.stale) continue;
1098
+ let t = Date.parse(U(r.expires_at));
1099
+ if (Number.isFinite(t)) {
1100
+ if (t <= e) return e;
1101
+ n = Math.min(n, t);
1102
+ }
1103
+ }
1104
+ return n;
1105
+ }
1106
+ function q(e) {
1107
+ G.delete(e), K.set(e, (K.get(e) ?? 0) + 1);
1108
+ }
1109
+ function Qt(e, t) {
1110
+ let n = [...t.syncCoordinatorGroups].sort().join(",");
1111
+ return [
1112
+ e.dbPath,
1113
+ t.syncCoordinatorUrl,
1114
+ n,
1115
+ $t(e),
1116
+ t.syncHost,
1117
+ t.syncPort,
1118
+ t.syncAdvertise,
1119
+ t.syncCoordinatorPresenceTtlS
1120
+ ].join("|");
1121
+ }
1122
+ function $t(e) {
1123
+ let t = process.env.CODEMEM_KEYS_DIR?.trim() || "";
1124
+ try {
1125
+ let n = e.db.prepare("SELECT device_id, fingerprint FROM sync_device LIMIT 1").get();
1126
+ return `${t}|${n?.device_id ?? ""}|${n?.fingerprint ?? ""}`;
1127
+ } catch {
1128
+ return t;
1129
+ }
1130
+ }
1131
+ function J(e, t) {
1132
+ return [
1133
+ Qt(e, t),
1134
+ t.syncEnabled ? "sync-enabled" : "sync-disabled",
1135
+ t.syncHost,
1136
+ t.syncPort,
1137
+ t.syncAdvertise,
1138
+ t.syncCoordinatorPresenceTtlS
1139
+ ].join("|");
1140
+ }
1141
+ function Y(e) {
1142
+ return Number(e.db.prepare("SELECT COUNT(1) AS total FROM sync_peers").get()?.total ?? 0);
1143
+ }
1144
+ function en(e) {
1145
+ let t = Math.max(1, e.syncCoordinatorPresenceTtlS), n = Math.floor(t / 2);
1146
+ return Math.max(5, Math.min(60, n > 0 ? n : 1)) * 1e3;
1147
+ }
1148
+ function tn() {
1149
+ return 3e4;
1150
+ }
1151
+ async function nn(e, t, n, r) {
1152
+ let i = Qt(e, t), a = W.get(i);
1153
+ if (a && r < a.nextRefreshAtMs) {
1154
+ n.presence_status = a.status, n.presence_error = a.error, n.advertised_addresses = a.advertisedAddresses;
1155
+ return;
1156
+ }
1157
+ try {
1158
+ let a = (await an(e, t))?.responses?.[0], o = a && typeof a == "object" ? a.addresses ?? [] : [];
1159
+ n.presence_status = "posted", n.presence_error = null, n.advertised_addresses = o, W.set(i, {
1160
+ status: "posted",
1161
+ error: null,
1162
+ advertisedAddresses: o,
1163
+ nextRefreshAtMs: r + en(t)
1164
+ });
1165
+ } catch (e) {
1166
+ let t = e instanceof Error ? e.message : String(e), a = t.includes("unknown_device") ? "not_enrolled" : "error", o = a === "not_enrolled" ? r : r + tn();
1167
+ n.presence_status = a, n.presence_error = t, n.advertised_addresses = [], W.set(i, {
1168
+ status: a,
1169
+ error: t,
1170
+ advertisedAddresses: [],
1171
+ nextRefreshAtMs: o
1172
+ });
1173
+ }
1174
+ }
1175
+ function rn(e) {
1176
+ let t = e.syncAdvertise.toLowerCase();
1177
+ if (t && t !== "auto" && t !== "default") return v([], t.split(",").map((e) => e.trim()).filter(Boolean), { defaultHttpPort: e.syncPort });
1178
+ if (e.syncHost && e.syncHost !== "0.0.0.0") return [oe(re(e.syncHost, e.syncPort))].filter(Boolean);
1179
+ let n = Object.values(ce()).flatMap((e) => e ?? []).filter((e) => !e.internal).map((e) => e.address).filter((e) => e && e !== "127.0.0.1" && e !== "::1").map((t) => oe(re(t, e.syncPort))).filter(Boolean);
1180
+ return [...new Set(n)];
1181
+ }
1182
+ async function an(e, t, n) {
1183
+ if (!_(t)) return null;
1184
+ let r = n?.keysDir ?? (process.env.CODEMEM_KEYS_DIR?.trim() || void 0), [i, o] = y(e.db, { keysDir: r }), s = ne(r);
1185
+ if (!s) throw Error("public key missing");
1186
+ let c = m(t.syncCoordinatorUrl), l = {
1187
+ fingerprint: o,
1188
+ public_key: s,
1189
+ addresses: rn(t),
1190
+ ttl_s: Math.max(1, t.syncCoordinatorPresenceTtlS),
1191
+ capabilities: {
1192
+ sync_capability: p,
1193
+ sync_features: u,
1194
+ applied_removal_seq: a(e.db)
1195
+ }
1196
+ }, d = [];
1197
+ for (let n of t.syncCoordinatorGroups) {
1198
+ let a = {
1199
+ ...l,
1200
+ group_id: n
1201
+ }, o = Buffer.from(JSON.stringify(a), "utf8"), s = `${c}/v1/presence`, u = h({
1202
+ deviceId: i,
1203
+ dbPath: e.dbPath,
1204
+ method: "POST",
1205
+ url: s,
1206
+ bodyBytes: o,
1207
+ keysDir: r
1208
+ }), [f, p] = await b("POST", s, {
1209
+ headers: u,
1210
+ body: a,
1211
+ bodyBytes: o,
1212
+ timeoutS: Math.max(1, t.syncCoordinatorTimeoutS)
1213
+ });
1214
+ if (f !== 200 || !p) {
1215
+ let e = typeof p?.error == "string" ? p.error : "unknown";
1216
+ throw Error(`coordinator presence failed (${f}: ${e})`);
1217
+ }
1218
+ d.push(p);
1219
+ }
1220
+ return {
1221
+ groups: t.syncCoordinatorGroups,
1222
+ responses: d
1223
+ };
1224
+ }
1225
+ async function X(e, t, n) {
1226
+ if (!_(t)) return [];
1227
+ let r = n?.keysDir ?? (process.env.CODEMEM_KEYS_DIR?.trim() || void 0), [i] = y(e.db, { keysDir: r }), a = m(t.syncCoordinatorUrl), o = /* @__PURE__ */ new Map();
1228
+ for (let n of t.syncCoordinatorGroups) {
1229
+ let s = `${a}/v1/peers?group_id=${encodeURIComponent(n)}`, c = h({
1230
+ deviceId: i,
1231
+ dbPath: e.dbPath,
1232
+ method: "GET",
1233
+ url: s,
1234
+ bodyBytes: Buffer.alloc(0),
1235
+ keysDir: r
1236
+ }), [l, u] = await b("GET", s, {
1237
+ headers: c,
1238
+ timeoutS: Math.max(1, t.syncCoordinatorTimeoutS)
1239
+ });
1240
+ if (l !== 200 || !u) {
1241
+ let e = typeof u?.error == "string" ? u.error : "unknown";
1242
+ throw Error(`coordinator lookup failed (${l}: ${e})`);
1243
+ }
1244
+ let d = Array.isArray(u.items) ? u.items : [];
1245
+ for (let e of d) {
1246
+ if (!e || typeof e != "object") continue;
1247
+ let t = e, r = U(t.device_id), i = U(t.fingerprint);
1248
+ if (!r) continue;
1249
+ let s = t.stale ? [] : Array.isArray(t.addresses) ? t.addresses.filter((e) => typeof e == "string") : [], c = `${r}:${i}`, l = o.get(c);
1250
+ if (!l) {
1251
+ o.set(c, {
1252
+ ...t,
1253
+ addresses: v([], s),
1254
+ coordinator_id: a,
1255
+ groups: [n],
1256
+ fresh_groups: t.stale ? [] : [n]
1257
+ });
1258
+ continue;
1259
+ }
1260
+ on(l, t, n, s);
1261
+ }
1262
+ }
1263
+ return [...o.values()];
1264
+ }
1265
+ function on(e, t, n, r) {
1266
+ e.addresses = v(Z(e.addresses), r), e.groups = Jt(Z(e.groups), [n]);
1267
+ let i = !!e.stale, a = !!t.stale;
1268
+ e.fresh_groups = Jt(Z(e.fresh_groups), a ? [] : [n]), e.stale = i && a;
1269
+ let o = U(t.last_seen_at) > U(e.last_seen_at) || i && !a;
1270
+ o && (!a || i) && (e.last_seen_at = t.last_seen_at), a ? i && o && (e.expires_at = t.expires_at) : e.expires_at = i ? t.expires_at : Yt(e.expires_at, t.expires_at);
1271
+ }
1272
+ function Z(e) {
1273
+ return Array.isArray(e) ? e.filter((e) => typeof e == "string" && e.trim().length > 0) : [];
1274
+ }
1275
+ function sn(e) {
1276
+ if (!Array.isArray(e) || e.length === 0) return null;
1277
+ let t = [];
1278
+ for (let n of e) {
1279
+ if (typeof n != "string" || !n.trim()) return null;
1280
+ t.push(n.trim());
1281
+ }
1282
+ return t;
1283
+ }
1284
+ function cn(e) {
1285
+ if (typeof e != "string" || e.trim().length === 0) return [];
1286
+ try {
1287
+ return Z(JSON.parse(e));
1288
+ } catch {
1289
+ return [];
1290
+ }
1291
+ }
1292
+ function ln(e, t, n) {
1293
+ let r = U(e.peer_device_id), i = U(e.pinned_fingerprint);
1294
+ if (!r || !i) return !1;
1295
+ let a = t.get(`${r}:${i}`);
1296
+ if (!a?.length) return !1;
1297
+ let o = v(cn(e.addresses_json), []), s = e.manual_addresses_json == null ? o : cn(e.manual_addresses_json), c = ae(o, a, s, { successfulAddress: e.last_success_address ?? void 0 });
1298
+ return JSON.stringify(c) === JSON.stringify(o) && e.manual_addresses_json != null ? !1 : (n(JSON.stringify(c), JSON.stringify(s), r, i), !0);
1299
+ }
1300
+ function Q(e, t) {
1301
+ let n = /* @__PURE__ */ new Map();
1302
+ for (let e of t) {
1303
+ if (e.stale) continue;
1304
+ let t = U(e.device_id), r = U(e.fingerprint);
1305
+ if (!t || !r) continue;
1306
+ let i = Z(e.addresses);
1307
+ if (i.length === 0) continue;
1308
+ let a = `${t}:${r}`;
1309
+ n.set(a, v(n.get(a) ?? [], i));
1310
+ }
1311
+ if (n.size === 0) return 0;
1312
+ let r = e.prepare("SELECT peer_device_id, pinned_fingerprint, addresses_json, manual_addresses_json, last_success_address FROM sync_peers").all(), i = e.prepare("UPDATE sync_peers SET addresses_json = ?, manual_addresses_json = ? WHERE peer_device_id = ? AND pinned_fingerprint = ?"), a = (e, t, n, r) => {
1313
+ i.run(e, t, n, r);
1314
+ }, o = 0;
1315
+ return e.transaction(() => {
1316
+ for (let e of r) ln(e, n, a) && (o += 1);
1317
+ }).immediate(), o;
1318
+ }
1319
+ function un(e, t) {
1320
+ let { localDeviceId: r, peerDeviceId: i, coordinatorId: a, peerGroupIds: o, peerPublicKey: s } = t, c = t.kinds?.length ? t.kinds : ["managed_project"], l = e.prepare("SELECT public_key FROM sync_device WHERE device_id = ?").pluck().get(r), u = e.prepare(`SELECT scope.scope_id, scope.coordinator_id, scope.group_id
1321
+ FROM scope_memberships local_member
1322
+ JOIN scope_memberships peer_member
1323
+ ON peer_member.scope_id = local_member.scope_id
1324
+ JOIN replication_scopes scope
1325
+ ON scope.scope_id = local_member.scope_id
1326
+ WHERE local_member.device_id = ?
1327
+ AND peer_member.device_id = ?
1328
+ AND scope.status = 'active'
1329
+ AND scope.kind IN (${c.map(() => "?").join(", ")})
1330
+ AND scope.authority_type = 'coordinator'
1331
+ ORDER BY scope.scope_id`).all(r, i, ...c), d = [], f = !1;
1332
+ for (let t of u) {
1333
+ let c = U(t.scope_id), u = U(t.group_id);
1334
+ if (!c || U(t.coordinator_id) !== a || !u || o !== null && !o.includes(u)) continue;
1335
+ let p = {
1336
+ coordinatorId: a,
1337
+ groupId: u
1338
+ }, m = n(e, {
1339
+ deviceId: r,
1340
+ scopeId: c,
1341
+ authority: p,
1342
+ expectedPublicKey: l ?? ""
1343
+ }), h = n(e, {
1344
+ deviceId: i,
1345
+ scopeId: c,
1346
+ authority: p,
1347
+ expectedPublicKey: s
1348
+ });
1349
+ if (!(!m.authorized || !h.authorized)) {
1350
+ if (m.freshness !== "fresh" || h.freshness !== "fresh") {
1351
+ f = !0;
1352
+ continue;
1353
+ }
1354
+ d.push({
1355
+ scopeId: c,
1356
+ groupId: u
1357
+ });
1358
+ }
1359
+ }
1360
+ return {
1361
+ scopes: d,
1362
+ indeterminate: f
1363
+ };
1364
+ }
1365
+ function $(e, t, n, r, i, a) {
1366
+ let { scopes: o, indeterminate: s } = un(e, {
1367
+ localDeviceId: t,
1368
+ peerDeviceId: n,
1369
+ coordinatorId: r,
1370
+ peerGroupIds: i,
1371
+ peerPublicKey: a
1372
+ }), [c] = o;
1373
+ return c ? {
1374
+ state: "authorized",
1375
+ groupId: c.groupId
1376
+ } : { state: s ? "indeterminate" : "not_authorized" };
1377
+ }
1378
+ function dn(e, t, n, r, i) {
1379
+ let a = n.stale ? [] : Z(n.addresses);
1380
+ ie(e, t, a, {
1381
+ name: U(n.display_name) || void 0,
1382
+ pinnedFingerprint: r,
1383
+ publicKey: i,
1384
+ coordinatorCandidates: !0
1385
+ });
1386
+ }
1387
+ function fn(e, t, n) {
1388
+ let r = 0;
1389
+ for (let i of n) {
1390
+ let n = U(i.device_id), a = U(i.public_key), o = U(i.fingerprint), s = U(i.coordinator_id), c = sn(i.groups);
1391
+ if (!n || n === t || !a || !o || !s || !c || !pn(a, o)) continue;
1392
+ let l = $(e, t, n, s, c, a);
1393
+ if (l.state !== "authorized") continue;
1394
+ let u = e.prepare("SELECT pinned_fingerprint, public_key, claimed_local_actor, actor_id,\n pending_bootstrap_grant_id, trust_provenance\n FROM sync_peers WHERE peer_device_id = ? LIMIT 1").get(n);
1395
+ if (u && (u.claimed_local_actor === 1 || U(u.pinned_fingerprint) && U(u.pinned_fingerprint) !== o || U(u.public_key) && U(u.public_key) !== a)) continue;
1396
+ let d = !!(U(u?.pinned_fingerprint) || U(u?.public_key)), f = !u || u.claimed_local_actor === 0 && u.actor_id == null && u.pending_bootstrap_grant_id == null && (!d || u.trust_provenance === "coordinator_policy");
1397
+ dn(e, n, i, o, a), f && e.prepare("UPDATE sync_peers SET discovered_via_coordinator_id = ?,\n discovered_via_group_id = ?, trust_provenance = 'coordinator_policy'\n WHERE peer_device_id = ?\n AND claimed_local_actor = 0 AND actor_id IS NULL\n AND pending_bootstrap_grant_id IS NULL").run(s, l.groupId, n), r += 1;
1398
+ }
1399
+ return r;
1400
+ }
1401
+ function pn(e, t) {
1402
+ try {
1403
+ return s(e) === t;
1404
+ } catch {
1405
+ return !1;
1406
+ }
1407
+ }
1408
+ function mn(e, t) {
1409
+ let n = e.prepare("SELECT peer_device_id, public_key, discovered_via_coordinator_id, discovered_via_group_id\n FROM sync_peers\n WHERE claimed_local_actor = 0\n AND actor_id IS NULL\n AND pending_bootstrap_grant_id IS NULL\n AND trust_provenance = 'coordinator_policy'\n AND discovered_via_coordinator_id IS NOT NULL\n AND discovered_via_group_id IS NOT NULL\n AND (pinned_fingerprint IS NOT NULL OR public_key IS NOT NULL)").all(), r = 0;
1410
+ for (let i of n) {
1411
+ let n = U(i.peer_device_id), a = U(i.discovered_via_coordinator_id), o = U(i.discovered_via_group_id);
1412
+ !n || !a || !o || $(e, t, n, a, null, U(i.public_key)).state === "not_authorized" && (r += H(e, {
1413
+ localDeviceId: t,
1414
+ reason: "policy",
1415
+ pairings: [{
1416
+ deviceId: n,
1417
+ coordinatorId: a,
1418
+ groupId: o
1419
+ }]
1420
+ }).syncPeers);
1421
+ }
1422
+ return r;
1423
+ }
1424
+ function hn(e, t, n) {
1425
+ return e.prepare("SELECT public_key, pinned_fingerprint FROM sync_peers\n WHERE peer_device_id = ? AND discovered_via_coordinator_id = ?\n AND trust_provenance = 'coordinator_policy'\n AND claimed_local_actor = 0 AND actor_id IS NULL\n AND pending_bootstrap_grant_id IS NULL").get(t, n);
1426
+ }
1427
+ function gn(e, t, n) {
1428
+ let r = U(n.device_id), i = U(n.coordinator_id), a = U(n.public_key), o = U(n.fingerprint), s = sn(n.groups);
1429
+ if (!r || r === t || !i || !s || !pn(a, o)) return null;
1430
+ let c = hn(e, r, i);
1431
+ if (!c?.public_key || !c.pinned_fingerprint || !pn(c.public_key, c.pinned_fingerprint)) return null;
1432
+ let l = $(e, t, r, i, s, a);
1433
+ return l.state !== "authorized" || $(e, t, r, i, null, c.public_key).state !== "not_authorized" ? null : {
1434
+ peerDeviceId: r,
1435
+ coordinatorId: i,
1436
+ groupId: l.groupId,
1437
+ publicKey: a,
1438
+ fingerprint: o,
1439
+ previousPublicKey: c.public_key,
1440
+ previousFingerprint: c.pinned_fingerprint
1441
+ };
1442
+ }
1443
+ function _n(e, t, n) {
1444
+ V(e, {
1445
+ localDeviceId: t,
1446
+ peerDeviceId: n.peerDeviceId
1447
+ }), e.prepare("UPDATE sync_peers SET public_key = ?, pinned_fingerprint = ?, discovered_via_group_id = ?\n WHERE peer_device_id = ? AND discovered_via_coordinator_id = ?\n AND public_key = ? AND pinned_fingerprint = ?\n AND trust_provenance = 'coordinator_policy'\n AND claimed_local_actor = 0 AND actor_id IS NULL\n AND pending_bootstrap_grant_id IS NULL").run(n.publicKey, n.fingerprint, n.groupId, n.peerDeviceId, n.coordinatorId, n.previousPublicKey, n.previousFingerprint);
1448
+ }
1449
+ function vn(e, t, n) {
1450
+ return e.transaction(() => {
1451
+ let r = /* @__PURE__ */ new Set();
1452
+ for (let i of n) {
1453
+ let n = gn(e, t, i);
1454
+ n && (_n(e, t, n), yn(e, n, i), r.add(n.peerDeviceId));
1455
+ }
1456
+ mn(e, t);
1457
+ let i = n.filter((e) => !r.has(U(e.device_id)));
1458
+ return r.size + fn(e, t, i);
1459
+ }).immediate();
1460
+ }
1461
+ function yn(e, t, n) {
1462
+ n.stale || ln(e.prepare("SELECT peer_device_id, pinned_fingerprint, addresses_json, manual_addresses_json,\n last_success_address FROM sync_peers WHERE peer_device_id = ?").get(t.peerDeviceId), /* @__PURE__ */ new Map([[`${t.peerDeviceId}:${t.fingerprint}`, Z(n.addresses)]]), (t, n, r, i) => {
1463
+ e.prepare("UPDATE sync_peers SET addresses_json = ?,\n manual_addresses_json = COALESCE(manual_addresses_json, ?)\n WHERE peer_device_id = ? AND pinned_fingerprint = ?").run(t, n, r, i);
1464
+ });
1465
+ }
1466
+ async function bn(e, t, n) {
1467
+ if (!_(t)) return {
1468
+ peers: [],
1469
+ trusted: 0
1470
+ };
1471
+ let r = n?.keysDir ?? (process.env.CODEMEM_KEYS_DIR?.trim() || void 0), [i] = y(e.db, { keysDir: r }), a = await X(e, t, { keysDir: r });
1472
+ return Q(e.db, a), {
1473
+ peers: a,
1474
+ trusted: vn(e.db, i, a)
1475
+ };
1476
+ }
1477
+ function xn(e, t, n) {
1478
+ if (n.status === "checked") {
1479
+ wt(e, t);
1480
+ return;
1481
+ }
1482
+ Ct(e, {
1483
+ coordinatorId: t,
1484
+ groupIds: n.removedFromGroups
1485
+ });
1486
+ }
1487
+ async function Sn(e, t, n) {
1488
+ if (!_(t)) return {
1489
+ revoked: 0,
1490
+ removed: 0,
1491
+ enrolled: [],
1492
+ status: "unsupported"
1493
+ };
1494
+ let a = n?.keysDir ?? (process.env.CODEMEM_KEYS_DIR?.trim() || void 0), [o] = y(e.db, { keysDir: a }), s = await bt(e, t, {
1495
+ localDeviceId: o,
1496
+ keysDir: a
1497
+ }), c = e.db, l = m(t.syncCoordinatorUrl);
1498
+ return s.status === "checked" ? c.transaction(() => {
1499
+ let e = s.generation;
1500
+ if (e === null || r(c)?.generation !== e) return {
1501
+ revoked: 0,
1502
+ removed: 0,
1503
+ enrolled: [],
1504
+ status: "failed"
1505
+ };
1506
+ xn(c, l, s);
1507
+ let t = Gt(c, o, s.revoked), n = H(c, {
1508
+ localDeviceId: o,
1509
+ reason: "removed",
1510
+ deviceIds: s.removed.filter((e) => e !== o)
1511
+ }).syncPeers;
1512
+ return s.removalSeq !== null && i(c, {
1513
+ generation: e,
1514
+ removalSeq: s.removalSeq
1515
+ }), {
1516
+ revoked: t,
1517
+ removed: n,
1518
+ enrolled: s.enrolled,
1519
+ status: s.status
1520
+ };
1521
+ }).immediate() : (xn(c, l, s), {
1522
+ revoked: 0,
1523
+ removed: 0,
1524
+ enrolled: [],
1525
+ status: s.status
1526
+ });
1527
+ }
1528
+ async function Cn(e, t, n, r) {
1529
+ if (r?.peers) return wn(r.peers);
1530
+ let i = ee();
1531
+ if (!_(i)) return /* @__PURE__ */ new Set();
1532
+ try {
1533
+ let r = await X({
1534
+ db: e,
1535
+ dbPath: t
1536
+ }, i, { keysDir: n });
1537
+ return Q(e, r), wn(r);
1538
+ } catch {
1539
+ return /* @__PURE__ */ new Set();
1540
+ }
1541
+ }
1542
+ function wn(e) {
1543
+ let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
1544
+ for (let a of e) {
1545
+ let e = U(a.device_id);
1546
+ if (!e) continue;
1547
+ let o = U(a.fingerprint), s = o ? `${e}:${o}` : "";
1548
+ a.stale ? (n.add(e), s && i.add(s)) : (t.add(e), s && r.add(s));
1549
+ }
1550
+ for (let e of t) n.delete(e);
1551
+ for (let e of r) i.delete(e);
1552
+ return /* @__PURE__ */ new Set([...n, ...i]);
1553
+ }
1554
+ async function Tn(e, t, n) {
1555
+ if (!_(t)) return [];
1556
+ let r = process.env.CODEMEM_KEYS_DIR?.trim() || void 0, [i] = y(e.db, { keysDir: r }), a = m(t.syncCoordinatorUrl), o = /* @__PURE__ */ new Map();
1557
+ for (let s of t.syncCoordinatorGroups) {
1558
+ let c = `${a}/v1/reciprocal-approvals?${new URLSearchParams({
1559
+ group_id: s,
1560
+ direction: n.direction,
1561
+ status: n.status?.trim() || "pending"
1562
+ }).toString()}`, l = h({
1563
+ deviceId: i,
1564
+ dbPath: e.dbPath,
1565
+ method: "GET",
1566
+ url: c,
1567
+ bodyBytes: Buffer.alloc(0),
1568
+ keysDir: r
1569
+ }), [u, d] = await b("GET", c, {
1570
+ headers: l,
1571
+ timeoutS: Math.max(1, t.syncCoordinatorTimeoutS)
1572
+ });
1573
+ if (u !== 200 || !d) {
1574
+ let e = typeof d?.error == "string" ? d.error : "unknown";
1575
+ throw Error(`coordinator reciprocal approval lookup failed (${u}: ${e})`);
1576
+ }
1577
+ let f = Array.isArray(d.items) ? d.items : [];
1578
+ for (let e of f) {
1579
+ if (!e || typeof e != "object") continue;
1580
+ let t = e, n = U(t.request_id);
1581
+ n && o.set(n, t);
1582
+ }
1583
+ }
1584
+ return [...o.values()];
1585
+ }
1586
+ async function En(e, t, n) {
1587
+ if (!_(t)) throw Error("Coordinator not configured.");
1588
+ let r = n.groupId.trim(), i = n.requestedDeviceId.trim(), a = n.expectedIncomingRequestId?.trim();
1589
+ if (!r || !i) throw Error("groupId and requestedDeviceId are required.");
1590
+ if (n.expectedIncomingRequestId !== void 0 && !a) throw Error("expectedIncomingRequestId must not be empty when provided.");
1591
+ let o = process.env.CODEMEM_KEYS_DIR?.trim() || void 0, [s] = y(e.db, { keysDir: o }), c = `${m(t.syncCoordinatorUrl)}/v1/reciprocal-approvals`, u = {
1592
+ group_id: r,
1593
+ requested_device_id: i,
1594
+ ...a === void 0 ? {} : { expected_incoming_request_id: a }
1595
+ }, d = Buffer.from(JSON.stringify(u), "utf8"), f = h({
1596
+ deviceId: s,
1597
+ dbPath: e.dbPath,
1598
+ method: "POST",
1599
+ url: c,
1600
+ bodyBytes: d,
1601
+ keysDir: o
1602
+ }), [p, g] = await b("POST", c, {
1603
+ headers: f,
1604
+ body: u,
1605
+ bodyBytes: d,
1606
+ timeoutS: Math.max(1, t.syncCoordinatorTimeoutS)
1607
+ });
1608
+ if (p !== 200 || !g || !g.request || typeof g.request != "object") {
1609
+ let n = typeof g?.error == "string" ? g.error : "unknown";
1610
+ throw p === 409 && n === "reciprocal_approval_request_changed" ? (q(J(e, t)), new l()) : Error(`coordinator reciprocal approval create failed (${p}: ${n})`);
1611
+ }
1612
+ return q(J(e, t)), g.request;
1613
+ }
1614
+ function Dn(e, t) {
1615
+ let n = /* @__PURE__ */ new Map();
1616
+ for (let r of e) {
1617
+ let e = U(r[t]);
1618
+ e && n.set(e, r);
1619
+ }
1620
+ return n;
1621
+ }
1622
+ async function On(e, t) {
1623
+ let n = Y(e);
1624
+ if (!_(t)) return {
1625
+ enabled: !1,
1626
+ configured: !1,
1627
+ sync_enabled: t.syncEnabled,
1628
+ coordinator_url: t.syncCoordinatorUrl || null,
1629
+ groups: t.syncCoordinatorGroups,
1630
+ paired_peer_count: n
1631
+ };
1632
+ let r = process.env.CODEMEM_KEYS_DIR?.trim() || void 0, [i] = y(e.db, { keysDir: r }), a = J(e, t), o = K.get(a) ?? 0, s = Date.now(), c = G.get(a);
1633
+ if (c && s < c.nextRefreshAtMs) {
1634
+ let n = structuredClone(c.snapshot);
1635
+ if (await nn(e, t, n, s), s = Date.now(), n.presence_status === "not_enrolled") return q(a), n.fresh_peer_count = 0, n.stale_peer_count = 0, n.discovered_peer_count = 0, n.discovered_devices = [], n.reciprocal_approvals = {
1636
+ incoming: [],
1637
+ outgoing: []
1638
+ }, {
1639
+ ...n,
1640
+ paired_peer_count: Y(e)
1641
+ };
1642
+ if (s < c.nextRefreshAtMs) return vn(e.db, i, c.discoveredPeers), {
1643
+ ...n,
1644
+ paired_peer_count: Y(e)
1645
+ };
1646
+ }
1647
+ let l = {
1648
+ enabled: !0,
1649
+ configured: !0,
1650
+ sync_enabled: t.syncEnabled,
1651
+ coordinator_url: t.syncCoordinatorUrl,
1652
+ groups: t.syncCoordinatorGroups,
1653
+ paired_peer_count: n,
1654
+ presence_status: "unknown",
1655
+ presence_error: null,
1656
+ advertised_addresses: [],
1657
+ fresh_peer_count: 0,
1658
+ stale_peer_count: 0,
1659
+ discovered_peer_count: 0,
1660
+ discovered_devices: []
1661
+ };
1662
+ await nn(e, t, l, s);
1663
+ let u = [];
1664
+ try {
1665
+ let { peers: n } = await bn(e, t, { keysDir: r });
1666
+ u = structuredClone(n);
1667
+ let i = [], a = [];
1668
+ try {
1669
+ i = await Tn(e, t, { direction: "incoming" }), a = await Tn(e, t, { direction: "outgoing" });
1670
+ } catch (e) {
1671
+ l.reciprocal_approval_error = e instanceof Error ? e.message : String(e);
1672
+ }
1673
+ let o = Dn(i, "requesting_device_id"), s = Dn(a, "requested_device_id");
1674
+ l.discovered_peer_count = n.length, l.fresh_peer_count = n.filter((e) => !e.stale).length, l.stale_peer_count = n.filter((e) => !!e.stale).length, l.reciprocal_approvals = {
1675
+ incoming: i,
1676
+ outgoing: a
1677
+ }, l.discovered_devices = n.map((e) => kn(e, o, s));
1678
+ } catch (e) {
1679
+ l.lookup_error = e instanceof Error ? e.message : String(e);
1680
+ }
1681
+ return l.presence_status !== "not_enrolled" && !l.lookup_error && !l.reciprocal_approval_error && (K.get(a) ?? 0) === o && G.set(a, {
1682
+ snapshot: structuredClone(l),
1683
+ discoveredPeers: u,
1684
+ nextRefreshAtMs: Zt(Date.now(), u)
1685
+ }), l;
1686
+ }
1687
+ function kn(e, t, n) {
1688
+ let r = t.get(U(e.device_id)), i = n.get(U(e.device_id));
1689
+ return {
1690
+ device_id: e.device_id,
1691
+ display_name: e.display_name ?? null,
1692
+ fingerprint: e.fingerprint ?? null,
1693
+ addresses: Array.isArray(e.addresses) ? e.addresses : [],
1694
+ groups: Array.isArray(e.groups) ? e.groups : [],
1695
+ last_seen_at: e.last_seen_at ?? null,
1696
+ expires_at: e.expires_at ?? null,
1697
+ stale: !!e.stale,
1698
+ needs_local_approval: !!r,
1699
+ waiting_for_peer_approval: !!i,
1700
+ incoming_reciprocal_request_id: r?.request_id ?? null,
1701
+ outgoing_reciprocal_request_id: i?.request_id ?? null
1702
+ };
1703
+ }
1704
+ async function An(e) {
1705
+ let t = e.syncCoordinatorGroup || e.syncCoordinatorGroups[0] || "";
1706
+ if (!t || !e.syncCoordinatorUrl || !e.syncCoordinatorAdminSecret) return [];
1707
+ let n = `${m(e.syncCoordinatorUrl)}/v1/admin/join-requests?group_id=${encodeURIComponent(t)}`, [r, i] = await b("GET", n, {
1708
+ headers: { "X-Codemem-Coordinator-Admin": e.syncCoordinatorAdminSecret },
1709
+ timeoutS: Math.max(1, e.syncCoordinatorTimeoutS)
1710
+ });
1711
+ return r !== 200 || !i ? [] : Array.isArray(i.items) ? i.items.filter((e) => !!e && typeof e == "object") : [];
1712
+ }
1713
+ //#endregion
1714
+ export { Ve as A, T as B, I as C, Ue as D, at as E, A as F, x as H, Be as I, Fe as L, Ge as M, ve as N, We as O, _e as P, C as R, ct as S, R as T, pe as U, me as V, H as _, Tn as a, xt as b, Q as c, un as d, fn as f, Lt as g, qt as h, An as i, M as j, j as k, an as l, Wt as m, En as n, X as o, Gt as p, Cn as r, bn as s, On as t, Sn as u, Tt as v, nt as w, Ke as x, bt as y, w as z };
1715
+
1716
+ //# sourceMappingURL=coordinator-runtime-ChgCIqfx.js.map