@xenosystem/agent-cli 0.5.190 → 0.5.191

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 (864) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/index.js +2 -2
  3. package/dist/metafile-esm.json +1 -1
  4. package/dist/sdk-build-identity.json +4 -4
  5. package/node_modules/@xeno-corporation/account/LICENSE +39 -0
  6. package/node_modules/@xeno-corporation/account/README.md +266 -0
  7. package/node_modules/@xeno-corporation/account/dist/chunk-FELZILY4.mjs +60 -0
  8. package/node_modules/@xeno-corporation/account/dist/chunk-FELZILY4.mjs.map +1 -0
  9. package/node_modules/@xeno-corporation/account/dist/client-D7OSWGkE.d.mts +2337 -0
  10. package/node_modules/@xeno-corporation/account/dist/client-D7OSWGkE.d.ts +2337 -0
  11. package/node_modules/@xeno-corporation/account/dist/index.d.mts +110 -0
  12. package/node_modules/@xeno-corporation/account/dist/index.d.ts +110 -0
  13. package/node_modules/@xeno-corporation/account/dist/index.js +4116 -0
  14. package/node_modules/@xeno-corporation/account/dist/index.js.map +1 -0
  15. package/node_modules/@xeno-corporation/account/dist/index.mjs +3968 -0
  16. package/node_modules/@xeno-corporation/account/dist/index.mjs.map +1 -0
  17. package/node_modules/@xeno-corporation/account/dist/node.d.mts +109 -0
  18. package/node_modules/@xeno-corporation/account/dist/node.d.ts +109 -0
  19. package/node_modules/@xeno-corporation/account/dist/node.js +1453 -0
  20. package/node_modules/@xeno-corporation/account/dist/node.js.map +1 -0
  21. package/node_modules/@xeno-corporation/account/dist/node.mjs +1379 -0
  22. package/node_modules/@xeno-corporation/account/dist/node.mjs.map +1 -0
  23. package/node_modules/@xeno-corporation/account/package.json +62 -0
  24. package/node_modules/zod/LICENSE +21 -0
  25. package/node_modules/zod/README.md +218 -0
  26. package/node_modules/zod/compile.cjs +96 -0
  27. package/node_modules/zod/compile.d.cts +1 -0
  28. package/node_modules/zod/compile.d.ts +1 -0
  29. package/node_modules/zod/compile.js +52 -0
  30. package/node_modules/zod/index.cjs +52 -0
  31. package/node_modules/zod/index.d.cts +3 -0
  32. package/node_modules/zod/index.d.ts +3 -0
  33. package/node_modules/zod/index.js +7 -0
  34. package/node_modules/zod/locales/index.cjs +36 -0
  35. package/node_modules/zod/locales/index.d.cts +1 -0
  36. package/node_modules/zod/locales/index.d.ts +1 -0
  37. package/node_modules/zod/locales/index.js +1 -0
  38. package/node_modules/zod/locales/package.json +7 -0
  39. package/node_modules/zod/mini/index.cjs +51 -0
  40. package/node_modules/zod/mini/index.d.cts +3 -0
  41. package/node_modules/zod/mini/index.d.ts +3 -0
  42. package/node_modules/zod/mini/index.js +3 -0
  43. package/node_modules/zod/mini/package.json +7 -0
  44. package/node_modules/zod/package.json +147 -0
  45. package/node_modules/zod/src/compile.ts +56 -0
  46. package/node_modules/zod/src/index.ts +7 -0
  47. package/node_modules/zod/src/locales/index.ts +1 -0
  48. package/node_modules/zod/src/mini/index.ts +3 -0
  49. package/node_modules/zod/src/v3/ZodError.ts +340 -0
  50. package/node_modules/zod/src/v3/benchmarks/datetime.ts +58 -0
  51. package/node_modules/zod/src/v3/benchmarks/discriminatedUnion.ts +80 -0
  52. package/node_modules/zod/src/v3/benchmarks/index.ts +59 -0
  53. package/node_modules/zod/src/v3/benchmarks/ipv4.ts +57 -0
  54. package/node_modules/zod/src/v3/benchmarks/object.ts +69 -0
  55. package/node_modules/zod/src/v3/benchmarks/primitives.ts +162 -0
  56. package/node_modules/zod/src/v3/benchmarks/realworld.ts +63 -0
  57. package/node_modules/zod/src/v3/benchmarks/string.ts +55 -0
  58. package/node_modules/zod/src/v3/benchmarks/union.ts +80 -0
  59. package/node_modules/zod/src/v3/errors.ts +13 -0
  60. package/node_modules/zod/src/v3/external.ts +6 -0
  61. package/node_modules/zod/src/v3/helpers/enumUtil.ts +17 -0
  62. package/node_modules/zod/src/v3/helpers/errorUtil.ts +8 -0
  63. package/node_modules/zod/src/v3/helpers/parseUtil.ts +176 -0
  64. package/node_modules/zod/src/v3/helpers/partialUtil.ts +34 -0
  65. package/node_modules/zod/src/v3/helpers/typeAliases.ts +2 -0
  66. package/node_modules/zod/src/v3/helpers/util.ts +224 -0
  67. package/node_modules/zod/src/v3/index.ts +4 -0
  68. package/node_modules/zod/src/v3/locales/en.ts +124 -0
  69. package/node_modules/zod/src/v3/standard-schema.ts +113 -0
  70. package/node_modules/zod/src/v3/tests/Mocker.ts +54 -0
  71. package/node_modules/zod/src/v3/tests/all-errors.test.ts +157 -0
  72. package/node_modules/zod/src/v3/tests/anyunknown.test.ts +28 -0
  73. package/node_modules/zod/src/v3/tests/array.test.ts +71 -0
  74. package/node_modules/zod/src/v3/tests/async-parsing.test.ts +388 -0
  75. package/node_modules/zod/src/v3/tests/async-refinements.test.ts +46 -0
  76. package/node_modules/zod/src/v3/tests/base.test.ts +29 -0
  77. package/node_modules/zod/src/v3/tests/bigint.test.ts +55 -0
  78. package/node_modules/zod/src/v3/tests/branded.test.ts +53 -0
  79. package/node_modules/zod/src/v3/tests/catch.test.ts +220 -0
  80. package/node_modules/zod/src/v3/tests/coerce.test.ts +133 -0
  81. package/node_modules/zod/src/v3/tests/complex.test.ts +70 -0
  82. package/node_modules/zod/src/v3/tests/custom.test.ts +31 -0
  83. package/node_modules/zod/src/v3/tests/date.test.ts +32 -0
  84. package/node_modules/zod/src/v3/tests/deepmasking.test.ts +186 -0
  85. package/node_modules/zod/src/v3/tests/default.test.ts +112 -0
  86. package/node_modules/zod/src/v3/tests/description.test.ts +33 -0
  87. package/node_modules/zod/src/v3/tests/discriminated-unions.test.ts +315 -0
  88. package/node_modules/zod/src/v3/tests/enum.test.ts +80 -0
  89. package/node_modules/zod/src/v3/tests/error.test.ts +586 -0
  90. package/node_modules/zod/src/v3/tests/firstparty.test.ts +87 -0
  91. package/node_modules/zod/src/v3/tests/firstpartyschematypes.test.ts +21 -0
  92. package/node_modules/zod/src/v3/tests/function.test.ts +261 -0
  93. package/node_modules/zod/src/v3/tests/generics.test.ts +48 -0
  94. package/node_modules/zod/src/v3/tests/instanceof.test.ts +37 -0
  95. package/node_modules/zod/src/v3/tests/intersection.test.ts +128 -0
  96. package/node_modules/zod/src/v3/tests/language-server.source.ts +76 -0
  97. package/node_modules/zod/src/v3/tests/language-server.test.ts +206 -0
  98. package/node_modules/zod/src/v3/tests/literal.test.ts +36 -0
  99. package/node_modules/zod/src/v3/tests/map.test.ts +110 -0
  100. package/node_modules/zod/src/v3/tests/masking.test.ts +4 -0
  101. package/node_modules/zod/src/v3/tests/mocker.test.ts +19 -0
  102. package/node_modules/zod/src/v3/tests/nan.test.ts +24 -0
  103. package/node_modules/zod/src/v3/tests/nativeEnum.test.ts +87 -0
  104. package/node_modules/zod/src/v3/tests/nullable.test.ts +42 -0
  105. package/node_modules/zod/src/v3/tests/number.test.ts +176 -0
  106. package/node_modules/zod/src/v3/tests/object-augmentation.test.ts +29 -0
  107. package/node_modules/zod/src/v3/tests/object-in-es5-env.test.ts +29 -0
  108. package/node_modules/zod/src/v3/tests/object.test.ts +431 -0
  109. package/node_modules/zod/src/v3/tests/optional.test.ts +42 -0
  110. package/node_modules/zod/src/v3/tests/parseUtil.test.ts +23 -0
  111. package/node_modules/zod/src/v3/tests/parser.test.ts +41 -0
  112. package/node_modules/zod/src/v3/tests/partials.test.ts +243 -0
  113. package/node_modules/zod/src/v3/tests/pickomit.test.ts +111 -0
  114. package/node_modules/zod/src/v3/tests/pipeline.test.ts +29 -0
  115. package/node_modules/zod/src/v3/tests/preprocess.test.ts +186 -0
  116. package/node_modules/zod/src/v3/tests/primitive.test.ts +440 -0
  117. package/node_modules/zod/src/v3/tests/promise.test.ts +90 -0
  118. package/node_modules/zod/src/v3/tests/readonly.test.ts +114 -0
  119. package/node_modules/zod/src/v3/tests/record.test.ts +171 -0
  120. package/node_modules/zod/src/v3/tests/recursive.test.ts +197 -0
  121. package/node_modules/zod/src/v3/tests/refine.test.ts +313 -0
  122. package/node_modules/zod/src/v3/tests/safeparse.test.ts +27 -0
  123. package/node_modules/zod/src/v3/tests/set.test.ts +142 -0
  124. package/node_modules/zod/src/v3/tests/standard-schema.test.ts +83 -0
  125. package/node_modules/zod/src/v3/tests/string.test.ts +922 -0
  126. package/node_modules/zod/src/v3/tests/transformer.test.ts +233 -0
  127. package/node_modules/zod/src/v3/tests/tuple.test.ts +90 -0
  128. package/node_modules/zod/src/v3/tests/unions.test.ts +57 -0
  129. package/node_modules/zod/src/v3/tests/validations.test.ts +133 -0
  130. package/node_modules/zod/src/v3/tests/void.test.ts +15 -0
  131. package/node_modules/zod/src/v3/types.ts +5138 -0
  132. package/node_modules/zod/src/v4/classic/checks.ts +33 -0
  133. package/node_modules/zod/src/v4/classic/coerce.ts +27 -0
  134. package/node_modules/zod/src/v4/classic/compat.ts +78 -0
  135. package/node_modules/zod/src/v4/classic/deep-partial.ts +76 -0
  136. package/node_modules/zod/src/v4/classic/errors.ts +97 -0
  137. package/node_modules/zod/src/v4/classic/external.ts +57 -0
  138. package/node_modules/zod/src/v4/classic/from-json-schema.ts +944 -0
  139. package/node_modules/zod/src/v4/classic/in-out.ts +45 -0
  140. package/node_modules/zod/src/v4/classic/index.ts +5 -0
  141. package/node_modules/zod/src/v4/classic/iso.ts +20 -0
  142. package/node_modules/zod/src/v4/classic/parse.ts +88 -0
  143. package/node_modules/zod/src/v4/classic/schemas.ts +2937 -0
  144. package/node_modules/zod/src/v4/classic/tests/anyunknown.test.ts +26 -0
  145. package/node_modules/zod/src/v4/classic/tests/apply.test.ts +86 -0
  146. package/node_modules/zod/src/v4/classic/tests/array.test.ts +291 -0
  147. package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +402 -0
  148. package/node_modules/zod/src/v4/classic/tests/async-parsing.test.ts +381 -0
  149. package/node_modules/zod/src/v4/classic/tests/async-refinements.test.ts +68 -0
  150. package/node_modules/zod/src/v4/classic/tests/base.test.ts +7 -0
  151. package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +89 -0
  152. package/node_modules/zod/src/v4/classic/tests/brand.test.ts +106 -0
  153. package/node_modules/zod/src/v4/classic/tests/catch.test.ts +604 -0
  154. package/node_modules/zod/src/v4/classic/tests/coalesce.test.ts +20 -0
  155. package/node_modules/zod/src/v4/classic/tests/codec-examples.test.ts +572 -0
  156. package/node_modules/zod/src/v4/classic/tests/codec.test.ts +704 -0
  157. package/node_modules/zod/src/v4/classic/tests/coerce.test.ts +160 -0
  158. package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +374 -0
  159. package/node_modules/zod/src/v4/classic/tests/credit-card.test.ts +76 -0
  160. package/node_modules/zod/src/v4/classic/tests/custom.test.ts +40 -0
  161. package/node_modules/zod/src/v4/classic/tests/cyclic-data.test.ts +985 -0
  162. package/node_modules/zod/src/v4/classic/tests/date.test.ts +92 -0
  163. package/node_modules/zod/src/v4/classic/tests/datetime.test.ts +316 -0
  164. package/node_modules/zod/src/v4/classic/tests/deep-partial.test.ts +380 -0
  165. package/node_modules/zod/src/v4/classic/tests/default-locale.test.ts +32 -0
  166. package/node_modules/zod/src/v4/classic/tests/default.test.ts +455 -0
  167. package/node_modules/zod/src/v4/classic/tests/describe-meta-checks.test.ts +27 -0
  168. package/node_modules/zod/src/v4/classic/tests/description.test.ts +32 -0
  169. package/node_modules/zod/src/v4/classic/tests/detached-methods.test.ts +221 -0
  170. package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +942 -0
  171. package/node_modules/zod/src/v4/classic/tests/enum.test.ts +305 -0
  172. package/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +917 -0
  173. package/node_modules/zod/src/v4/classic/tests/error.test.ts +1108 -0
  174. package/node_modules/zod/src/v4/classic/tests/file.test.ts +96 -0
  175. package/node_modules/zod/src/v4/classic/tests/firstparty.test.ts +179 -0
  176. package/node_modules/zod/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
  177. package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +1467 -0
  178. package/node_modules/zod/src/v4/classic/tests/function.test.ts +391 -0
  179. package/node_modules/zod/src/v4/classic/tests/generics.test.ts +72 -0
  180. package/node_modules/zod/src/v4/classic/tests/global-config.test.ts +32 -0
  181. package/node_modules/zod/src/v4/classic/tests/hash.test.ts +67 -0
  182. package/node_modules/zod/src/v4/classic/tests/iban.test.ts +81 -0
  183. package/node_modules/zod/src/v4/classic/tests/in-out.test.ts +159 -0
  184. package/node_modules/zod/src/v4/classic/tests/index.test.ts +958 -0
  185. package/node_modules/zod/src/v4/classic/tests/instance-footprint.test.ts +319 -0
  186. package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +127 -0
  187. package/node_modules/zod/src/v4/classic/tests/intersection.test.ts +334 -0
  188. package/node_modules/zod/src/v4/classic/tests/issue-schema.test.ts +215 -0
  189. package/node_modules/zod/src/v4/classic/tests/jitless-allows-eval.test.ts +39 -0
  190. package/node_modules/zod/src/v4/classic/tests/json.test.ts +109 -0
  191. package/node_modules/zod/src/v4/classic/tests/lazy.test.ts +262 -0
  192. package/node_modules/zod/src/v4/classic/tests/literal.test.ts +128 -0
  193. package/node_modules/zod/src/v4/classic/tests/locales_ka.test.ts +29 -0
  194. package/node_modules/zod/src/v4/classic/tests/locales_ro.test.ts +24 -0
  195. package/node_modules/zod/src/v4/classic/tests/map.test.ts +349 -0
  196. package/node_modules/zod/src/v4/classic/tests/nan.test.ts +21 -0
  197. package/node_modules/zod/src/v4/classic/tests/nested-refine.test.ts +168 -0
  198. package/node_modules/zod/src/v4/classic/tests/nonoptional.test.ts +101 -0
  199. package/node_modules/zod/src/v4/classic/tests/nullable.test.ts +22 -0
  200. package/node_modules/zod/src/v4/classic/tests/number.test.ts +401 -0
  201. package/node_modules/zod/src/v4/classic/tests/object.test.ts +1006 -0
  202. package/node_modules/zod/src/v4/classic/tests/optin-ladder.test.ts +235 -0
  203. package/node_modules/zod/src/v4/classic/tests/optional.test.ts +366 -0
  204. package/node_modules/zod/src/v4/classic/tests/partial.test.ts +497 -0
  205. package/node_modules/zod/src/v4/classic/tests/pickomit.test.ts +211 -0
  206. package/node_modules/zod/src/v4/classic/tests/pipe.test.ts +101 -0
  207. package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +144 -0
  208. package/node_modules/zod/src/v4/classic/tests/preprocess-types.test.ts +44 -0
  209. package/node_modules/zod/src/v4/classic/tests/preprocess.test.ts +351 -0
  210. package/node_modules/zod/src/v4/classic/tests/primitive.test.ts +175 -0
  211. package/node_modules/zod/src/v4/classic/tests/promise.test.ts +81 -0
  212. package/node_modules/zod/src/v4/classic/tests/properties.test.ts +141 -0
  213. package/node_modules/zod/src/v4/classic/tests/prototypes.test.ts +23 -0
  214. package/node_modules/zod/src/v4/classic/tests/readonly.test.ts +184 -0
  215. package/node_modules/zod/src/v4/classic/tests/record.test.ts +885 -0
  216. package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +707 -0
  217. package/node_modules/zod/src/v4/classic/tests/redos.test.ts +68 -0
  218. package/node_modules/zod/src/v4/classic/tests/refine.test.ts +693 -0
  219. package/node_modules/zod/src/v4/classic/tests/registries.test.ts +243 -0
  220. package/node_modules/zod/src/v4/classic/tests/set.test.ts +196 -0
  221. package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +153 -0
  222. package/node_modules/zod/src/v4/classic/tests/string-formats.test.ts +125 -0
  223. package/node_modules/zod/src/v4/classic/tests/string.test.ts +1440 -0
  224. package/node_modules/zod/src/v4/classic/tests/stringbool.test.ts +124 -0
  225. package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +812 -0
  226. package/node_modules/zod/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
  227. package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +4733 -0
  228. package/node_modules/zod/src/v4/classic/tests/transform.test.ts +378 -0
  229. package/node_modules/zod/src/v4/classic/tests/tuple.test.ts +511 -0
  230. package/node_modules/zod/src/v4/classic/tests/union.test.ts +310 -0
  231. package/node_modules/zod/src/v4/classic/tests/url.test.ts +13 -0
  232. package/node_modules/zod/src/v4/classic/tests/validate.test.ts +645 -0
  233. package/node_modules/zod/src/v4/classic/tests/validations.test.ts +283 -0
  234. package/node_modules/zod/src/v4/classic/tests/void.test.ts +12 -0
  235. package/node_modules/zod/src/v4/core/api.ts +1875 -0
  236. package/node_modules/zod/src/v4/core/checks.ts +1266 -0
  237. package/node_modules/zod/src/v4/core/compile.ts +2322 -0
  238. package/node_modules/zod/src/v4/core/core.ts +230 -0
  239. package/node_modules/zod/src/v4/core/doc.ts +52 -0
  240. package/node_modules/zod/src/v4/core/errors.ts +543 -0
  241. package/node_modules/zod/src/v4/core/index.ts +19 -0
  242. package/node_modules/zod/src/v4/core/json-schema-generator.ts +131 -0
  243. package/node_modules/zod/src/v4/core/json-schema-processors.ts +934 -0
  244. package/node_modules/zod/src/v4/core/json-schema.ts +148 -0
  245. package/node_modules/zod/src/v4/core/memoizer.ts +331 -0
  246. package/node_modules/zod/src/v4/core/parse.ts +309 -0
  247. package/node_modules/zod/src/v4/core/regexes.ts +217 -0
  248. package/node_modules/zod/src/v4/core/registries.ts +105 -0
  249. package/node_modules/zod/src/v4/core/schemas.ts +5226 -0
  250. package/node_modules/zod/src/v4/core/standard-schema.ts +159 -0
  251. package/node_modules/zod/src/v4/core/tests/cached.test.ts +54 -0
  252. package/node_modules/zod/src/v4/core/tests/compile-differential.test.ts +1004 -0
  253. package/node_modules/zod/src/v4/core/tests/compile-generative.test.ts +445 -0
  254. package/node_modules/zod/src/v4/core/tests/compile-global.test.ts +89 -0
  255. package/node_modules/zod/src/v4/core/tests/compile-off-by-default.test.ts +26 -0
  256. package/node_modules/zod/src/v4/core/tests/compile-stats.test.ts +34 -0
  257. package/node_modules/zod/src/v4/core/tests/compile.test.ts +2036 -0
  258. package/node_modules/zod/src/v4/core/tests/email-regex.test.ts +140 -0
  259. package/node_modules/zod/src/v4/core/tests/extend.test.ts +59 -0
  260. package/node_modules/zod/src/v4/core/tests/index.test.ts +46 -0
  261. package/node_modules/zod/src/v4/core/tests/locales/be.test.ts +124 -0
  262. package/node_modules/zod/src/v4/core/tests/locales/el.test.ts +214 -0
  263. package/node_modules/zod/src/v4/core/tests/locales/en.test.ts +22 -0
  264. package/node_modules/zod/src/v4/core/tests/locales/es.test.ts +180 -0
  265. package/node_modules/zod/src/v4/core/tests/locales/fr.test.ts +72 -0
  266. package/node_modules/zod/src/v4/core/tests/locales/he.test.ts +379 -0
  267. package/node_modules/zod/src/v4/core/tests/locales/hr.test.ts +163 -0
  268. package/node_modules/zod/src/v4/core/tests/locales/nl.test.ts +46 -0
  269. package/node_modules/zod/src/v4/core/tests/locales/parity.test.ts +42 -0
  270. package/node_modules/zod/src/v4/core/tests/locales/ru.test.ts +128 -0
  271. package/node_modules/zod/src/v4/core/tests/locales/tg.test.ts +85 -0
  272. package/node_modules/zod/src/v4/core/tests/locales/tk.test.ts +69 -0
  273. package/node_modules/zod/src/v4/core/tests/locales/tr.test.ts +69 -0
  274. package/node_modules/zod/src/v4/core/tests/locales/uz.test.ts +105 -0
  275. package/node_modules/zod/src/v4/core/tests/polyfill-collision.test.ts +46 -0
  276. package/node_modules/zod/src/v4/core/tests/record-constructor.test.ts +125 -0
  277. package/node_modules/zod/src/v4/core/tests/recursive-tuples.test.ts +45 -0
  278. package/node_modules/zod/src/v4/core/tests/treeshake.test.ts +51 -0
  279. package/node_modules/zod/src/v4/core/tests/url-no-canparse.test.ts +133 -0
  280. package/node_modules/zod/src/v4/core/to-json-schema.ts +857 -0
  281. package/node_modules/zod/src/v4/core/util.ts +1293 -0
  282. package/node_modules/zod/src/v4/core/versions.ts +5 -0
  283. package/node_modules/zod/src/v4/core/visit.ts +193 -0
  284. package/node_modules/zod/src/v4/core/zsf.ts +323 -0
  285. package/node_modules/zod/src/v4/index.ts +4 -0
  286. package/node_modules/zod/src/v4/locales/ar.ts +120 -0
  287. package/node_modules/zod/src/v4/locales/az.ts +116 -0
  288. package/node_modules/zod/src/v4/locales/be.ts +188 -0
  289. package/node_modules/zod/src/v4/locales/bg.ts +133 -0
  290. package/node_modules/zod/src/v4/locales/bn.ts +123 -0
  291. package/node_modules/zod/src/v4/locales/ca.ts +121 -0
  292. package/node_modules/zod/src/v4/locales/ckb.ts +140 -0
  293. package/node_modules/zod/src/v4/locales/cs.ts +123 -0
  294. package/node_modules/zod/src/v4/locales/da.ts +128 -0
  295. package/node_modules/zod/src/v4/locales/de.ts +121 -0
  296. package/node_modules/zod/src/v4/locales/el.ts +124 -0
  297. package/node_modules/zod/src/v4/locales/en.ts +136 -0
  298. package/node_modules/zod/src/v4/locales/eo.ts +123 -0
  299. package/node_modules/zod/src/v4/locales/es.ts +145 -0
  300. package/node_modules/zod/src/v4/locales/fa.ts +131 -0
  301. package/node_modules/zod/src/v4/locales/fi.ts +126 -0
  302. package/node_modules/zod/src/v4/locales/fr-CA.ts +121 -0
  303. package/node_modules/zod/src/v4/locales/fr.ts +139 -0
  304. package/node_modules/zod/src/v4/locales/gu.ts +123 -0
  305. package/node_modules/zod/src/v4/locales/he.ts +253 -0
  306. package/node_modules/zod/src/v4/locales/hi.ts +126 -0
  307. package/node_modules/zod/src/v4/locales/hr.ts +135 -0
  308. package/node_modules/zod/src/v4/locales/hu.ts +122 -0
  309. package/node_modules/zod/src/v4/locales/hy.ts +175 -0
  310. package/node_modules/zod/src/v4/locales/id.ts +120 -0
  311. package/node_modules/zod/src/v4/locales/index.ts +63 -0
  312. package/node_modules/zod/src/v4/locales/is.ts +124 -0
  313. package/node_modules/zod/src/v4/locales/it.ts +121 -0
  314. package/node_modules/zod/src/v4/locales/ja.ts +119 -0
  315. package/node_modules/zod/src/v4/locales/ka.ts +128 -0
  316. package/node_modules/zod/src/v4/locales/kh.ts +7 -0
  317. package/node_modules/zod/src/v4/locales/km.ts +124 -0
  318. package/node_modules/zod/src/v4/locales/kn.ts +126 -0
  319. package/node_modules/zod/src/v4/locales/ko.ts +126 -0
  320. package/node_modules/zod/src/v4/locales/lt.ts +243 -0
  321. package/node_modules/zod/src/v4/locales/mk.ts +123 -0
  322. package/node_modules/zod/src/v4/locales/ms.ts +120 -0
  323. package/node_modules/zod/src/v4/locales/ne.ts +128 -0
  324. package/node_modules/zod/src/v4/locales/nl.ts +126 -0
  325. package/node_modules/zod/src/v4/locales/nn.ts +121 -0
  326. package/node_modules/zod/src/v4/locales/no.ts +121 -0
  327. package/node_modules/zod/src/v4/locales/ota.ts +122 -0
  328. package/node_modules/zod/src/v4/locales/pl.ts +123 -0
  329. package/node_modules/zod/src/v4/locales/ps.ts +131 -0
  330. package/node_modules/zod/src/v4/locales/pt-BR.ts +161 -0
  331. package/node_modules/zod/src/v4/locales/pt.ts +159 -0
  332. package/node_modules/zod/src/v4/locales/ro.ts +132 -0
  333. package/node_modules/zod/src/v4/locales/ru.ts +188 -0
  334. package/node_modules/zod/src/v4/locales/sk.ts +123 -0
  335. package/node_modules/zod/src/v4/locales/sl.ts +123 -0
  336. package/node_modules/zod/src/v4/locales/sv.ts +124 -0
  337. package/node_modules/zod/src/v4/locales/ta.ts +123 -0
  338. package/node_modules/zod/src/v4/locales/tg.ts +135 -0
  339. package/node_modules/zod/src/v4/locales/th.ts +124 -0
  340. package/node_modules/zod/src/v4/locales/tk.ts +113 -0
  341. package/node_modules/zod/src/v4/locales/tr.ts +116 -0
  342. package/node_modules/zod/src/v4/locales/ua.ts +7 -0
  343. package/node_modules/zod/src/v4/locales/uk.ts +122 -0
  344. package/node_modules/zod/src/v4/locales/ur.ts +124 -0
  345. package/node_modules/zod/src/v4/locales/uz.ts +120 -0
  346. package/node_modules/zod/src/v4/locales/vi.ts +122 -0
  347. package/node_modules/zod/src/v4/locales/yo.ts +129 -0
  348. package/node_modules/zod/src/v4/locales/zh-CN.ts +121 -0
  349. package/node_modules/zod/src/v4/locales/zh-TW.ts +120 -0
  350. package/node_modules/zod/src/v4/mini/checks.ts +33 -0
  351. package/node_modules/zod/src/v4/mini/coerce.ts +27 -0
  352. package/node_modules/zod/src/v4/mini/deep-partial.ts +73 -0
  353. package/node_modules/zod/src/v4/mini/external.ts +52 -0
  354. package/node_modules/zod/src/v4/mini/in-out.ts +45 -0
  355. package/node_modules/zod/src/v4/mini/index.ts +3 -0
  356. package/node_modules/zod/src/v4/mini/iso.ts +66 -0
  357. package/node_modules/zod/src/v4/mini/parse.ts +16 -0
  358. package/node_modules/zod/src/v4/mini/schemas.ts +2051 -0
  359. package/node_modules/zod/src/v4/mini/tests/apply.test.ts +57 -0
  360. package/node_modules/zod/src/v4/mini/tests/assignability.test.ts +190 -0
  361. package/node_modules/zod/src/v4/mini/tests/brand.test.ts +94 -0
  362. package/node_modules/zod/src/v4/mini/tests/checks.test.ts +158 -0
  363. package/node_modules/zod/src/v4/mini/tests/codec.test.ts +582 -0
  364. package/node_modules/zod/src/v4/mini/tests/computed.test.ts +30 -0
  365. package/node_modules/zod/src/v4/mini/tests/cyclic-data.test.ts +84 -0
  366. package/node_modules/zod/src/v4/mini/tests/deep-partial.test.ts +54 -0
  367. package/node_modules/zod/src/v4/mini/tests/error.test.ts +41 -0
  368. package/node_modules/zod/src/v4/mini/tests/functions.test.ts +14 -0
  369. package/node_modules/zod/src/v4/mini/tests/index.test.ts +1146 -0
  370. package/node_modules/zod/src/v4/mini/tests/number.test.ts +109 -0
  371. package/node_modules/zod/src/v4/mini/tests/object.test.ts +292 -0
  372. package/node_modules/zod/src/v4/mini/tests/prototypes.test.ts +43 -0
  373. package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +341 -0
  374. package/node_modules/zod/src/v4/mini/tests/standard-schema.test.ts +50 -0
  375. package/node_modules/zod/src/v4/mini/tests/string.test.ts +396 -0
  376. package/node_modules/zod/src/v4-mini/index.ts +3 -0
  377. package/node_modules/zod/v3/ZodError.cjs +167 -0
  378. package/node_modules/zod/v3/ZodError.d.cts +164 -0
  379. package/node_modules/zod/v3/ZodError.d.ts +164 -0
  380. package/node_modules/zod/v3/ZodError.js +143 -0
  381. package/node_modules/zod/v3/errors.cjs +36 -0
  382. package/node_modules/zod/v3/errors.d.cts +5 -0
  383. package/node_modules/zod/v3/errors.d.ts +5 -0
  384. package/node_modules/zod/v3/errors.js +9 -0
  385. package/node_modules/zod/v3/external.cjs +41 -0
  386. package/node_modules/zod/v3/external.d.cts +6 -0
  387. package/node_modules/zod/v3/external.d.ts +6 -0
  388. package/node_modules/zod/v3/external.js +6 -0
  389. package/node_modules/zod/v3/helpers/enumUtil.cjs +21 -0
  390. package/node_modules/zod/v3/helpers/enumUtil.d.cts +8 -0
  391. package/node_modules/zod/v3/helpers/enumUtil.d.ts +8 -0
  392. package/node_modules/zod/v3/helpers/enumUtil.js +1 -0
  393. package/node_modules/zod/v3/helpers/errorUtil.cjs +28 -0
  394. package/node_modules/zod/v3/helpers/errorUtil.d.cts +9 -0
  395. package/node_modules/zod/v3/helpers/errorUtil.d.ts +9 -0
  396. package/node_modules/zod/v3/helpers/errorUtil.js +6 -0
  397. package/node_modules/zod/v3/helpers/parseUtil.cjs +143 -0
  398. package/node_modules/zod/v3/helpers/parseUtil.d.cts +78 -0
  399. package/node_modules/zod/v3/helpers/parseUtil.d.ts +78 -0
  400. package/node_modules/zod/v3/helpers/parseUtil.js +109 -0
  401. package/node_modules/zod/v3/helpers/partialUtil.cjs +21 -0
  402. package/node_modules/zod/v3/helpers/partialUtil.d.cts +8 -0
  403. package/node_modules/zod/v3/helpers/partialUtil.d.ts +8 -0
  404. package/node_modules/zod/v3/helpers/partialUtil.js +1 -0
  405. package/node_modules/zod/v3/helpers/typeAliases.cjs +21 -0
  406. package/node_modules/zod/v3/helpers/typeAliases.d.cts +2 -0
  407. package/node_modules/zod/v3/helpers/typeAliases.d.ts +2 -0
  408. package/node_modules/zod/v3/helpers/typeAliases.js +1 -0
  409. package/node_modules/zod/v3/helpers/util.cjs +156 -0
  410. package/node_modules/zod/v3/helpers/util.d.cts +85 -0
  411. package/node_modules/zod/v3/helpers/util.d.ts +85 -0
  412. package/node_modules/zod/v3/helpers/util.js +133 -0
  413. package/node_modules/zod/v3/index.cjs +52 -0
  414. package/node_modules/zod/v3/index.d.cts +4 -0
  415. package/node_modules/zod/v3/index.d.ts +4 -0
  416. package/node_modules/zod/v3/index.js +4 -0
  417. package/node_modules/zod/v3/locales/en.cjs +112 -0
  418. package/node_modules/zod/v3/locales/en.d.cts +3 -0
  419. package/node_modules/zod/v3/locales/en.d.ts +3 -0
  420. package/node_modules/zod/v3/locales/en.js +109 -0
  421. package/node_modules/zod/v3/package.json +7 -0
  422. package/node_modules/zod/v3/standard-schema.cjs +21 -0
  423. package/node_modules/zod/v3/standard-schema.d.cts +102 -0
  424. package/node_modules/zod/v3/standard-schema.d.ts +102 -0
  425. package/node_modules/zod/v3/standard-schema.js +1 -0
  426. package/node_modules/zod/v3/types.cjs +3798 -0
  427. package/node_modules/zod/v3/types.d.cts +1034 -0
  428. package/node_modules/zod/v3/types.d.ts +1034 -0
  429. package/node_modules/zod/v3/types.js +3697 -0
  430. package/node_modules/zod/v4/classic/checks.cjs +53 -0
  431. package/node_modules/zod/v4/classic/checks.d.cts +1 -0
  432. package/node_modules/zod/v4/classic/checks.d.ts +1 -0
  433. package/node_modules/zod/v4/classic/checks.js +1 -0
  434. package/node_modules/zod/v4/classic/coerce.cjs +66 -0
  435. package/node_modules/zod/v4/classic/coerce.d.cts +17 -0
  436. package/node_modules/zod/v4/classic/coerce.d.ts +17 -0
  437. package/node_modules/zod/v4/classic/coerce.js +17 -0
  438. package/node_modules/zod/v4/classic/compat.cjs +80 -0
  439. package/node_modules/zod/v4/classic/compat.d.cts +48 -0
  440. package/node_modules/zod/v4/classic/compat.d.ts +48 -0
  441. package/node_modules/zod/v4/classic/compat.js +31 -0
  442. package/node_modules/zod/v4/classic/deep-partial.cjs +58 -0
  443. package/node_modules/zod/v4/classic/deep-partial.d.cts +14 -0
  444. package/node_modules/zod/v4/classic/deep-partial.d.ts +14 -0
  445. package/node_modules/zod/v4/classic/deep-partial.js +13 -0
  446. package/node_modules/zod/v4/classic/errors.cjs +102 -0
  447. package/node_modules/zod/v4/classic/errors.d.cts +29 -0
  448. package/node_modules/zod/v4/classic/errors.d.ts +29 -0
  449. package/node_modules/zod/v4/classic/errors.js +57 -0
  450. package/node_modules/zod/v4/classic/external.cjs +97 -0
  451. package/node_modules/zod/v4/classic/external.d.cts +19 -0
  452. package/node_modules/zod/v4/classic/external.d.ts +19 -0
  453. package/node_modules/zod/v4/classic/external.js +17 -0
  454. package/node_modules/zod/v4/classic/from-json-schema.cjs +926 -0
  455. package/node_modules/zod/v4/classic/from-json-schema.d.cts +12 -0
  456. package/node_modules/zod/v4/classic/from-json-schema.d.ts +12 -0
  457. package/node_modules/zod/v4/classic/from-json-schema.js +881 -0
  458. package/node_modules/zod/v4/classic/in-out.cjs +82 -0
  459. package/node_modules/zod/v4/classic/in-out.d.cts +8 -0
  460. package/node_modules/zod/v4/classic/in-out.d.ts +8 -0
  461. package/node_modules/zod/v4/classic/in-out.js +36 -0
  462. package/node_modules/zod/v4/classic/index.cjs +52 -0
  463. package/node_modules/zod/v4/classic/index.d.cts +3 -0
  464. package/node_modules/zod/v4/classic/index.d.ts +3 -0
  465. package/node_modules/zod/v4/classic/index.js +4 -0
  466. package/node_modules/zod/v4/classic/iso.cjs +68 -0
  467. package/node_modules/zod/v4/classic/iso.d.cts +7 -0
  468. package/node_modules/zod/v4/classic/iso.d.ts +7 -0
  469. package/node_modules/zod/v4/classic/iso.js +15 -0
  470. package/node_modules/zod/v4/classic/package.json +7 -0
  471. package/node_modules/zod/v4/classic/parse.cjs +63 -0
  472. package/node_modules/zod/v4/classic/parse.d.cts +44 -0
  473. package/node_modules/zod/v4/classic/parse.d.ts +44 -0
  474. package/node_modules/zod/v4/classic/parse.js +16 -0
  475. package/node_modules/zod/v4/classic/schemas.cjs +1676 -0
  476. package/node_modules/zod/v4/classic/schemas.d.cts +816 -0
  477. package/node_modules/zod/v4/classic/schemas.d.ts +816 -0
  478. package/node_modules/zod/v4/classic/schemas.js +1535 -0
  479. package/node_modules/zod/v4/core/api.cjs +1269 -0
  480. package/node_modules/zod/v4/core/api.d.cts +335 -0
  481. package/node_modules/zod/v4/core/api.d.ts +335 -0
  482. package/node_modules/zod/v4/core/api.js +1107 -0
  483. package/node_modules/zod/v4/core/checks.cjs +561 -0
  484. package/node_modules/zod/v4/core/checks.d.cts +294 -0
  485. package/node_modules/zod/v4/core/checks.d.ts +294 -0
  486. package/node_modules/zod/v4/core/checks.js +516 -0
  487. package/node_modules/zod/v4/core/compile.cjs +1916 -0
  488. package/node_modules/zod/v4/core/compile.d.cts +65 -0
  489. package/node_modules/zod/v4/core/compile.d.ts +65 -0
  490. package/node_modules/zod/v4/core/compile.js +1866 -0
  491. package/node_modules/zod/v4/core/core.cjs +167 -0
  492. package/node_modules/zod/v4/core/core.d.cts +82 -0
  493. package/node_modules/zod/v4/core/core.d.ts +82 -0
  494. package/node_modules/zod/v4/core/core.js +141 -0
  495. package/node_modules/zod/v4/core/doc.cjs +61 -0
  496. package/node_modules/zod/v4/core/doc.d.cts +16 -0
  497. package/node_modules/zod/v4/core/doc.d.ts +16 -0
  498. package/node_modules/zod/v4/core/doc.js +38 -0
  499. package/node_modules/zod/v4/core/errors.cjs +317 -0
  500. package/node_modules/zod/v4/core/errors.d.cts +225 -0
  501. package/node_modules/zod/v4/core/errors.d.ts +225 -0
  502. package/node_modules/zod/v4/core/errors.js +267 -0
  503. package/node_modules/zod/v4/core/index.cjs +70 -0
  504. package/node_modules/zod/v4/core/index.d.cts +19 -0
  505. package/node_modules/zod/v4/core/index.d.ts +19 -0
  506. package/node_modules/zod/v4/core/index.js +19 -0
  507. package/node_modules/zod/v4/core/json-schema-generator.cjs +122 -0
  508. package/node_modules/zod/v4/core/json-schema-generator.d.cts +65 -0
  509. package/node_modules/zod/v4/core/json-schema-generator.d.ts +65 -0
  510. package/node_modules/zod/v4/core/json-schema-generator.js +99 -0
  511. package/node_modules/zod/v4/core/json-schema-processors.cjs +929 -0
  512. package/node_modules/zod/v4/core/json-schema-processors.d.cts +65 -0
  513. package/node_modules/zod/v4/core/json-schema-processors.d.ts +65 -0
  514. package/node_modules/zod/v4/core/json-schema-processors.js +843 -0
  515. package/node_modules/zod/v4/core/json-schema.cjs +21 -0
  516. package/node_modules/zod/v4/core/json-schema.d.cts +89 -0
  517. package/node_modules/zod/v4/core/json-schema.d.ts +89 -0
  518. package/node_modules/zod/v4/core/json-schema.js +1 -0
  519. package/node_modules/zod/v4/core/memoizer.cjs +360 -0
  520. package/node_modules/zod/v4/core/memoizer.d.cts +15 -0
  521. package/node_modules/zod/v4/core/memoizer.d.ts +15 -0
  522. package/node_modules/zod/v4/core/memoizer.js +311 -0
  523. package/node_modules/zod/v4/core/package.json +7 -0
  524. package/node_modules/zod/v4/core/parse.cjs +233 -0
  525. package/node_modules/zod/v4/core/parse.d.cts +52 -0
  526. package/node_modules/zod/v4/core/parse.d.ts +52 -0
  527. package/node_modules/zod/v4/core/parse.js +175 -0
  528. package/node_modules/zod/v4/core/regexes.cjs +209 -0
  529. package/node_modules/zod/v4/core/regexes.d.cts +90 -0
  530. package/node_modules/zod/v4/core/regexes.d.ts +90 -0
  531. package/node_modules/zod/v4/core/regexes.js +156 -0
  532. package/node_modules/zod/v4/core/registries.cjs +75 -0
  533. package/node_modules/zod/v4/core/registries.d.cts +35 -0
  534. package/node_modules/zod/v4/core/registries.d.ts +35 -0
  535. package/node_modules/zod/v4/core/registries.js +51 -0
  536. package/node_modules/zod/v4/core/schemas.cjs +2699 -0
  537. package/node_modules/zod/v4/core/schemas.d.cts +1275 -0
  538. package/node_modules/zod/v4/core/schemas.d.ts +1275 -0
  539. package/node_modules/zod/v4/core/schemas.js +2636 -0
  540. package/node_modules/zod/v4/core/standard-schema.cjs +21 -0
  541. package/node_modules/zod/v4/core/standard-schema.d.cts +126 -0
  542. package/node_modules/zod/v4/core/standard-schema.d.ts +126 -0
  543. package/node_modules/zod/v4/core/standard-schema.js +1 -0
  544. package/node_modules/zod/v4/core/to-json-schema.cjs +681 -0
  545. package/node_modules/zod/v4/core/to-json-schema.d.cts +154 -0
  546. package/node_modules/zod/v4/core/to-json-schema.d.ts +154 -0
  547. package/node_modules/zod/v4/core/to-json-schema.js +651 -0
  548. package/node_modules/zod/v4/core/util.cjs +964 -0
  549. package/node_modules/zod/v4/core/util.d.cts +280 -0
  550. package/node_modules/zod/v4/core/util.d.ts +280 -0
  551. package/node_modules/zod/v4/core/util.js +873 -0
  552. package/node_modules/zod/v4/core/versions.cjs +27 -0
  553. package/node_modules/zod/v4/core/versions.d.cts +5 -0
  554. package/node_modules/zod/v4/core/versions.d.ts +5 -0
  555. package/node_modules/zod/v4/core/versions.js +5 -0
  556. package/node_modules/zod/v4/core/visit.cjs +214 -0
  557. package/node_modules/zod/v4/core/visit.d.cts +30 -0
  558. package/node_modules/zod/v4/core/visit.d.ts +30 -0
  559. package/node_modules/zod/v4/core/visit.js +169 -0
  560. package/node_modules/zod/v4/index.cjs +51 -0
  561. package/node_modules/zod/v4/index.d.cts +3 -0
  562. package/node_modules/zod/v4/index.d.ts +3 -0
  563. package/node_modules/zod/v4/index.js +4 -0
  564. package/node_modules/zod/v4/locales/ar.cjs +138 -0
  565. package/node_modules/zod/v4/locales/ar.d.cts +5 -0
  566. package/node_modules/zod/v4/locales/ar.d.ts +4 -0
  567. package/node_modules/zod/v4/locales/ar.js +111 -0
  568. package/node_modules/zod/v4/locales/az.cjs +137 -0
  569. package/node_modules/zod/v4/locales/az.d.cts +5 -0
  570. package/node_modules/zod/v4/locales/az.d.ts +4 -0
  571. package/node_modules/zod/v4/locales/az.js +110 -0
  572. package/node_modules/zod/v4/locales/be.cjs +195 -0
  573. package/node_modules/zod/v4/locales/be.d.cts +5 -0
  574. package/node_modules/zod/v4/locales/be.d.ts +4 -0
  575. package/node_modules/zod/v4/locales/be.js +168 -0
  576. package/node_modules/zod/v4/locales/bg.cjs +152 -0
  577. package/node_modules/zod/v4/locales/bg.d.cts +5 -0
  578. package/node_modules/zod/v4/locales/bg.d.ts +4 -0
  579. package/node_modules/zod/v4/locales/bg.js +125 -0
  580. package/node_modules/zod/v4/locales/bn.cjs +140 -0
  581. package/node_modules/zod/v4/locales/bn.d.cts +5 -0
  582. package/node_modules/zod/v4/locales/bn.d.ts +4 -0
  583. package/node_modules/zod/v4/locales/bn.js +113 -0
  584. package/node_modules/zod/v4/locales/ca.cjs +139 -0
  585. package/node_modules/zod/v4/locales/ca.d.cts +5 -0
  586. package/node_modules/zod/v4/locales/ca.d.ts +4 -0
  587. package/node_modules/zod/v4/locales/ca.js +112 -0
  588. package/node_modules/zod/v4/locales/ckb.cjs +160 -0
  589. package/node_modules/zod/v4/locales/ckb.d.cts +5 -0
  590. package/node_modules/zod/v4/locales/ckb.d.ts +4 -0
  591. package/node_modules/zod/v4/locales/ckb.js +133 -0
  592. package/node_modules/zod/v4/locales/cs.cjs +143 -0
  593. package/node_modules/zod/v4/locales/cs.d.cts +5 -0
  594. package/node_modules/zod/v4/locales/cs.d.ts +4 -0
  595. package/node_modules/zod/v4/locales/cs.js +116 -0
  596. package/node_modules/zod/v4/locales/da.cjs +147 -0
  597. package/node_modules/zod/v4/locales/da.d.cts +5 -0
  598. package/node_modules/zod/v4/locales/da.d.ts +4 -0
  599. package/node_modules/zod/v4/locales/da.js +120 -0
  600. package/node_modules/zod/v4/locales/de.cjs +140 -0
  601. package/node_modules/zod/v4/locales/de.d.cts +5 -0
  602. package/node_modules/zod/v4/locales/de.d.ts +4 -0
  603. package/node_modules/zod/v4/locales/de.js +113 -0
  604. package/node_modules/zod/v4/locales/el.cjs +139 -0
  605. package/node_modules/zod/v4/locales/el.d.cts +5 -0
  606. package/node_modules/zod/v4/locales/el.d.ts +4 -0
  607. package/node_modules/zod/v4/locales/el.js +112 -0
  608. package/node_modules/zod/v4/locales/en.cjs +152 -0
  609. package/node_modules/zod/v4/locales/en.d.cts +5 -0
  610. package/node_modules/zod/v4/locales/en.d.ts +4 -0
  611. package/node_modules/zod/v4/locales/en.js +125 -0
  612. package/node_modules/zod/v4/locales/eo.cjs +141 -0
  613. package/node_modules/zod/v4/locales/eo.d.cts +5 -0
  614. package/node_modules/zod/v4/locales/eo.d.ts +4 -0
  615. package/node_modules/zod/v4/locales/eo.js +114 -0
  616. package/node_modules/zod/v4/locales/es.cjs +163 -0
  617. package/node_modules/zod/v4/locales/es.d.cts +5 -0
  618. package/node_modules/zod/v4/locales/es.d.ts +4 -0
  619. package/node_modules/zod/v4/locales/es.js +136 -0
  620. package/node_modules/zod/v4/locales/fa.cjs +146 -0
  621. package/node_modules/zod/v4/locales/fa.d.cts +5 -0
  622. package/node_modules/zod/v4/locales/fa.d.ts +4 -0
  623. package/node_modules/zod/v4/locales/fa.js +119 -0
  624. package/node_modules/zod/v4/locales/fi.cjs +144 -0
  625. package/node_modules/zod/v4/locales/fi.d.cts +5 -0
  626. package/node_modules/zod/v4/locales/fi.d.ts +4 -0
  627. package/node_modules/zod/v4/locales/fi.js +117 -0
  628. package/node_modules/zod/v4/locales/fr-CA.cjs +139 -0
  629. package/node_modules/zod/v4/locales/fr-CA.d.cts +5 -0
  630. package/node_modules/zod/v4/locales/fr-CA.d.ts +4 -0
  631. package/node_modules/zod/v4/locales/fr-CA.js +112 -0
  632. package/node_modules/zod/v4/locales/fr.cjs +156 -0
  633. package/node_modules/zod/v4/locales/fr.d.cts +5 -0
  634. package/node_modules/zod/v4/locales/fr.d.ts +4 -0
  635. package/node_modules/zod/v4/locales/fr.js +129 -0
  636. package/node_modules/zod/v4/locales/gu.cjs +140 -0
  637. package/node_modules/zod/v4/locales/gu.d.cts +5 -0
  638. package/node_modules/zod/v4/locales/gu.d.ts +4 -0
  639. package/node_modules/zod/v4/locales/gu.js +113 -0
  640. package/node_modules/zod/v4/locales/he.cjs +248 -0
  641. package/node_modules/zod/v4/locales/he.d.cts +5 -0
  642. package/node_modules/zod/v4/locales/he.d.ts +4 -0
  643. package/node_modules/zod/v4/locales/he.js +221 -0
  644. package/node_modules/zod/v4/locales/hi.cjs +138 -0
  645. package/node_modules/zod/v4/locales/hi.d.cts +5 -0
  646. package/node_modules/zod/v4/locales/hi.d.ts +4 -0
  647. package/node_modules/zod/v4/locales/hi.js +111 -0
  648. package/node_modules/zod/v4/locales/hr.cjs +153 -0
  649. package/node_modules/zod/v4/locales/hr.d.cts +5 -0
  650. package/node_modules/zod/v4/locales/hr.d.ts +4 -0
  651. package/node_modules/zod/v4/locales/hr.js +126 -0
  652. package/node_modules/zod/v4/locales/hu.cjs +140 -0
  653. package/node_modules/zod/v4/locales/hu.d.cts +5 -0
  654. package/node_modules/zod/v4/locales/hu.d.ts +4 -0
  655. package/node_modules/zod/v4/locales/hu.js +113 -0
  656. package/node_modules/zod/v4/locales/hy.cjs +185 -0
  657. package/node_modules/zod/v4/locales/hy.d.cts +5 -0
  658. package/node_modules/zod/v4/locales/hy.d.ts +4 -0
  659. package/node_modules/zod/v4/locales/hy.js +158 -0
  660. package/node_modules/zod/v4/locales/id.cjs +138 -0
  661. package/node_modules/zod/v4/locales/id.d.cts +5 -0
  662. package/node_modules/zod/v4/locales/id.d.ts +4 -0
  663. package/node_modules/zod/v4/locales/id.js +111 -0
  664. package/node_modules/zod/v4/locales/index.cjs +152 -0
  665. package/node_modules/zod/v4/locales/index.d.cts +63 -0
  666. package/node_modules/zod/v4/locales/index.d.ts +63 -0
  667. package/node_modules/zod/v4/locales/index.js +63 -0
  668. package/node_modules/zod/v4/locales/is.cjs +141 -0
  669. package/node_modules/zod/v4/locales/is.d.cts +5 -0
  670. package/node_modules/zod/v4/locales/is.d.ts +4 -0
  671. package/node_modules/zod/v4/locales/is.js +114 -0
  672. package/node_modules/zod/v4/locales/it.cjs +140 -0
  673. package/node_modules/zod/v4/locales/it.d.cts +5 -0
  674. package/node_modules/zod/v4/locales/it.d.ts +4 -0
  675. package/node_modules/zod/v4/locales/it.js +113 -0
  676. package/node_modules/zod/v4/locales/ja.cjs +139 -0
  677. package/node_modules/zod/v4/locales/ja.d.cts +5 -0
  678. package/node_modules/zod/v4/locales/ja.d.ts +4 -0
  679. package/node_modules/zod/v4/locales/ja.js +112 -0
  680. package/node_modules/zod/v4/locales/ka.cjs +144 -0
  681. package/node_modules/zod/v4/locales/ka.d.cts +5 -0
  682. package/node_modules/zod/v4/locales/ka.d.ts +4 -0
  683. package/node_modules/zod/v4/locales/ka.js +117 -0
  684. package/node_modules/zod/v4/locales/kh.cjs +12 -0
  685. package/node_modules/zod/v4/locales/kh.d.cts +5 -0
  686. package/node_modules/zod/v4/locales/kh.d.ts +5 -0
  687. package/node_modules/zod/v4/locales/kh.js +5 -0
  688. package/node_modules/zod/v4/locales/km.cjs +142 -0
  689. package/node_modules/zod/v4/locales/km.d.cts +5 -0
  690. package/node_modules/zod/v4/locales/km.d.ts +4 -0
  691. package/node_modules/zod/v4/locales/km.js +115 -0
  692. package/node_modules/zod/v4/locales/kn.cjs +143 -0
  693. package/node_modules/zod/v4/locales/kn.d.cts +5 -0
  694. package/node_modules/zod/v4/locales/kn.d.ts +4 -0
  695. package/node_modules/zod/v4/locales/kn.js +116 -0
  696. package/node_modules/zod/v4/locales/ko.cjs +143 -0
  697. package/node_modules/zod/v4/locales/ko.d.cts +5 -0
  698. package/node_modules/zod/v4/locales/ko.d.ts +4 -0
  699. package/node_modules/zod/v4/locales/ko.js +116 -0
  700. package/node_modules/zod/v4/locales/lt.cjs +234 -0
  701. package/node_modules/zod/v4/locales/lt.d.cts +5 -0
  702. package/node_modules/zod/v4/locales/lt.d.ts +4 -0
  703. package/node_modules/zod/v4/locales/lt.js +207 -0
  704. package/node_modules/zod/v4/locales/mk.cjs +141 -0
  705. package/node_modules/zod/v4/locales/mk.d.cts +5 -0
  706. package/node_modules/zod/v4/locales/mk.d.ts +4 -0
  707. package/node_modules/zod/v4/locales/mk.js +114 -0
  708. package/node_modules/zod/v4/locales/ms.cjs +139 -0
  709. package/node_modules/zod/v4/locales/ms.d.cts +5 -0
  710. package/node_modules/zod/v4/locales/ms.d.ts +4 -0
  711. package/node_modules/zod/v4/locales/ms.js +112 -0
  712. package/node_modules/zod/v4/locales/ne.cjs +138 -0
  713. package/node_modules/zod/v4/locales/ne.d.cts +5 -0
  714. package/node_modules/zod/v4/locales/ne.d.ts +4 -0
  715. package/node_modules/zod/v4/locales/ne.js +111 -0
  716. package/node_modules/zod/v4/locales/nl.cjs +142 -0
  717. package/node_modules/zod/v4/locales/nl.d.cts +5 -0
  718. package/node_modules/zod/v4/locales/nl.d.ts +4 -0
  719. package/node_modules/zod/v4/locales/nl.js +115 -0
  720. package/node_modules/zod/v4/locales/nn.cjs +140 -0
  721. package/node_modules/zod/v4/locales/nn.d.cts +5 -0
  722. package/node_modules/zod/v4/locales/nn.d.ts +4 -0
  723. package/node_modules/zod/v4/locales/nn.js +113 -0
  724. package/node_modules/zod/v4/locales/no.cjs +140 -0
  725. package/node_modules/zod/v4/locales/no.d.cts +5 -0
  726. package/node_modules/zod/v4/locales/no.d.ts +4 -0
  727. package/node_modules/zod/v4/locales/no.js +113 -0
  728. package/node_modules/zod/v4/locales/ota.cjs +141 -0
  729. package/node_modules/zod/v4/locales/ota.d.cts +5 -0
  730. package/node_modules/zod/v4/locales/ota.d.ts +4 -0
  731. package/node_modules/zod/v4/locales/ota.js +114 -0
  732. package/node_modules/zod/v4/locales/package.json +7 -0
  733. package/node_modules/zod/v4/locales/pl.cjs +141 -0
  734. package/node_modules/zod/v4/locales/pl.d.cts +5 -0
  735. package/node_modules/zod/v4/locales/pl.d.ts +4 -0
  736. package/node_modules/zod/v4/locales/pl.js +114 -0
  737. package/node_modules/zod/v4/locales/ps.cjs +146 -0
  738. package/node_modules/zod/v4/locales/ps.d.cts +5 -0
  739. package/node_modules/zod/v4/locales/ps.d.ts +4 -0
  740. package/node_modules/zod/v4/locales/ps.js +119 -0
  741. package/node_modules/zod/v4/locales/pt-BR.cjs +170 -0
  742. package/node_modules/zod/v4/locales/pt-BR.d.cts +5 -0
  743. package/node_modules/zod/v4/locales/pt-BR.d.ts +4 -0
  744. package/node_modules/zod/v4/locales/pt-BR.js +143 -0
  745. package/node_modules/zod/v4/locales/pt.cjs +169 -0
  746. package/node_modules/zod/v4/locales/pt.d.cts +5 -0
  747. package/node_modules/zod/v4/locales/pt.d.ts +4 -0
  748. package/node_modules/zod/v4/locales/pt.js +142 -0
  749. package/node_modules/zod/v4/locales/ro.cjs +149 -0
  750. package/node_modules/zod/v4/locales/ro.d.cts +5 -0
  751. package/node_modules/zod/v4/locales/ro.d.ts +4 -0
  752. package/node_modules/zod/v4/locales/ro.js +122 -0
  753. package/node_modules/zod/v4/locales/ru.cjs +195 -0
  754. package/node_modules/zod/v4/locales/ru.d.cts +5 -0
  755. package/node_modules/zod/v4/locales/ru.d.ts +4 -0
  756. package/node_modules/zod/v4/locales/ru.js +168 -0
  757. package/node_modules/zod/v4/locales/sk.cjs +143 -0
  758. package/node_modules/zod/v4/locales/sk.d.cts +5 -0
  759. package/node_modules/zod/v4/locales/sk.d.ts +4 -0
  760. package/node_modules/zod/v4/locales/sk.js +116 -0
  761. package/node_modules/zod/v4/locales/sl.cjs +141 -0
  762. package/node_modules/zod/v4/locales/sl.d.cts +5 -0
  763. package/node_modules/zod/v4/locales/sl.d.ts +4 -0
  764. package/node_modules/zod/v4/locales/sl.js +114 -0
  765. package/node_modules/zod/v4/locales/sv.cjs +142 -0
  766. package/node_modules/zod/v4/locales/sv.d.cts +5 -0
  767. package/node_modules/zod/v4/locales/sv.d.ts +4 -0
  768. package/node_modules/zod/v4/locales/sv.js +115 -0
  769. package/node_modules/zod/v4/locales/ta.cjs +142 -0
  770. package/node_modules/zod/v4/locales/ta.d.cts +5 -0
  771. package/node_modules/zod/v4/locales/ta.d.ts +4 -0
  772. package/node_modules/zod/v4/locales/ta.js +115 -0
  773. package/node_modules/zod/v4/locales/tg.cjs +144 -0
  774. package/node_modules/zod/v4/locales/tg.d.cts +5 -0
  775. package/node_modules/zod/v4/locales/tg.d.ts +4 -0
  776. package/node_modules/zod/v4/locales/tg.js +117 -0
  777. package/node_modules/zod/v4/locales/th.cjs +142 -0
  778. package/node_modules/zod/v4/locales/th.d.cts +5 -0
  779. package/node_modules/zod/v4/locales/th.d.ts +4 -0
  780. package/node_modules/zod/v4/locales/th.js +115 -0
  781. package/node_modules/zod/v4/locales/tk.cjs +134 -0
  782. package/node_modules/zod/v4/locales/tk.d.cts +5 -0
  783. package/node_modules/zod/v4/locales/tk.d.ts +4 -0
  784. package/node_modules/zod/v4/locales/tk.js +107 -0
  785. package/node_modules/zod/v4/locales/tr.cjs +137 -0
  786. package/node_modules/zod/v4/locales/tr.d.cts +5 -0
  787. package/node_modules/zod/v4/locales/tr.d.ts +4 -0
  788. package/node_modules/zod/v4/locales/tr.js +110 -0
  789. package/node_modules/zod/v4/locales/ua.cjs +12 -0
  790. package/node_modules/zod/v4/locales/ua.d.cts +5 -0
  791. package/node_modules/zod/v4/locales/ua.d.ts +5 -0
  792. package/node_modules/zod/v4/locales/ua.js +5 -0
  793. package/node_modules/zod/v4/locales/uk.cjs +140 -0
  794. package/node_modules/zod/v4/locales/uk.d.cts +5 -0
  795. package/node_modules/zod/v4/locales/uk.d.ts +4 -0
  796. package/node_modules/zod/v4/locales/uk.js +113 -0
  797. package/node_modules/zod/v4/locales/ur.cjs +142 -0
  798. package/node_modules/zod/v4/locales/ur.d.cts +5 -0
  799. package/node_modules/zod/v4/locales/ur.d.ts +4 -0
  800. package/node_modules/zod/v4/locales/ur.js +115 -0
  801. package/node_modules/zod/v4/locales/uz.cjs +140 -0
  802. package/node_modules/zod/v4/locales/uz.d.cts +5 -0
  803. package/node_modules/zod/v4/locales/uz.d.ts +4 -0
  804. package/node_modules/zod/v4/locales/uz.js +113 -0
  805. package/node_modules/zod/v4/locales/vi.cjs +140 -0
  806. package/node_modules/zod/v4/locales/vi.d.cts +5 -0
  807. package/node_modules/zod/v4/locales/vi.d.ts +4 -0
  808. package/node_modules/zod/v4/locales/vi.js +113 -0
  809. package/node_modules/zod/v4/locales/yo.cjs +139 -0
  810. package/node_modules/zod/v4/locales/yo.d.cts +5 -0
  811. package/node_modules/zod/v4/locales/yo.d.ts +4 -0
  812. package/node_modules/zod/v4/locales/yo.js +112 -0
  813. package/node_modules/zod/v4/locales/zh-CN.cjs +141 -0
  814. package/node_modules/zod/v4/locales/zh-CN.d.cts +5 -0
  815. package/node_modules/zod/v4/locales/zh-CN.d.ts +4 -0
  816. package/node_modules/zod/v4/locales/zh-CN.js +114 -0
  817. package/node_modules/zod/v4/locales/zh-TW.cjs +139 -0
  818. package/node_modules/zod/v4/locales/zh-TW.d.cts +5 -0
  819. package/node_modules/zod/v4/locales/zh-TW.d.ts +4 -0
  820. package/node_modules/zod/v4/locales/zh-TW.js +112 -0
  821. package/node_modules/zod/v4/mini/checks.cjs +54 -0
  822. package/node_modules/zod/v4/mini/checks.d.cts +1 -0
  823. package/node_modules/zod/v4/mini/checks.d.ts +1 -0
  824. package/node_modules/zod/v4/mini/checks.js +1 -0
  825. package/node_modules/zod/v4/mini/coerce.cjs +71 -0
  826. package/node_modules/zod/v4/mini/coerce.d.cts +7 -0
  827. package/node_modules/zod/v4/mini/coerce.d.ts +7 -0
  828. package/node_modules/zod/v4/mini/coerce.js +22 -0
  829. package/node_modules/zod/v4/mini/deep-partial.cjs +58 -0
  830. package/node_modules/zod/v4/mini/deep-partial.d.cts +14 -0
  831. package/node_modules/zod/v4/mini/deep-partial.d.ts +14 -0
  832. package/node_modules/zod/v4/mini/deep-partial.js +13 -0
  833. package/node_modules/zod/v4/mini/external.cjs +95 -0
  834. package/node_modules/zod/v4/mini/external.d.cts +16 -0
  835. package/node_modules/zod/v4/mini/external.d.ts +16 -0
  836. package/node_modules/zod/v4/mini/external.js +16 -0
  837. package/node_modules/zod/v4/mini/in-out.cjs +82 -0
  838. package/node_modules/zod/v4/mini/in-out.d.cts +8 -0
  839. package/node_modules/zod/v4/mini/in-out.d.ts +8 -0
  840. package/node_modules/zod/v4/mini/in-out.js +36 -0
  841. package/node_modules/zod/v4/mini/index.cjs +51 -0
  842. package/node_modules/zod/v4/mini/index.d.cts +3 -0
  843. package/node_modules/zod/v4/mini/index.d.ts +3 -0
  844. package/node_modules/zod/v4/mini/index.js +3 -0
  845. package/node_modules/zod/v4/mini/iso.cjs +83 -0
  846. package/node_modules/zod/v4/mini/iso.d.cts +22 -0
  847. package/node_modules/zod/v4/mini/iso.d.ts +22 -0
  848. package/node_modules/zod/v4/mini/iso.js +34 -0
  849. package/node_modules/zod/v4/mini/package.json +7 -0
  850. package/node_modules/zod/v4/mini/parse.cjs +37 -0
  851. package/node_modules/zod/v4/mini/parse.d.cts +1 -0
  852. package/node_modules/zod/v4/mini/parse.d.ts +1 -0
  853. package/node_modules/zod/v4/mini/parse.js +1 -0
  854. package/node_modules/zod/v4/mini/schemas.cjs +1147 -0
  855. package/node_modules/zod/v4/mini/schemas.d.cts +480 -0
  856. package/node_modules/zod/v4/mini/schemas.d.ts +480 -0
  857. package/node_modules/zod/v4/mini/schemas.js +1002 -0
  858. package/node_modules/zod/v4/package.json +7 -0
  859. package/node_modules/zod/v4-mini/index.cjs +51 -0
  860. package/node_modules/zod/v4-mini/index.d.cts +3 -0
  861. package/node_modules/zod/v4-mini/index.d.ts +3 -0
  862. package/node_modules/zod/v4-mini/index.js +3 -0
  863. package/node_modules/zod/v4-mini/package.json +7 -0
  864. package/package.json +94 -94
@@ -0,0 +1,4116 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ ACCOUNT_SDK_CONTRACT: () => ACCOUNT_SDK_CONTRACT,
25
+ AccountClient: () => AccountClient,
26
+ AccountError: () => AccountError,
27
+ AccountIntegrationClient: () => AccountIntegrationClient,
28
+ AccountMutationError: () => AccountMutationError,
29
+ AuthzClient: () => AuthzClient,
30
+ BffSessionClient: () => BffSessionClient,
31
+ LedgerClient: () => LedgerClient,
32
+ MICRO_PER_CREDIT: () => MICRO_PER_CREDIT,
33
+ NotificationsClient: () => NotificationsClient,
34
+ Transport: () => Transport,
35
+ WorkforceClient: () => WorkforceClient,
36
+ WorkforceResourceMutationError: () => WorkforceResourceMutationError,
37
+ WorkspaceClient: () => WorkspaceClient,
38
+ WorkspaceKeyMutationError: () => WorkspaceKeyMutationError,
39
+ WorkspaceMembershipMutationError: () => WorkspaceMembershipMutationError,
40
+ XenoAccountClient: () => XenoAccountClient,
41
+ accountOperationIntentSchema: () => accountOperationIntentSchema,
42
+ accountSchema: () => accountSchema,
43
+ assertMembershipOperation: () => assertMembershipOperation,
44
+ authzCheckSchema: () => authzCheckSchema,
45
+ authzResultSchema: () => authzResultSchema,
46
+ balanceSchema: () => balanceSchema,
47
+ buildAuthorizeUrl: () => buildAuthorizeUrl,
48
+ codeForStatus: () => codeForStatus,
49
+ createOidcIntrospectionSessionAuthority: () => createOidcIntrospectionSessionAuthority,
50
+ createResourceRequestAuthorizer: () => createResourceRequestAuthorizer,
51
+ exchangeCode: () => exchangeCode,
52
+ fromMicro: () => fromMicro,
53
+ generatePkce: () => generatePkce,
54
+ generateState: () => generateState,
55
+ holdRequestSchema: () => holdRequestSchema,
56
+ holdSchema: () => holdSchema,
57
+ keychainStore: () => keychainStore,
58
+ membershipAbandonedSchema: () => membershipAbandonedSchema,
59
+ membershipCommittedSchema: () => membershipCommittedSchema,
60
+ membershipDeliverySchema: () => membershipDeliverySchema,
61
+ membershipMutationSchema: () => membershipMutationSchema,
62
+ membershipOperationSchema: () => membershipOperationSchema,
63
+ membershipRejectedSchema: () => membershipRejectedSchema,
64
+ memoryStore: () => memoryStore,
65
+ meterAggregationSchema: () => meterAggregationSchema,
66
+ normalize: () => normalize,
67
+ normalizeDpopHtu: () => normalizeDpopHtu,
68
+ notificationChannelSchema: () => notificationChannelSchema,
69
+ notificationDestinationActionSchema: () => notificationDestinationActionSchema,
70
+ notificationDestinationOperationSchema: () => notificationDestinationOperationSchema,
71
+ notificationEventSchema: () => notificationEventSchema,
72
+ notificationRuleSchema: () => notificationRuleSchema,
73
+ notificationScopeSchema: () => notificationScopeSchema,
74
+ notificationSettingsSchema: () => notificationSettingsSchema,
75
+ oauthTokenResponseSchema: () => oauthTokenResponseSchema,
76
+ pollDeviceToken: () => pollDeviceToken,
77
+ redact: () => redact,
78
+ refreshTokens: () => refreshTokens,
79
+ startDeviceAuthorization: () => startDeviceAuthorization,
80
+ surfaceSchema: () => surfaceSchema,
81
+ toMicro: () => toMicro,
82
+ tokenSetSchema: () => tokenSetSchema,
83
+ usageEventSchema: () => usageEventSchema,
84
+ usageResultSchema: () => usageResultSchema,
85
+ verifyAccessToken: () => verifyAccessToken,
86
+ verifyIdToken: () => verifyIdToken,
87
+ verifyLogoutToken: () => verifyLogoutToken,
88
+ workforceCreateResourceSchema: () => workforceCreateResourceSchema,
89
+ workforceDefinitionSchema: () => workforceDefinitionSchema,
90
+ workforceListOwnedResourcesSchema: () => workforceListOwnedResourcesSchema,
91
+ workforceOwnerSchema: () => workforceOwnerSchema,
92
+ workforceReadOperationSchema: () => workforceReadOperationSchema,
93
+ workspaceInviteRoleSchema: () => workspaceInviteRoleSchema,
94
+ workspaceInviteSchema: () => workspaceInviteSchema,
95
+ workspaceKeyOperationSchema: () => workspaceKeyOperationSchema,
96
+ workspaceKeyRejectionSchema: () => workspaceKeyRejectionSchema,
97
+ workspaceKeySchema: () => workspaceKeySchema,
98
+ workspaceKeyScopeSchema: () => workspaceKeyScopeSchema,
99
+ workspaceMemberSchema: () => workspaceMemberSchema,
100
+ workspaceRoleSchema: () => workspaceRoleSchema,
101
+ workspaceSchema: () => workspaceSchema
102
+ });
103
+ module.exports = __toCommonJS(src_exports);
104
+
105
+ // src/types.ts
106
+ var import_zod = require("zod");
107
+ var MICRO_PER_CREDIT = 1e6;
108
+ var surfaceSchema = import_zod.z.string().min(2).max(64).regex(/^xeno[_a-z0-9]+$/, "surface must look like xeno_post");
109
+ var accountSchema = import_zod.z.object({
110
+ id: import_zod.z.string().min(1),
111
+ email: import_zod.z.string().email(),
112
+ username: import_zod.z.string().nullable().default(null),
113
+ displayName: import_zod.z.string().nullable().default(null),
114
+ avatarUrl: import_zod.z.string().url().nullable().default(null),
115
+ emailVerified: import_zod.z.boolean().default(false),
116
+ /** Linked app surfaces for this account (unified-account view). */
117
+ linkedSurfaces: import_zod.z.array(surfaceSchema).default([])
118
+ });
119
+ var tokenSetSchema = import_zod.z.object({
120
+ accessToken: import_zod.z.string().min(1),
121
+ /** Opaque or JWT; the SDK treats it as opaque. */
122
+ tokenType: import_zod.z.string().default("Bearer"),
123
+ expiresAt: import_zod.z.coerce.date().nullable().default(null),
124
+ refreshToken: import_zod.z.string().nullable().default(null),
125
+ /** OIDC ID token (authentication only — never sent to resource APIs). */
126
+ idToken: import_zod.z.string().nullable().default(null),
127
+ scope: import_zod.z.array(import_zod.z.string()).default([]),
128
+ /** Session id claim, the join key for back-channel logout. */
129
+ sid: import_zod.z.string().nullable().default(null),
130
+ /** Signature-verified claims; never populated by unverified decoding. */
131
+ accessClaims: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).nullable().default(null),
132
+ idClaims: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).nullable().default(null)
133
+ });
134
+ var oauthTokenResponseSchema = import_zod.z.object({
135
+ access_token: import_zod.z.string(),
136
+ token_type: import_zod.z.string().default("Bearer"),
137
+ expires_in: import_zod.z.number().optional(),
138
+ refresh_token: import_zod.z.string().optional(),
139
+ id_token: import_zod.z.string().optional(),
140
+ scope: import_zod.z.string().optional()
141
+ });
142
+ var balanceSchema = import_zod.z.object({
143
+ /** Settled balance. */
144
+ postedMicro: import_zod.z.number().int(),
145
+ /** Settled minus active holds. */
146
+ pendingMicro: import_zod.z.number().int(),
147
+ /** Most conservative spendable amount — gate approvals on this. */
148
+ availableMicro: import_zod.z.number().int(),
149
+ currency: import_zod.z.literal("credits").default("credits"),
150
+ asOf: import_zod.z.coerce.date().default(() => /* @__PURE__ */ new Date(0))
151
+ });
152
+ var meterAggregationSchema = import_zod.z.enum([
153
+ "sum",
154
+ "count",
155
+ "max",
156
+ "min",
157
+ "unique_count",
158
+ "latest"
159
+ ]);
160
+ var usageEventSchema = import_zod.z.object({
161
+ surface: surfaceSchema,
162
+ /** Stable, producer-supplied dedup id. */
163
+ transactionId: import_zod.z.string().min(8).max(255),
164
+ operation: import_zod.z.string().min(1),
165
+ model: import_zod.z.string().nullable().default(null),
166
+ provider: import_zod.z.string().nullable().default(null),
167
+ /** Pre-computed cost in micro-credits, if the caller priced it. */
168
+ costMicro: import_zod.z.number().int().nonnegative().nullable().default(null),
169
+ inputTokens: import_zod.z.number().int().nonnegative().nullable().default(null),
170
+ outputTokens: import_zod.z.number().int().nonnegative().nullable().default(null),
171
+ /** Arbitrary attribution dimensions (project, workspace, …). */
172
+ dimensions: import_zod.z.record(import_zod.z.string(), import_zod.z.string()).default({}),
173
+ occurredAt: import_zod.z.coerce.date().optional()
174
+ });
175
+ var usageResultSchema = import_zod.z.object({
176
+ accepted: import_zod.z.boolean(),
177
+ /** True when the event was a duplicate (idempotent no-op). */
178
+ duplicate: import_zod.z.boolean().default(false),
179
+ costMicro: import_zod.z.number().int().nonnegative(),
180
+ transactionId: import_zod.z.string(),
181
+ balance: balanceSchema.nullable().default(null)
182
+ });
183
+ var holdRequestSchema = import_zod.z.object({
184
+ surface: surfaceSchema,
185
+ /** Idempotency key for the hold itself. */
186
+ holdId: import_zod.z.string().min(8).max(255),
187
+ amountMicro: import_zod.z.number().int().positive(),
188
+ operation: import_zod.z.string().min(1),
189
+ expiresInSeconds: import_zod.z.number().int().positive().max(86400).default(900),
190
+ dimensions: import_zod.z.record(import_zod.z.string(), import_zod.z.string()).default({})
191
+ });
192
+ var holdSchema = import_zod.z.object({
193
+ holdId: import_zod.z.string(),
194
+ state: import_zod.z.enum([
195
+ "held",
196
+ "settled",
197
+ "voided",
198
+ "expired"
199
+ ]),
200
+ amountMicro: import_zod.z.number().int().nonnegative(),
201
+ settledMicro: import_zod.z.number().int().nonnegative().default(0),
202
+ balance: balanceSchema.nullable().default(null)
203
+ });
204
+ var authzCheckSchema = import_zod.z.object({
205
+ /** e.g. `user:abc` or `agent:scout`. */
206
+ subject: import_zod.z.string().min(1),
207
+ relation: import_zod.z.string().min(1),
208
+ /** e.g. `workspace:acme` or `post:123`. */
209
+ object: import_zod.z.string().min(1),
210
+ context: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).default({})
211
+ });
212
+ var authzResultSchema = import_zod.z.object({
213
+ allowed: import_zod.z.boolean(),
214
+ /** Optional reason/trace for debugging (never authoritative). */
215
+ reason: import_zod.z.string().nullable().default(null)
216
+ });
217
+ function toMicro(credits) {
218
+ return Math.round(credits * MICRO_PER_CREDIT);
219
+ }
220
+ __name(toMicro, "toMicro");
221
+ function fromMicro(micro) {
222
+ return micro / MICRO_PER_CREDIT;
223
+ }
224
+ __name(fromMicro, "fromMicro");
225
+
226
+ // src/errors.ts
227
+ var AccountError = class extends Error {
228
+ static {
229
+ __name(this, "AccountError");
230
+ }
231
+ code;
232
+ httpStatus;
233
+ retryable;
234
+ retryAfterMs;
235
+ oauthError;
236
+ constructor(args) {
237
+ super(args.message);
238
+ this.name = "AccountError";
239
+ this.code = args.code;
240
+ this.httpStatus = args.httpStatus ?? null;
241
+ this.retryable = args.retryable ?? defaultRetryable(args.code);
242
+ this.retryAfterMs = args.retryAfterMs ?? null;
243
+ this.oauthError = args.oauthError ?? null;
244
+ }
245
+ };
246
+ function defaultRetryable(code) {
247
+ return code === "UNREACHABLE" || code === "RATE_LIMITED" || code === "PLATFORM_ERROR";
248
+ }
249
+ __name(defaultRetryable, "defaultRetryable");
250
+ function codeForStatus(status) {
251
+ if (status === 401 || status === 403) return "INVALID_TOKEN";
252
+ if (status === 402) return "INSUFFICIENT_CREDITS";
253
+ if (status === 409) return "CONFLICT";
254
+ if (status === 400 || status === 422) return "BAD_REQUEST";
255
+ if (status === 404) return "NOT_FOUND";
256
+ if (status === 429) return "RATE_LIMITED";
257
+ if (status >= 500) return "UNREACHABLE";
258
+ return "PLATFORM_ERROR";
259
+ }
260
+ __name(codeForStatus, "codeForStatus");
261
+
262
+ // src/jwt-json.ts
263
+ function parseJwtObject(source) {
264
+ if (source.length > 16384) throw new SyntaxError("JWT JSON bound");
265
+ let offset = 0;
266
+ const whitespace = /* @__PURE__ */ __name(() => {
267
+ while (offset < source.length && /[ \t\r\n]/.test(source[offset] ?? "")) offset++;
268
+ }, "whitespace");
269
+ const invalid2 = /* @__PURE__ */ __name(() => {
270
+ throw new SyntaxError("Ambiguous JWT JSON");
271
+ }, "invalid");
272
+ const string = /* @__PURE__ */ __name(() => {
273
+ const start = offset++;
274
+ while (offset < source.length) {
275
+ const current = source[offset++];
276
+ if (current === '"') return JSON.parse(source.slice(start, offset));
277
+ if (current === "\\") offset++;
278
+ }
279
+ return invalid2();
280
+ }, "string");
281
+ const value = /* @__PURE__ */ __name((depth) => {
282
+ if (depth > 8) invalid2();
283
+ whitespace();
284
+ const opening = source[offset];
285
+ if (opening === '"') {
286
+ string();
287
+ return;
288
+ }
289
+ if (opening === "{" || opening === "[") {
290
+ const close = opening === "{" ? "}" : "]";
291
+ offset++;
292
+ whitespace();
293
+ if (source[offset] === close) {
294
+ offset++;
295
+ return;
296
+ }
297
+ const names = /* @__PURE__ */ new Set();
298
+ let count = 0;
299
+ while (offset < source.length) {
300
+ if (++count > 256) invalid2();
301
+ if (opening === "{") {
302
+ whitespace();
303
+ if (source[offset] !== '"') invalid2();
304
+ const key = string();
305
+ if (names.has(key) || key === "__proto__" || key === "constructor" || key === "prototype") invalid2();
306
+ names.add(key);
307
+ whitespace();
308
+ if (source[offset++] !== ":") invalid2();
309
+ }
310
+ value(depth + 1);
311
+ whitespace();
312
+ if (source[offset] === close) {
313
+ offset++;
314
+ return;
315
+ }
316
+ if (source[offset++] !== ",") invalid2();
317
+ }
318
+ return invalid2();
319
+ }
320
+ const literal = /^(?:true|false|null|-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)/.exec(source.slice(offset));
321
+ if (!literal) return invalid2();
322
+ offset += literal[0].length;
323
+ }, "value");
324
+ value(0);
325
+ whitespace();
326
+ if (offset !== source.length) invalid2();
327
+ const parsed = JSON.parse(source, (_key, item) => {
328
+ if (typeof item === "number" && !Number.isFinite(item)) invalid2();
329
+ return item;
330
+ });
331
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) invalid2();
332
+ return parsed;
333
+ }
334
+ __name(parseJwtObject, "parseJwtObject");
335
+
336
+ // src/http.ts
337
+ function authorizationArgs(auth) {
338
+ return typeof auth === "function" ? {
339
+ authorization: auth
340
+ } : typeof auth === "string" ? {
341
+ token: auth,
342
+ tokenType: "Bearer"
343
+ } : {
344
+ token: auth.token,
345
+ tokenType: auth.tokenType,
346
+ headers: auth.headers
347
+ };
348
+ }
349
+ __name(authorizationArgs, "authorizationArgs");
350
+ var Transport = class {
351
+ static {
352
+ __name(this, "Transport");
353
+ }
354
+ fetchImpl;
355
+ timeoutMs;
356
+ maxRetries;
357
+ userAgent;
358
+ maxResponseBytes;
359
+ constructor(opts = {}) {
360
+ this.fetchImpl = opts.fetchImpl ?? globalThis.fetch;
361
+ this.timeoutMs = opts.timeoutMs ?? 8e3;
362
+ this.maxRetries = opts.maxRetries ?? 2;
363
+ this.userAgent = opts.userAgent ?? "xeno-account-client/0.1";
364
+ this.maxResponseBytes = opts.maxResponseBytes ?? 1024 * 1024;
365
+ if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs < 1 || this.timeoutMs > 12e4 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes < 1 || this.maxResponseBytes > 8 * 1024 * 1024 || !Number.isSafeInteger(this.maxRetries) || this.maxRetries < 0 || this.maxRetries > 10) throw new TypeError("Account transport deadline and response bound are invalid");
366
+ }
367
+ /** Perform a request and return parsed JSON (or null for empty bodies). */
368
+ async request(args) {
369
+ let body = args.body;
370
+ const headers = {
371
+ ...args.headers
372
+ };
373
+ if (body !== void 0 && typeof body !== "string") {
374
+ try {
375
+ body = JSON.stringify(body);
376
+ } catch {
377
+ throw new AccountError({
378
+ code: "BAD_REQUEST",
379
+ message: "Account request body cannot be serialized"
380
+ });
381
+ }
382
+ headers["content-type"] = "application/json";
383
+ }
384
+ args = Object.freeze({
385
+ ...args,
386
+ body,
387
+ headers: Object.freeze(headers)
388
+ });
389
+ const isMutation = args.method !== "GET";
390
+ const staticProof = args.tokenType === "DPoP" || Object.keys(args.headers ?? {}).some((name) => name.toLowerCase() === "dpop");
391
+ const retrySafe = (!isMutation || Boolean(args.idempotencyKey)) && (!staticProof || Boolean(args.authorization));
392
+ const attempts = retrySafe ? this.maxRetries + 1 : 1;
393
+ let lastErr = null;
394
+ for (let attempt = 0; attempt < attempts; attempt += 1) {
395
+ try {
396
+ return await this.once(args);
397
+ } catch (err) {
398
+ const ae = err instanceof AccountError ? err : new AccountError({
399
+ code: "UNREACHABLE",
400
+ message: "Account request failed before a verified response was received"
401
+ });
402
+ lastErr = ae;
403
+ if (!ae.retryable || attempt === attempts - 1) throw ae;
404
+ await sleep(backoffMs(attempt, ae.retryAfterMs), args.signal);
405
+ }
406
+ }
407
+ throw lastErr ?? new AccountError({
408
+ code: "PLATFORM_ERROR",
409
+ message: "request failed"
410
+ });
411
+ }
412
+ async once(args) {
413
+ const controller = new AbortController();
414
+ const callerAborted = /* @__PURE__ */ __name(() => controller.abort(), "callerAborted");
415
+ args.signal?.addEventListener("abort", callerAborted, {
416
+ once: true
417
+ });
418
+ if (args.signal?.aborted) callerAborted();
419
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
420
+ let res;
421
+ try {
422
+ if (args.signal?.aborted) throw cancellationError();
423
+ let auth;
424
+ if (args.authorization) {
425
+ try {
426
+ auth = await beforeAbort(args.authorization(args.method, args.url), controller.signal);
427
+ } catch (error) {
428
+ throw new AccountError({
429
+ code: error instanceof AccountError ? error.code : "UNREACHABLE",
430
+ message: "Account request authorization unavailable",
431
+ ...error instanceof AccountError ? {
432
+ httpStatus: error.httpStatus,
433
+ retryable: error.retryable
434
+ } : {}
435
+ });
436
+ }
437
+ if (!auth || typeof auth.token !== "string" || !auth.token || auth.token.length > 16384 || /[\r\n]/.test(auth.token) || ![
438
+ "Bearer",
439
+ "DPoP"
440
+ ].includes(auth.tokenType)) throw new AccountError({
441
+ code: "INVALID_TOKEN",
442
+ message: "Account request authorization invalid"
443
+ });
444
+ const proofHeaders = Object.entries(auth.headers ?? {}).filter(([name]) => name.toLowerCase() === "dpop");
445
+ if (auth.tokenType === "DPoP" && (proofHeaders.length !== 1 || typeof proofHeaders[0]?.[1] !== "string" || !proofHeaders[0][1] || proofHeaders[0][1].length > 16384 || /[\r\n]/.test(proofHeaders[0][1]))) throw new AccountError({
446
+ code: "INVALID_TOKEN",
447
+ message: "Account request proof invalid"
448
+ });
449
+ }
450
+ const supplied = Object.fromEntries(Object.entries(args.headers ?? {}).map(([key, value]) => [
451
+ key.toLowerCase(),
452
+ value
453
+ ]));
454
+ if (auth) {
455
+ delete supplied.authorization;
456
+ delete supplied.dpop;
457
+ }
458
+ const headers = {
459
+ accept: "application/json",
460
+ "user-agent": this.userAgent,
461
+ ...supplied,
462
+ ...Object.fromEntries(Object.entries(auth?.headers ?? {}).map(([key, value]) => [
463
+ key.toLowerCase(),
464
+ value
465
+ ]))
466
+ };
467
+ const token = auth?.token ?? args.token;
468
+ if (token) headers["authorization"] = `${auth?.tokenType ?? args.tokenType ?? "Bearer"} ${token}`;
469
+ if (args.idempotencyKey) headers["idempotency-key"] = args.idempotencyKey;
470
+ let payload;
471
+ if (typeof args.body === "string") {
472
+ payload = args.body;
473
+ } else if (args.body !== void 0) {
474
+ headers["content-type"] = "application/json";
475
+ try {
476
+ payload = JSON.stringify(args.body);
477
+ } catch {
478
+ throw new AccountError({
479
+ code: "BAD_REQUEST",
480
+ message: "Account request body cannot be serialized"
481
+ });
482
+ }
483
+ }
484
+ if (controller.signal.aborted) throw new Error("Account response deadline");
485
+ res = await fetchBeforeAbort(this.fetchImpl, args.url, {
486
+ method: args.method,
487
+ headers,
488
+ body: payload,
489
+ signal: controller.signal,
490
+ redirect: "error",
491
+ cache: "no-store",
492
+ credentials: "omit"
493
+ }, controller.signal);
494
+ if (!res.ok) {
495
+ const code = codeForStatus(res.status);
496
+ const oauthError = args.oauthErrorResponse ? await readOAuthError(res, controller.signal) : null;
497
+ throw new AccountError({
498
+ code,
499
+ message: `${args.method} ${safeUrl(args.url)} -> ${res.status}`,
500
+ httpStatus: res.status,
501
+ retryAfterMs: parseRetryAfter(res.headers.get("retry-after")),
502
+ oauthError
503
+ });
504
+ }
505
+ if (res.status === 204 || !res.body) return null;
506
+ const text2 = await readBoundedText(res, controller.signal, this.maxResponseBytes);
507
+ if (!text2) return null;
508
+ try {
509
+ return JSON.parse(text2);
510
+ } catch {
511
+ throw new AccountError({
512
+ code: "INVALID_RESPONSE",
513
+ message: `non-JSON response from ${safeUrl(args.url)}`
514
+ });
515
+ }
516
+ } catch (err) {
517
+ if (args.signal?.aborted) throw cancellationError();
518
+ if (err instanceof AccountError) throw err;
519
+ throw new AccountError({
520
+ code: "UNREACHABLE",
521
+ message: `request to ${safeUrl(args.url)} failed`,
522
+ retryable: true
523
+ });
524
+ } finally {
525
+ controller.abort();
526
+ args.signal?.removeEventListener("abort", callerAborted);
527
+ clearTimeout(timer);
528
+ if (res) cancelBody(res);
529
+ }
530
+ }
531
+ };
532
+ function cancelBody(response) {
533
+ void response.body?.cancel().catch(() => {
534
+ });
535
+ }
536
+ __name(cancelBody, "cancelBody");
537
+ function beforeAbort(pending, signal) {
538
+ return new Promise((resolve, reject) => {
539
+ const aborted = /* @__PURE__ */ __name(() => {
540
+ signal.removeEventListener("abort", aborted);
541
+ reject(new Error("Account response deadline"));
542
+ }, "aborted");
543
+ if (signal.aborted) {
544
+ void pending.catch(() => {
545
+ });
546
+ aborted();
547
+ return;
548
+ }
549
+ signal.addEventListener("abort", aborted, {
550
+ once: true
551
+ });
552
+ pending.then((value) => {
553
+ signal.removeEventListener("abort", aborted);
554
+ if (signal.aborted) aborted();
555
+ else resolve(value);
556
+ }, (error) => {
557
+ signal.removeEventListener("abort", aborted);
558
+ reject(error);
559
+ });
560
+ });
561
+ }
562
+ __name(beforeAbort, "beforeAbort");
563
+ function fetchBeforeAbort(fetchImpl, url, init, signal) {
564
+ const pending = Promise.resolve(fetchImpl(url, init));
565
+ void pending.then((response) => {
566
+ if (signal.aborted) cancelBody(response);
567
+ }, () => {
568
+ });
569
+ return beforeAbort(pending, signal);
570
+ }
571
+ __name(fetchBeforeAbort, "fetchBeforeAbort");
572
+ async function readBoundedText(response, signal, maxBytes) {
573
+ const reader = response.body?.getReader();
574
+ if (!reader) return "";
575
+ let complete = false;
576
+ try {
577
+ const decoder = new TextDecoder("utf-8", {
578
+ fatal: true
579
+ });
580
+ let text2 = "", size = 0;
581
+ while (true) {
582
+ const chunk = await beforeAbort(reader.read(), signal);
583
+ if (chunk.done) {
584
+ complete = true;
585
+ break;
586
+ }
587
+ size += chunk.value.byteLength;
588
+ if (size > maxBytes) throw new AccountError({
589
+ code: "INVALID_RESPONSE",
590
+ message: "Account response exceeds configured bound"
591
+ });
592
+ try {
593
+ text2 += decoder.decode(chunk.value, {
594
+ stream: true
595
+ });
596
+ } catch {
597
+ throw new AccountError({
598
+ code: "INVALID_RESPONSE",
599
+ message: "Account response is not valid UTF-8"
600
+ });
601
+ }
602
+ }
603
+ try {
604
+ return text2 + decoder.decode();
605
+ } catch {
606
+ throw new AccountError({
607
+ code: "INVALID_RESPONSE",
608
+ message: "Account response is not valid UTF-8"
609
+ });
610
+ }
611
+ } finally {
612
+ if (!complete) void reader.cancel().catch(() => {
613
+ });
614
+ reader.releaseLock();
615
+ }
616
+ }
617
+ __name(readBoundedText, "readBoundedText");
618
+ async function readOAuthError(response, signal) {
619
+ try {
620
+ const body = parseJwtObject(await readBoundedText(response, signal, 4096));
621
+ const code = body.error;
622
+ return typeof code === "string" && [
623
+ "invalid_grant",
624
+ "invalid_client",
625
+ "invalid_scope",
626
+ "invalid_request",
627
+ "unauthorized_client",
628
+ "unsupported_grant_type",
629
+ "authorization_pending",
630
+ "slow_down",
631
+ "access_denied",
632
+ "expired_token",
633
+ "use_dpop_nonce",
634
+ "invalid_dpop_proof"
635
+ ].includes(code) ? code : null;
636
+ } catch {
637
+ return null;
638
+ }
639
+ }
640
+ __name(readOAuthError, "readOAuthError");
641
+ function backoffMs(attempt, retryAfterMs) {
642
+ if (retryAfterMs && retryAfterMs > 0) return Math.min(retryAfterMs, 1e4);
643
+ return Math.min(200 * (2 ** attempt + (attempt === 0 ? 0 : 1)), 5e3);
644
+ }
645
+ __name(backoffMs, "backoffMs");
646
+ function parseRetryAfter(header) {
647
+ if (!header) return null;
648
+ const seconds = Number(header);
649
+ return Number.isFinite(seconds) ? seconds * 1e3 : null;
650
+ }
651
+ __name(parseRetryAfter, "parseRetryAfter");
652
+ function cancellationError() {
653
+ return new AccountError({
654
+ code: "BAD_REQUEST",
655
+ message: "Account request was cancelled; outcome may be unconfirmed",
656
+ retryable: false
657
+ });
658
+ }
659
+ __name(cancellationError, "cancellationError");
660
+ function sleep(ms, signal) {
661
+ return new Promise((resolve, reject) => {
662
+ const timer = setTimeout(done, ms);
663
+ function cleanup() {
664
+ clearTimeout(timer);
665
+ signal?.removeEventListener("abort", aborted);
666
+ }
667
+ __name(cleanup, "cleanup");
668
+ function done() {
669
+ cleanup();
670
+ resolve();
671
+ }
672
+ __name(done, "done");
673
+ function aborted() {
674
+ cleanup();
675
+ reject(cancellationError());
676
+ }
677
+ __name(aborted, "aborted");
678
+ signal?.addEventListener("abort", aborted, {
679
+ once: true
680
+ });
681
+ if (signal?.aborted) aborted();
682
+ });
683
+ }
684
+ __name(sleep, "sleep");
685
+ function safeUrl(url) {
686
+ try {
687
+ const u = new URL(url);
688
+ return u.origin;
689
+ } catch {
690
+ return "[invalid account URL]";
691
+ }
692
+ }
693
+ __name(safeUrl, "safeUrl");
694
+
695
+ // src/account.ts
696
+ var AccountClient = class {
697
+ static {
698
+ __name(this, "AccountClient");
699
+ }
700
+ base;
701
+ transport;
702
+ constructor(base2, transport) {
703
+ this.base = base2;
704
+ this.transport = transport;
705
+ }
706
+ /** Resolve a token to its account, or throw an AccountError. */
707
+ async me(auth) {
708
+ let raw;
709
+ try {
710
+ raw = await this.transport.request({
711
+ method: "GET",
712
+ url: `${this.base}/api/v2/me`,
713
+ ...authorizationArgs(auth)
714
+ });
715
+ } catch (err) {
716
+ const isDpop = typeof auth === "object" && auth.tokenType === "DPoP";
717
+ if (err instanceof AccountError && err.code === "NOT_FOUND" && !isDpop) {
718
+ raw = await this.transport.request({
719
+ method: "GET",
720
+ url: `${this.base}/api/auth/me`,
721
+ ...authorizationArgs(auth)
722
+ });
723
+ } else {
724
+ throw err;
725
+ }
726
+ }
727
+ const account = normalize(raw);
728
+ if (!account) {
729
+ throw new AccountError({
730
+ code: "INVALID_RESPONSE",
731
+ message: "/me returned an unrecognised shape"
732
+ });
733
+ }
734
+ return account;
735
+ }
736
+ };
737
+ function normalize(body) {
738
+ if (!body || typeof body !== "object") return null;
739
+ const root = body;
740
+ const user = root["user"] ?? root["data"] ?? root;
741
+ if (!user || typeof user !== "object") return null;
742
+ const id5 = str(user["id"]);
743
+ const email = str(user["email"]);
744
+ if (!id5 || !email) return null;
745
+ const linked2 = Array.isArray(user["linkedSurfaces"]) ? [
746
+ ...new Set(user["linkedSurfaces"].map(normalizeSurface).filter(isSurface))
747
+ ] : [];
748
+ const parsed = accountSchema.safeParse({
749
+ id: id5,
750
+ email,
751
+ username: str(user["username"]) ?? null,
752
+ displayName: str(user["display_name"]) ?? str(user["displayName"]) ?? null,
753
+ avatarUrl: str(user["avatar_url"]) ?? str(user["avatarUrl"]) ?? null,
754
+ emailVerified: Boolean(user["email_verified"] ?? user["emailVerified"] ?? false),
755
+ linkedSurfaces: linked2
756
+ });
757
+ return parsed.success ? parsed.data : null;
758
+ }
759
+ __name(normalize, "normalize");
760
+ function str(v) {
761
+ return typeof v === "string" && v.length > 0 ? v : void 0;
762
+ }
763
+ __name(str, "str");
764
+ function normalizeSurface(value) {
765
+ if (typeof value !== "string") return void 0;
766
+ const parsed = surfaceSchema.safeParse(value.trim().toLowerCase().replace(/-/g, "_"));
767
+ return parsed.success ? parsed.data : void 0;
768
+ }
769
+ __name(normalizeSurface, "normalizeSurface");
770
+ function isSurface(value) {
771
+ return value !== void 0;
772
+ }
773
+ __name(isSurface, "isSurface");
774
+
775
+ // src/ledger.ts
776
+ var LedgerClient = class {
777
+ static {
778
+ __name(this, "LedgerClient");
779
+ }
780
+ apiBase;
781
+ transport;
782
+ constructor(apiBase, transport) {
783
+ this.apiBase = apiBase;
784
+ this.transport = transport;
785
+ }
786
+ /** Posted / pending / available balance for the token's account. */
787
+ async getBalance(auth) {
788
+ const raw = await this.transport.request({
789
+ method: "GET",
790
+ url: `${this.apiBase}/api/v2/ledger/balance`,
791
+ ...authorizationArgs(auth)
792
+ });
793
+ return parse(balanceSchema, raw);
794
+ }
795
+ /**
796
+ * Record a usage event (the meter). Idempotent on `transactionId`; a duplicate
797
+ * returns `{ duplicate: true }` and does not charge again.
798
+ */
799
+ async recordUsage(auth, event) {
800
+ const e = usageEventSchema.parse(event);
801
+ const raw = await this.transport.request({
802
+ method: "POST",
803
+ url: `${this.apiBase}/api/v2/ledger/usage`,
804
+ ...authorizationArgs(auth),
805
+ body: e,
806
+ idempotencyKey: e.transactionId
807
+ });
808
+ return parse(usageResultSchema, raw);
809
+ }
810
+ /**
811
+ * Reserve credits for a per-use action (phase 1 of two-phase spend). Rejected
812
+ * with `INSUFFICIENT_CREDITS` if `available < amount`. Idempotent on `holdId`.
813
+ */
814
+ async hold(auth, req) {
815
+ const r = holdRequestSchema.parse(req);
816
+ const raw = await this.transport.request({
817
+ method: "POST",
818
+ url: `${this.apiBase}/api/v2/ledger/holds`,
819
+ ...authorizationArgs(auth),
820
+ body: r,
821
+ idempotencyKey: r.holdId
822
+ });
823
+ return parse(holdSchema, raw);
824
+ }
825
+ /**
826
+ * Settle a hold for the actual cost (phase 2). Posting less than the held
827
+ * amount auto-restores the remainder. Idempotent on `holdId`.
828
+ */
829
+ async settle(auth, holdId, actualCostMicro) {
830
+ const raw = await this.transport.request({
831
+ method: "POST",
832
+ url: `${this.apiBase}/api/v2/ledger/holds/${encodeURIComponent(holdId)}/settle`,
833
+ ...authorizationArgs(auth),
834
+ body: {
835
+ actualCostMicro
836
+ },
837
+ idempotencyKey: `${holdId}:settle`
838
+ });
839
+ return parse(holdSchema, raw);
840
+ }
841
+ /** Release a hold without charging (failure/cancel). Idempotent on `holdId`. */
842
+ async void(auth, holdId) {
843
+ const raw = await this.transport.request({
844
+ method: "POST",
845
+ url: `${this.apiBase}/api/v2/ledger/holds/${encodeURIComponent(holdId)}/void`,
846
+ ...authorizationArgs(auth),
847
+ body: {},
848
+ idempotencyKey: `${holdId}:void`
849
+ });
850
+ return parse(holdSchema, raw);
851
+ }
852
+ };
853
+ function parse(schema, raw) {
854
+ const r = schema.safeParse(raw);
855
+ if (!r.success || r.data === void 0) {
856
+ throw new AccountError({
857
+ code: "INVALID_RESPONSE",
858
+ message: "ledger returned an unrecognised shape"
859
+ });
860
+ }
861
+ return r.data;
862
+ }
863
+ __name(parse, "parse");
864
+
865
+ // src/authz.ts
866
+ var AuthzClient = class {
867
+ static {
868
+ __name(this, "AuthzClient");
869
+ }
870
+ apiBase;
871
+ transport;
872
+ constructor(apiBase, transport) {
873
+ this.apiBase = apiBase;
874
+ this.transport = transport;
875
+ }
876
+ async check(auth, check) {
877
+ const raw = await this.transport.request({
878
+ method: "POST",
879
+ url: `${this.apiBase}/api/v2/authz/check`,
880
+ ...authorizationArgs(auth),
881
+ body: check
882
+ });
883
+ const parsed = authzResultSchema.safeParse(raw);
884
+ if (!parsed.success) {
885
+ throw new AccountError({
886
+ code: "INVALID_RESPONSE",
887
+ message: "authz returned an unrecognised shape"
888
+ });
889
+ }
890
+ return parsed.data;
891
+ }
892
+ };
893
+
894
+ // src/workspaces.ts
895
+ var import_zod3 = require("zod");
896
+
897
+ // src/workspaceMembership.ts
898
+ var import_zod2 = require("zod");
899
+ var id = import_zod2.z.string().uuid();
900
+ var timestamp = import_zod2.z.string().datetime({
901
+ offset: true
902
+ });
903
+ var role = import_zod2.z.enum([
904
+ "admin",
905
+ "member",
906
+ "viewer"
907
+ ]);
908
+ var membershipMutationSchema = import_zod2.z.discriminatedUnion("action", [
909
+ import_zod2.z.object({
910
+ action: import_zod2.z.literal("invite.create"),
911
+ email: import_zod2.z.string().email().max(320).regex(/^[^\x00-\x20\x7f]+$/),
912
+ role
913
+ }).strict(),
914
+ import_zod2.z.object({
915
+ action: import_zod2.z.literal("invite.revoke"),
916
+ inviteId: id
917
+ }).strict(),
918
+ import_zod2.z.object({
919
+ action: import_zod2.z.literal("invite.resend"),
920
+ inviteId: id
921
+ }).strict(),
922
+ import_zod2.z.object({
923
+ action: import_zod2.z.literal("member.role"),
924
+ memberId: id,
925
+ role
926
+ }).strict(),
927
+ import_zod2.z.object({
928
+ action: import_zod2.z.literal("member.remove"),
929
+ memberId: id
930
+ }).strict(),
931
+ import_zod2.z.object({
932
+ action: import_zod2.z.literal("owner.transfer"),
933
+ newOwnerId: id
934
+ }).strict()
935
+ ]);
936
+ var base = {
937
+ operation_id: id,
938
+ workspace_id: id,
939
+ actor_user_id: id,
940
+ client_id: import_zod2.z.string().regex(/^[a-zA-Z0-9._-]{1,128}$/),
941
+ committed_at: timestamp
942
+ };
943
+ var invite = import_zod2.z.object({
944
+ id,
945
+ workspace_id: id,
946
+ invited_email: import_zod2.z.string().email(),
947
+ role,
948
+ status: import_zod2.z.enum([
949
+ "pending",
950
+ "revoked"
951
+ ]),
952
+ expires_at: timestamp
953
+ }).strict();
954
+ var delivery = import_zod2.z.object({
955
+ id,
956
+ state: import_zod2.z.literal("queued")
957
+ }).strict();
958
+ var membershipCommittedSchema = import_zod2.z.discriminatedUnion("action", [
959
+ import_zod2.z.object({
960
+ ...base,
961
+ action: import_zod2.z.literal("invite.create"),
962
+ result: import_zod2.z.object({
963
+ invite,
964
+ delivery
965
+ }).strict()
966
+ }).strict(),
967
+ import_zod2.z.object({
968
+ ...base,
969
+ action: import_zod2.z.literal("invite.resend"),
970
+ result: import_zod2.z.object({
971
+ invite,
972
+ delivery
973
+ }).strict()
974
+ }).strict(),
975
+ import_zod2.z.object({
976
+ ...base,
977
+ action: import_zod2.z.literal("invite.revoke"),
978
+ result: import_zod2.z.object({
979
+ invite
980
+ }).strict()
981
+ }).strict(),
982
+ import_zod2.z.object({
983
+ ...base,
984
+ action: import_zod2.z.literal("member.role"),
985
+ result: import_zod2.z.object({
986
+ memberId: id,
987
+ role
988
+ }).strict()
989
+ }).strict(),
990
+ import_zod2.z.object({
991
+ ...base,
992
+ action: import_zod2.z.literal("member.remove"),
993
+ result: import_zod2.z.object({
994
+ memberId: id
995
+ }).strict()
996
+ }).strict(),
997
+ import_zod2.z.object({
998
+ ...base,
999
+ action: import_zod2.z.literal("owner.transfer"),
1000
+ result: import_zod2.z.object({
1001
+ memberId: id,
1002
+ previousOwnerId: id
1003
+ }).strict()
1004
+ }).strict()
1005
+ ]);
1006
+ var membershipRejectedSchema = import_zod2.z.object({
1007
+ ...base,
1008
+ action: import_zod2.z.enum([
1009
+ "invite.create",
1010
+ "invite.resend",
1011
+ "invite.revoke",
1012
+ "member.role",
1013
+ "member.remove",
1014
+ "owner.transfer"
1015
+ ]),
1016
+ rejection: import_zod2.z.enum([
1017
+ "invalid_membership_request",
1018
+ "member_not_found",
1019
+ "owner_transfer_required",
1020
+ "owner_target_not_member",
1021
+ "invite_not_found",
1022
+ "invite_already_pending",
1023
+ "already_member",
1024
+ "seat_limit"
1025
+ ])
1026
+ }).strict();
1027
+ var membershipAbandonedSchema = membershipRejectedSchema.omit({
1028
+ rejection: true
1029
+ }).extend({
1030
+ abandoned: import_zod2.z.literal(true),
1031
+ request: membershipMutationSchema
1032
+ }).strict();
1033
+ var membershipOperationSchema = import_zod2.z.union([
1034
+ membershipCommittedSchema,
1035
+ membershipRejectedSchema,
1036
+ membershipAbandonedSchema
1037
+ ]);
1038
+ var membershipDeliverySchema = import_zod2.z.object({
1039
+ id,
1040
+ state: import_zod2.z.enum([
1041
+ "queued",
1042
+ "accepted",
1043
+ "skipped",
1044
+ "unknown"
1045
+ ])
1046
+ }).strict();
1047
+ var WorkspaceMembershipMutationError = class extends AccountError {
1048
+ static {
1049
+ __name(this, "WorkspaceMembershipMutationError");
1050
+ }
1051
+ operationId;
1052
+ outcome = "uncertain";
1053
+ constructor(operationId) {
1054
+ super({
1055
+ code: "PLATFORM_ERROR",
1056
+ message: "Workspace membership acknowledgement is uncertain. Read back the same operation.",
1057
+ retryable: false
1058
+ }), this.operationId = operationId;
1059
+ }
1060
+ };
1061
+ function assertMembershipOperation(workspaceId, operationId, operation3, request) {
1062
+ if (operation3.workspace_id.toLowerCase() !== workspaceId.toLowerCase() || operation3.operation_id.toLowerCase() !== operationId.toLowerCase() || request && operation3.action !== request.action) throw new Error("Foreign membership receipt");
1063
+ if ("rejection" in operation3) return;
1064
+ if ("abandoned" in operation3) {
1065
+ if (operation3.request.action !== operation3.action || request && JSON.stringify(membershipMutationSchema.parse(request)) !== JSON.stringify(operation3.request)) throw new Error("Wrong abandoned membership intent");
1066
+ return;
1067
+ }
1068
+ if (operation3.action.startsWith("invite.")) {
1069
+ if (!("invite" in operation3.result) || operation3.result.invite.workspace_id !== operation3.workspace_id || operation3.result.invite.status !== (operation3.action === "invite.revoke" ? "revoked" : "pending")) throw new Error("Foreign invitation receipt");
1070
+ if (request && "inviteId" in request && operation3.result.invite.id !== request.inviteId) throw new Error("Wrong invitation target");
1071
+ if (request?.action === "invite.create" && (operation3.result.invite.invited_email !== request.email.toLowerCase() || operation3.result.invite.role !== request.role)) throw new Error("Wrong invitation intent");
1072
+ } else if ("memberId" in operation3.result) {
1073
+ if (request && "memberId" in request && operation3.result.memberId !== request.memberId) throw new Error("Wrong member target");
1074
+ if (request?.action === "member.role" && (!("role" in operation3.result) || operation3.result.role !== request.role)) throw new Error("Wrong member role");
1075
+ if (operation3.action === "owner.transfer" && (operation3.result.previousOwnerId !== operation3.actor_user_id || request?.action === "owner.transfer" && operation3.result.memberId !== request.newOwnerId)) throw new Error("Wrong owner target");
1076
+ }
1077
+ }
1078
+ __name(assertMembershipOperation, "assertMembershipOperation");
1079
+
1080
+ // src/workspaces.ts
1081
+ var workspaceRoleSchema = import_zod3.z.enum([
1082
+ "owner",
1083
+ "admin",
1084
+ "member",
1085
+ "viewer"
1086
+ ]);
1087
+ var workspaceInviteRoleSchema = import_zod3.z.enum([
1088
+ "admin",
1089
+ "member",
1090
+ "viewer"
1091
+ ]);
1092
+ var id2 = import_zod3.z.string().uuid();
1093
+ var timestamp2 = import_zod3.z.string().datetime({
1094
+ offset: true
1095
+ });
1096
+ var workspaceSchema = import_zod3.z.object({
1097
+ id: id2,
1098
+ owner_user_id: id2,
1099
+ // What the server SAYS a workspace is, read as given. It was an enum of personal and team; the server added
1100
+ // company workspaces on 2026-10-16 and one of them made the whole list an INVALID_RESPONSE, so an account in
1101
+ // a company could list and link nothing (owner's account: 2 company workspaces, 2026-11-12). A caller decides
1102
+ // which types it knows. Creating one keeps its own strict list (see `mutateAccount`).
1103
+ workspace_type: import_zod3.z.string().min(1).max(64),
1104
+ name: import_zod3.z.string().min(1),
1105
+ slug: import_zod3.z.string().min(1),
1106
+ status: import_zod3.z.string().min(1),
1107
+ created_at: timestamp2,
1108
+ updated_at: timestamp2,
1109
+ metadata: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()),
1110
+ member_role: workspaceRoleSchema.optional(),
1111
+ member_count: import_zod3.z.number().int().nonnegative().optional()
1112
+ });
1113
+ var workspaceMemberSchema = import_zod3.z.object({
1114
+ id: id2,
1115
+ user_id: id2,
1116
+ member_role: workspaceRoleSchema,
1117
+ member_status: import_zod3.z.literal("active"),
1118
+ created_at: timestamp2,
1119
+ user: import_zod3.z.object({
1120
+ username: import_zod3.z.string().nullable(),
1121
+ email: import_zod3.z.string().email(),
1122
+ display_name: import_zod3.z.string().nullable(),
1123
+ avatar_url: import_zod3.z.string().url().nullable()
1124
+ }).optional()
1125
+ });
1126
+ var workspaceInviteSchema = import_zod3.z.object({
1127
+ id: id2,
1128
+ workspace_id: id2,
1129
+ invited_by_user_id: id2,
1130
+ invited_user_id: id2.nullable(),
1131
+ invited_email: import_zod3.z.string().email(),
1132
+ role: workspaceInviteRoleSchema,
1133
+ status: import_zod3.z.enum([
1134
+ "pending",
1135
+ "accepted",
1136
+ "declined",
1137
+ "revoked",
1138
+ "expired"
1139
+ ]),
1140
+ created_at: timestamp2,
1141
+ expires_at: timestamp2.nullable(),
1142
+ workspace_name: import_zod3.z.string().optional(),
1143
+ invited_by_name: import_zod3.z.string().nullable().optional()
1144
+ });
1145
+ var accountOperationIntentSchema = import_zod3.z.discriminatedUnion("action", [
1146
+ import_zod3.z.object({
1147
+ action: import_zod3.z.literal("workspace.create"),
1148
+ name: import_zod3.z.string().trim().min(1).max(128),
1149
+ type: import_zod3.z.literal("team")
1150
+ }).strict(),
1151
+ import_zod3.z.object({
1152
+ action: import_zod3.z.literal("invite.accept"),
1153
+ inviteId: id2
1154
+ }).strict(),
1155
+ import_zod3.z.object({
1156
+ action: import_zod3.z.literal("invite.decline"),
1157
+ inviteId: id2
1158
+ }).strict()
1159
+ ]);
1160
+ var accountOperationSchema = import_zod3.z.object({
1161
+ operation_id: id2,
1162
+ actor_user_id: id2,
1163
+ client_id: import_zod3.z.string().regex(/^[a-zA-Z0-9._-]{1,128}$/),
1164
+ action: import_zod3.z.enum([
1165
+ "workspace.create",
1166
+ "invite.accept",
1167
+ "invite.decline"
1168
+ ]),
1169
+ committed_at: timestamp2,
1170
+ result: import_zod3.z.union([
1171
+ import_zod3.z.object({
1172
+ workspace: workspaceSchema
1173
+ }).strict(),
1174
+ import_zod3.z.object({
1175
+ invite: workspaceInviteSchema
1176
+ }).strict()
1177
+ ])
1178
+ }).strict();
1179
+ var AccountMutationError = class extends AccountError {
1180
+ static {
1181
+ __name(this, "AccountMutationError");
1182
+ }
1183
+ operationId;
1184
+ outcome = "uncertain";
1185
+ constructor(operationId) {
1186
+ super({
1187
+ code: "PLATFORM_ERROR",
1188
+ message: "Account mutation acknowledgement is uncertain. Read back the same operation.",
1189
+ retryable: false
1190
+ }), this.operationId = operationId;
1191
+ }
1192
+ };
1193
+ var workspaceKeyScopeSchema = import_zod3.z.enum([
1194
+ "workspace:read",
1195
+ "workspace:members:read"
1196
+ ]);
1197
+ var keyScopes = import_zod3.z.array(workspaceKeyScopeSchema).min(1).max(2).refine((values) => new Set(values).size === values.length);
1198
+ var workspaceKeySchema = import_zod3.z.object({
1199
+ id: id2,
1200
+ workspace_id: id2,
1201
+ created_by_user_id: id2,
1202
+ name: import_zod3.z.string().min(1).max(100),
1203
+ prefix: import_zod3.z.string().regex(/^xeno-ws-v1_[0-9a-f]{13}$/),
1204
+ scopes: keyScopes,
1205
+ revision: import_zod3.z.number().int().positive(),
1206
+ created_at: timestamp2,
1207
+ expires_at: timestamp2,
1208
+ revoked_at: timestamp2.nullable(),
1209
+ replaced_by: id2.nullable()
1210
+ });
1211
+ var workspaceKeyInputSchema = import_zod3.z.object({
1212
+ name: import_zod3.z.string().trim().min(1).max(100).regex(/^[^\x00-\x1f]+$/),
1213
+ scopes: keyScopes,
1214
+ expires_at: timestamp2.refine((value) => Date.parse(value) > Date.now() && Date.parse(value) <= Date.now() + 90 * 864e5)
1215
+ }).strict();
1216
+ var keySecretSchema = import_zod3.z.string().regex(/^xeno-ws-v1_[0-9a-f]{64}$/);
1217
+ var committedKeyOperationSchema = import_zod3.z.object({
1218
+ operation_id: id2,
1219
+ workspace_id: id2,
1220
+ actor_user_id: id2,
1221
+ client_id: import_zod3.z.string().regex(/^[a-zA-Z0-9._-]{1,128}$/),
1222
+ action: import_zod3.z.enum([
1223
+ "create",
1224
+ "rotate",
1225
+ "revoke"
1226
+ ]),
1227
+ key: workspaceKeySchema,
1228
+ previous_key_id: id2.nullable(),
1229
+ committed_at: timestamp2
1230
+ }).strict();
1231
+ var workspaceKeyRejectionSchema = import_zod3.z.enum([
1232
+ "invalid_workspace_key_request",
1233
+ "invalid_workspace_key_revision",
1234
+ "workspace_key_not_found",
1235
+ "workspace_key_conflict"
1236
+ ]);
1237
+ var rejectedKeyOperationSchema = committedKeyOperationSchema.omit({
1238
+ key: true
1239
+ }).extend({
1240
+ rejection: workspaceKeyRejectionSchema
1241
+ }).strict();
1242
+ var abandonedKeyOperationSchema = committedKeyOperationSchema.omit({
1243
+ key: true
1244
+ }).extend({
1245
+ abandoned: import_zod3.z.literal(true)
1246
+ }).strict();
1247
+ var workspaceKeyOperationSchema = import_zod3.z.union([
1248
+ committedKeyOperationSchema,
1249
+ rejectedKeyOperationSchema,
1250
+ abandonedKeyOperationSchema
1251
+ ]);
1252
+ var keyOperationInput = workspaceKeyInputSchema.extend({
1253
+ expires_at: timestamp2
1254
+ });
1255
+ var keyMutationSchema = import_zod3.z.discriminatedUnion("action", [
1256
+ import_zod3.z.object({
1257
+ action: import_zod3.z.literal("create"),
1258
+ input: keyOperationInput
1259
+ }).strict(),
1260
+ import_zod3.z.object({
1261
+ action: import_zod3.z.literal("rotate"),
1262
+ keyId: id2,
1263
+ expectedRevision: import_zod3.z.number().int().positive(),
1264
+ input: keyOperationInput.partial().optional()
1265
+ }).strict(),
1266
+ import_zod3.z.object({
1267
+ action: import_zod3.z.literal("revoke"),
1268
+ keyId: id2,
1269
+ expectedRevision: import_zod3.z.number().int().positive()
1270
+ }).strict()
1271
+ ]);
1272
+ var WorkspaceKeyMutationError = class extends AccountError {
1273
+ static {
1274
+ __name(this, "WorkspaceKeyMutationError");
1275
+ }
1276
+ operationId;
1277
+ outcome = "uncertain";
1278
+ constructor(operationId) {
1279
+ super({
1280
+ code: "PLATFORM_ERROR",
1281
+ message: "Workspace key mutation acknowledgement is uncertain. Read back the same operation.",
1282
+ retryable: false
1283
+ }), this.operationId = operationId;
1284
+ }
1285
+ };
1286
+ var workspaceKeyCursor = import_zod3.z.string().regex(/^[a-z0-9_-]{1,512}$/i);
1287
+ var success = import_zod3.z.object({
1288
+ success: import_zod3.z.literal(true)
1289
+ });
1290
+ var membersResponse = success.extend({
1291
+ workspace: workspaceSchema,
1292
+ members: import_zod3.z.array(workspaceMemberSchema)
1293
+ });
1294
+ var invitesResponse = success.extend({
1295
+ invites: import_zod3.z.array(workspaceInviteSchema)
1296
+ });
1297
+ var WorkspaceClient = class {
1298
+ static {
1299
+ __name(this, "WorkspaceClient");
1300
+ }
1301
+ transport;
1302
+ authorize;
1303
+ base;
1304
+ constructor(base2, transport, authorize) {
1305
+ this.transport = transport;
1306
+ this.authorize = authorize;
1307
+ const origin = new URL(base2);
1308
+ if (origin.protocol !== "https:" || origin.username || origin.password || origin.search || origin.hash || origin.pathname !== "/") {
1309
+ throw new AccountError({
1310
+ code: "BAD_REQUEST",
1311
+ message: "Workspace API requires an HTTPS origin."
1312
+ });
1313
+ }
1314
+ this.base = origin.origin;
1315
+ }
1316
+ async call(method, path, scope, schema, body, idempotencyKey) {
1317
+ const url = `${this.base}/api${path}`;
1318
+ const raw = await this.transport.request({
1319
+ method,
1320
+ url,
1321
+ ...body === void 0 ? {} : {
1322
+ body
1323
+ },
1324
+ ...idempotencyKey ? {
1325
+ idempotencyKey
1326
+ } : {},
1327
+ authorization: /* @__PURE__ */ __name(async () => {
1328
+ const auth = await this.authorize(method, url, {
1329
+ scopes: [
1330
+ scope
1331
+ ],
1332
+ silent: true
1333
+ });
1334
+ if (!auth) throw new AccountError({
1335
+ code: "INVALID_TOKEN",
1336
+ message: "Sign in to manage workspaces."
1337
+ });
1338
+ return auth;
1339
+ }, "authorization")
1340
+ });
1341
+ const parsed = schema.safeParse(raw);
1342
+ if (!parsed.success) throw new AccountError({
1343
+ code: "INVALID_RESPONSE",
1344
+ message: "Invalid workspace response."
1345
+ });
1346
+ return parsed.data;
1347
+ }
1348
+ async list() {
1349
+ return (await this.call("GET", "/workspaces", "team:read", success.extend({
1350
+ workspaces: import_zod3.z.array(workspaceSchema)
1351
+ }))).workspaces;
1352
+ }
1353
+ async keys(workspaceId, options = {}) {
1354
+ const input = import_zod3.z.object({
1355
+ cursor: workspaceKeyCursor.optional(),
1356
+ limit: import_zod3.z.number().int().min(1).max(200).optional()
1357
+ }).strict().parse(options);
1358
+ const query = new URLSearchParams();
1359
+ if (input.cursor !== void 0) query.set("cursor", input.cursor);
1360
+ if (input.limit !== void 0) query.set("limit", String(input.limit));
1361
+ const result = await this.call("GET", `/workspaces/${id2.parse(workspaceId)}/api-keys${query.size ? `?${query}` : ""}`, "team:manage", success.extend({
1362
+ keys: import_zod3.z.array(workspaceKeySchema).max(200),
1363
+ next_cursor: workspaceKeyCursor.nullable()
1364
+ }));
1365
+ const { keys, next_cursor } = result;
1366
+ if (keys.some((key) => key.workspace_id.toLowerCase() !== workspaceId.toLowerCase())) throw new AccountError({
1367
+ code: "INVALID_RESPONSE",
1368
+ message: "Workspace key response belongs to another workspace."
1369
+ });
1370
+ return {
1371
+ keys,
1372
+ next_cursor
1373
+ };
1374
+ }
1375
+ async createKey(workspaceId, input) {
1376
+ const body = workspaceKeyInputSchema.parse(input);
1377
+ const response = await this.call("POST", `/workspaces/${id2.parse(workspaceId)}/api-keys`, "team:manage", success.extend({
1378
+ key: workspaceKeySchema,
1379
+ secret: keySecretSchema
1380
+ }), body);
1381
+ this.assertKeyReceipt(workspaceId, response.key);
1382
+ return {
1383
+ key: response.key,
1384
+ secret: response.secret
1385
+ };
1386
+ }
1387
+ async keyOperation(workspaceId, operationId) {
1388
+ const workspace = id2.parse(workspaceId), operation3 = id2.parse(operationId);
1389
+ const response = await this.call("GET", `/workspaces/${workspace}/api-keys/operations/${operation3}`, "team:manage", import_zod3.z.discriminatedUnion("state", [
1390
+ import_zod3.z.object({
1391
+ success: import_zod3.z.literal(true),
1392
+ state: import_zod3.z.literal("not-observed"),
1393
+ operation: import_zod3.z.null()
1394
+ }).strict(),
1395
+ import_zod3.z.object({
1396
+ success: import_zod3.z.literal(true),
1397
+ state: import_zod3.z.literal("committed"),
1398
+ operation: committedKeyOperationSchema
1399
+ }).strict(),
1400
+ import_zod3.z.object({
1401
+ success: import_zod3.z.literal(true),
1402
+ state: import_zod3.z.literal("rejected"),
1403
+ operation: rejectedKeyOperationSchema
1404
+ }).strict(),
1405
+ import_zod3.z.object({
1406
+ success: import_zod3.z.literal(true),
1407
+ state: import_zod3.z.literal("abandoned"),
1408
+ operation: abandonedKeyOperationSchema
1409
+ }).strict()
1410
+ ]));
1411
+ if (response.state === "not-observed") return {
1412
+ state: response.state,
1413
+ operation: null
1414
+ };
1415
+ this.assertOperation(workspace, operation3, response.operation);
1416
+ if (response.state === "abandoned") return {
1417
+ state: response.state,
1418
+ operation: response.operation
1419
+ };
1420
+ return response.state === "rejected" ? {
1421
+ state: response.state,
1422
+ operation: response.operation
1423
+ } : {
1424
+ state: response.state,
1425
+ operation: response.operation
1426
+ };
1427
+ }
1428
+ async mutateKey(workspaceId, operationId, request) {
1429
+ const workspace = id2.parse(workspaceId), operation3 = id2.parse(operationId), input = keyMutationSchema.parse(request);
1430
+ const path = `/workspaces/${workspace}/api-keys${input.action === "create" ? "" : `/${input.keyId}${input.action === "rotate" ? "/rotate" : ""}`}`;
1431
+ const body = {
1432
+ ...input.action === "revoke" ? {} : input.input,
1433
+ operation_id: operation3,
1434
+ ...input.action === "create" ? {} : {
1435
+ expected_revision: input.expectedRevision
1436
+ }
1437
+ };
1438
+ try {
1439
+ const response = await this.call(input.action === "revoke" ? "DELETE" : "POST", path, "team:manage", import_zod3.z.object({
1440
+ success: import_zod3.z.literal(true),
1441
+ key: workspaceKeySchema.optional(),
1442
+ operation: workspaceKeyOperationSchema,
1443
+ replayed: import_zod3.z.boolean(),
1444
+ secret: keySecretSchema.optional()
1445
+ }).strict(), body);
1446
+ this.assertOperation(workspace, operation3, response.operation);
1447
+ if ("rejection" in response.operation || "abandoned" in response.operation) {
1448
+ if (response.key !== void 0 || response.secret !== void 0 || response.operation.action !== input.action || response.operation.previous_key_id?.toLowerCase() !== (input.action === "create" ? void 0 : input.keyId.toLowerCase())) throw new Error("Invalid rejection receipt");
1449
+ return {
1450
+ operation: response.operation,
1451
+ replayed: response.replayed
1452
+ };
1453
+ }
1454
+ if (!response.key) throw new Error("Missing key");
1455
+ if (response.operation.action !== input.action || JSON.stringify(response.key) !== JSON.stringify(response.operation.key) || response.operation.previous_key_id?.toLowerCase() !== (input.action === "create" ? void 0 : input.keyId.toLowerCase()) || (response.replayed || input.action === "revoke" ? response.secret !== void 0 : response.secret === void 0) || response.secret !== void 0 && !response.secret.startsWith(response.key.prefix)) throw new Error("Invalid receipt");
1456
+ if (input.action === "revoke") {
1457
+ if (response.key.id.toLowerCase() !== input.keyId.toLowerCase() || !response.key.revoked_at || response.key.revision !== input.expectedRevision + 1) throw new Error("Invalid revocation");
1458
+ } else {
1459
+ this.assertKeyReceipt(workspace, response.key);
1460
+ if (input.action === "rotate" && response.key.id.toLowerCase() === input.keyId.toLowerCase()) throw new Error("Invalid rotation");
1461
+ }
1462
+ return {
1463
+ operation: response.operation,
1464
+ replayed: response.replayed,
1465
+ ...response.secret === void 0 ? {} : {
1466
+ secret: response.secret
1467
+ }
1468
+ };
1469
+ } catch {
1470
+ throw new WorkspaceKeyMutationError(operation3);
1471
+ }
1472
+ }
1473
+ assertOperation(workspaceId, operationId, operation3) {
1474
+ if (operation3.workspace_id.toLowerCase() !== workspaceId.toLowerCase() || operation3.operation_id.toLowerCase() !== operationId.toLowerCase()) {
1475
+ throw new AccountError({
1476
+ code: "INVALID_RESPONSE",
1477
+ message: "Workspace operation response belongs to another authority."
1478
+ });
1479
+ }
1480
+ if ("rejection" in operation3 || "abandoned" in operation3) return;
1481
+ if (operation3.key.workspace_id.toLowerCase() !== workspaceId.toLowerCase() || operation3.key.created_by_user_id.toLowerCase() !== operation3.actor_user_id.toLowerCase() && operation3.action !== "revoke") throw new AccountError({
1482
+ code: "INVALID_RESPONSE",
1483
+ message: "Foreign key receipt."
1484
+ });
1485
+ if (operation3.action === "revoke" ? !operation3.key.revoked_at || operation3.key.revision < 2 || operation3.previous_key_id !== operation3.key.id : operation3.key.revoked_at !== null || operation3.key.replaced_by !== null || operation3.key.revision !== 1 || (operation3.action === "create" ? operation3.previous_key_id !== null : operation3.previous_key_id === null || operation3.previous_key_id === operation3.key.id)) {
1486
+ throw new AccountError({
1487
+ code: "INVALID_RESPONSE",
1488
+ message: "Invalid committed workspace key operation."
1489
+ });
1490
+ }
1491
+ }
1492
+ async rotateKey(workspaceId, keyId, expectedRevision, input = {}) {
1493
+ const body = {
1494
+ ...workspaceKeyInputSchema.partial().parse(input),
1495
+ expected_revision: import_zod3.z.number().int().positive().parse(expectedRevision)
1496
+ };
1497
+ const response = await this.call("POST", `/workspaces/${id2.parse(workspaceId)}/api-keys/${id2.parse(keyId)}/rotate`, "team:manage", success.extend({
1498
+ key: workspaceKeySchema,
1499
+ secret: keySecretSchema
1500
+ }), body);
1501
+ this.assertKeyReceipt(workspaceId, response.key);
1502
+ if (response.key.id.toLowerCase() === keyId.toLowerCase()) throw new AccountError({
1503
+ code: "INVALID_RESPONSE",
1504
+ message: "Rotation did not acknowledge a new key identity."
1505
+ });
1506
+ return {
1507
+ key: response.key,
1508
+ secret: response.secret
1509
+ };
1510
+ }
1511
+ async revokeKey(workspaceId, keyId, expectedRevision) {
1512
+ const key = (await this.call("DELETE", `/workspaces/${id2.parse(workspaceId)}/api-keys/${id2.parse(keyId)}`, "team:manage", success.extend({
1513
+ key: workspaceKeySchema
1514
+ }), {
1515
+ expected_revision: import_zod3.z.number().int().positive().parse(expectedRevision)
1516
+ })).key;
1517
+ if (key.workspace_id.toLowerCase() !== workspaceId.toLowerCase() || key.id.toLowerCase() !== keyId.toLowerCase() || !key.revoked_at || key.revision !== expectedRevision + 1) throw new AccountError({
1518
+ code: "INVALID_RESPONSE",
1519
+ message: "Revocation was not acknowledged for the requested key revision."
1520
+ });
1521
+ return key;
1522
+ }
1523
+ assertKeyReceipt(workspaceId, key) {
1524
+ if (key.workspace_id.toLowerCase() !== workspaceId.toLowerCase() || key.revoked_at || key.replaced_by || key.revision !== 1) throw new AccountError({
1525
+ code: "INVALID_RESPONSE",
1526
+ message: "Invalid workspace key creation receipt."
1527
+ });
1528
+ }
1529
+ async create(name, type = "team") {
1530
+ const body = import_zod3.z.object({
1531
+ name: import_zod3.z.string().trim().min(1).max(128),
1532
+ workspace_type: import_zod3.z.enum([
1533
+ "personal",
1534
+ "team"
1535
+ ])
1536
+ }).parse({
1537
+ name,
1538
+ workspace_type: type
1539
+ });
1540
+ return (await this.call("POST", "/workspaces", "team:manage", success.extend({
1541
+ workspace: workspaceSchema
1542
+ }), body)).workspace;
1543
+ }
1544
+ async accountOperation(operationId) {
1545
+ const operation3 = id2.parse(operationId);
1546
+ const response = await this.call("GET", `/account-operations/${operation3}`, "team:manage", import_zod3.z.discriminatedUnion("state", [
1547
+ import_zod3.z.object({
1548
+ success: import_zod3.z.literal(true),
1549
+ state: import_zod3.z.literal("not-observed"),
1550
+ operation: import_zod3.z.null()
1551
+ }).strict(),
1552
+ import_zod3.z.object({
1553
+ success: import_zod3.z.literal(true),
1554
+ state: import_zod3.z.literal("committed"),
1555
+ operation: accountOperationSchema
1556
+ }).strict()
1557
+ ]));
1558
+ if (response.state === "not-observed") return response;
1559
+ if (response.operation.operation_id.toLowerCase() !== operation3.toLowerCase()) throw new AccountError({
1560
+ code: "INVALID_RESPONSE",
1561
+ message: "Account operation response belongs to another operation."
1562
+ });
1563
+ return {
1564
+ state: "committed",
1565
+ operation: response.operation
1566
+ };
1567
+ }
1568
+ async mutateAccount(operationId, request) {
1569
+ const operation3 = id2.parse(operationId), intent = accountOperationIntentSchema.parse(request);
1570
+ const path = intent.action === "workspace.create" ? "/workspaces" : `/workspace-invites/${intent.inviteId}/${intent.action === "invite.accept" ? "accept" : "decline"}`;
1571
+ const body = intent.action === "workspace.create" ? {
1572
+ operation_id: operation3,
1573
+ name: intent.name,
1574
+ workspace_type: intent.type
1575
+ } : {
1576
+ operation_id: operation3
1577
+ };
1578
+ try {
1579
+ const response = await this.call("POST", path, "team:manage", import_zod3.z.object({
1580
+ success: import_zod3.z.literal(true),
1581
+ operation: accountOperationSchema,
1582
+ replayed: import_zod3.z.boolean(),
1583
+ workspace: workspaceSchema.optional()
1584
+ }).strict(), body, operation3);
1585
+ if (response.operation.operation_id.toLowerCase() !== operation3.toLowerCase() || response.operation.action !== intent.action) throw new Error("foreign operation");
1586
+ if (intent.action === "workspace.create" && (!("workspace" in response.operation.result) || JSON.stringify(response.workspace) !== JSON.stringify(response.operation.result.workspace))) throw new Error("foreign workspace");
1587
+ if (intent.action !== "workspace.create" && (!("invite" in response.operation.result) || response.operation.result.invite.id.toLowerCase() !== intent.inviteId.toLowerCase())) throw new Error("foreign invite");
1588
+ return {
1589
+ operation: response.operation,
1590
+ replayed: response.replayed
1591
+ };
1592
+ } catch {
1593
+ throw new AccountMutationError(operation3);
1594
+ }
1595
+ }
1596
+ async select(workspaceId) {
1597
+ await this.call("POST", `/workspaces/${id2.parse(workspaceId)}/select`, "team:read", success);
1598
+ }
1599
+ async members(workspaceId) {
1600
+ return this.call("GET", `/workspaces/${id2.parse(workspaceId)}/members`, "team:read", membersResponse);
1601
+ }
1602
+ async updateMember(workspaceId, memberId, role2) {
1603
+ await this.call("PATCH", `/workspaces/${id2.parse(workspaceId)}/members/${id2.parse(memberId)}`, "team:manage", success, {
1604
+ member_role: workspaceInviteRoleSchema.parse(role2)
1605
+ });
1606
+ }
1607
+ async membershipOperation(workspaceId, operationId) {
1608
+ const ws = id2.parse(workspaceId), op = id2.parse(operationId);
1609
+ const response = await this.call("GET", `/workspaces/${ws}/membership-operations/${op}`, "team:manage", import_zod3.z.discriminatedUnion("state", [
1610
+ import_zod3.z.object({
1611
+ success: import_zod3.z.literal(true),
1612
+ state: import_zod3.z.literal("not-observed"),
1613
+ operation: import_zod3.z.null()
1614
+ }).strict(),
1615
+ import_zod3.z.object({
1616
+ success: import_zod3.z.literal(true),
1617
+ state: import_zod3.z.literal("committed"),
1618
+ operation: membershipCommittedSchema,
1619
+ delivery: membershipDeliverySchema.optional()
1620
+ }).strict(),
1621
+ import_zod3.z.object({
1622
+ success: import_zod3.z.literal(true),
1623
+ state: import_zod3.z.literal("rejected"),
1624
+ operation: membershipRejectedSchema
1625
+ }).strict(),
1626
+ import_zod3.z.object({
1627
+ success: import_zod3.z.literal(true),
1628
+ state: import_zod3.z.literal("abandoned"),
1629
+ operation: membershipAbandonedSchema
1630
+ }).strict()
1631
+ ]));
1632
+ if (response.state === "not-observed") return {
1633
+ state: response.state,
1634
+ operation: null
1635
+ };
1636
+ assertMembershipOperation(ws, op, response.operation);
1637
+ if (response.state === "abandoned") return {
1638
+ state: response.state,
1639
+ operation: response.operation
1640
+ };
1641
+ if (response.state === "committed" && response.delivery && (!("delivery" in response.operation.result) || response.operation.result.delivery.id !== response.delivery.id)) throw new AccountError({
1642
+ code: "INVALID_RESPONSE",
1643
+ message: "Foreign invitation delivery state."
1644
+ });
1645
+ return response.state === "committed" ? {
1646
+ state: response.state,
1647
+ operation: response.operation,
1648
+ ...response.delivery ? {
1649
+ delivery: response.delivery
1650
+ } : {}
1651
+ } : {
1652
+ state: response.state,
1653
+ operation: response.operation
1654
+ };
1655
+ }
1656
+ async mutateMembership(workspaceId, operationId, request) {
1657
+ const ws = id2.parse(workspaceId), op = id2.parse(operationId), input = membershipMutationSchema.parse(request);
1658
+ const path = input.action === "invite.create" ? "/invites" : "inviteId" in input ? `/invites/${input.inviteId}${input.action === "invite.resend" ? "/resend" : ""}` : "memberId" in input ? `/members/${input.memberId}` : "/owner-transfer";
1659
+ const method = input.action === "member.role" ? "PATCH" : input.action === "invite.revoke" || input.action === "member.remove" ? "DELETE" : "POST";
1660
+ const body = {
1661
+ operation_id: op,
1662
+ ...input.action === "invite.create" ? {
1663
+ email: input.email,
1664
+ role: input.role
1665
+ } : input.action === "member.role" ? {
1666
+ member_role: input.role
1667
+ } : input.action === "owner.transfer" ? {
1668
+ new_owner_user_id: input.newOwnerId
1669
+ } : {}
1670
+ };
1671
+ try {
1672
+ const response = await this.call(method, `/workspaces/${ws}${path}`, "team:manage", import_zod3.z.object({
1673
+ success: import_zod3.z.literal(true),
1674
+ operation: membershipOperationSchema,
1675
+ replayed: import_zod3.z.boolean()
1676
+ }).strict(), body);
1677
+ assertMembershipOperation(ws, op, response.operation, input);
1678
+ return {
1679
+ operation: response.operation,
1680
+ replayed: response.replayed
1681
+ };
1682
+ } catch {
1683
+ throw new WorkspaceMembershipMutationError(op);
1684
+ }
1685
+ }
1686
+ /** Explicit user-requested settlement only. A lost ACK remains uncertain; never
1687
+ * synthesize abandonment locally or automatically retry with a new ID. */
1688
+ async abandonMembershipOperation(workspaceId, operationId, request) {
1689
+ const ws = id2.parse(workspaceId), op = id2.parse(operationId), input = membershipMutationSchema.parse(request);
1690
+ try {
1691
+ const response = await this.call("POST", `/workspaces/${ws}/membership-operations/${op}/abandon`, "team:manage", import_zod3.z.object({
1692
+ success: import_zod3.z.literal(true),
1693
+ operation: membershipOperationSchema,
1694
+ replayed: import_zod3.z.boolean()
1695
+ }).strict(), {
1696
+ request: input
1697
+ });
1698
+ assertMembershipOperation(ws, op, response.operation, input);
1699
+ return {
1700
+ operation: response.operation,
1701
+ replayed: response.replayed
1702
+ };
1703
+ } catch {
1704
+ throw new WorkspaceMembershipMutationError(op);
1705
+ }
1706
+ }
1707
+ async abandonKeyOperation(workspaceId, operationId, request) {
1708
+ const ws = id2.parse(workspaceId), op = id2.parse(operationId), input = keyMutationSchema.parse(request);
1709
+ const original = {
1710
+ action: input.action,
1711
+ ...input.action === "revoke" ? {} : input.input,
1712
+ ...input.action === "create" ? {} : {
1713
+ id: input.keyId,
1714
+ expected_revision: input.expectedRevision
1715
+ }
1716
+ };
1717
+ try {
1718
+ const response = await this.call("POST", `/workspaces/${ws}/api-keys/operations/${op}/abandon`, "team:manage", import_zod3.z.object({
1719
+ success: import_zod3.z.literal(true),
1720
+ operation: workspaceKeyOperationSchema,
1721
+ replayed: import_zod3.z.boolean()
1722
+ }).strict(), {
1723
+ request: original
1724
+ });
1725
+ this.assertOperation(ws, op, response.operation);
1726
+ if (response.operation.action !== input.action || response.operation.previous_key_id?.toLowerCase() !== (input.action === "create" ? void 0 : input.keyId.toLowerCase())) throw new Error("Wrong key operation intent");
1727
+ return {
1728
+ operation: response.operation,
1729
+ replayed: response.replayed
1730
+ };
1731
+ } catch {
1732
+ throw new WorkspaceKeyMutationError(op);
1733
+ }
1734
+ }
1735
+ async removeMember(workspaceId, memberId) {
1736
+ await this.call("DELETE", `/workspaces/${id2.parse(workspaceId)}/members/${id2.parse(memberId)}`, "team:manage", success);
1737
+ }
1738
+ async transferOwnership(workspaceId, newOwnerUserId) {
1739
+ await this.call("POST", `/workspaces/${id2.parse(workspaceId)}/owner-transfer`, "team:manage", success, {
1740
+ new_owner_user_id: id2.parse(newOwnerUserId)
1741
+ });
1742
+ }
1743
+ async invites(workspaceId) {
1744
+ return (await this.call("GET", `/workspaces/${id2.parse(workspaceId)}/invites`, "team:read", invitesResponse)).invites;
1745
+ }
1746
+ async invite(workspaceId, email, role2 = "member") {
1747
+ const body = {
1748
+ email: import_zod3.z.string().trim().email().parse(email),
1749
+ role: workspaceInviteRoleSchema.parse(role2)
1750
+ };
1751
+ return (await this.call("POST", `/workspaces/${id2.parse(workspaceId)}/invites`, "team:manage", success.extend({
1752
+ invite: workspaceInviteSchema
1753
+ }), body)).invite;
1754
+ }
1755
+ async revokeInvite(workspaceId, inviteId) {
1756
+ await this.call("DELETE", `/workspaces/${id2.parse(workspaceId)}/invites/${id2.parse(inviteId)}`, "team:manage", success);
1757
+ }
1758
+ async resendInvite(workspaceId, inviteId) {
1759
+ await this.call("POST", `/workspaces/${id2.parse(workspaceId)}/invites/${id2.parse(inviteId)}/resend`, "team:manage", success);
1760
+ }
1761
+ async pendingInvites() {
1762
+ return (await this.call("GET", "/workspace-invites", "team:read", invitesResponse)).invites;
1763
+ }
1764
+ async acceptInvite(inviteId) {
1765
+ await this.call("POST", `/workspace-invites/${id2.parse(inviteId)}/accept`, "team:manage", success);
1766
+ }
1767
+ async declineInvite(inviteId) {
1768
+ await this.call("POST", `/workspace-invites/${id2.parse(inviteId)}/decline`, "team:manage", success);
1769
+ }
1770
+ };
1771
+
1772
+ // src/workforce.ts
1773
+ var import_zod4 = require("zod");
1774
+ var uuid = import_zod4.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i).transform((value) => value.toLowerCase());
1775
+ var timestamp3 = import_zod4.z.string().datetime({
1776
+ offset: true
1777
+ });
1778
+ var identifier = import_zod4.z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:/@+-]{0,127}$/);
1779
+ var hash = import_zod4.z.string().regex(/^[a-f0-9]{64}$/);
1780
+ var revision = import_zod4.z.string().max(19).regex(/^[1-9][0-9]*$/).refine((value) => BigInt(value) <= 9223372036854775807n);
1781
+ var text = /* @__PURE__ */ __name((max, empty = false) => import_zod4.z.string().max(max).refine((value) => !value.includes("\0") && (empty || Boolean(value.trim())) && new TextEncoder().encode(value).length <= max), "text");
1782
+ var unique = /* @__PURE__ */ __name((items, key) => new Set(items.map(key)).size === items.length, "unique");
1783
+ var workforceOwnerSchema = import_zod4.z.object({
1784
+ type: import_zod4.z.enum([
1785
+ "user",
1786
+ "workspace"
1787
+ ]),
1788
+ id: uuid
1789
+ }).strict();
1790
+ var skill = import_zod4.z.object({
1791
+ id: identifier,
1792
+ version: identifier,
1793
+ hash
1794
+ }).strict();
1795
+ var secretReference = import_zod4.z.object({
1796
+ name: import_zod4.z.string().regex(/^[A-Z][A-Z0-9_]{0,63}$/),
1797
+ ref: uuid
1798
+ }).strict();
1799
+ var contentShape = {
1800
+ instructions: text(32768, true),
1801
+ skills: import_zod4.z.array(skill).max(64).refine((items) => unique(items, (item) => item.id)),
1802
+ requestedCapabilities: import_zod4.z.array(identifier).max(64).refine((items) => unique(items, (item) => item)),
1803
+ secretReferences: import_zod4.z.array(secretReference).max(32).refine((items) => unique(items, (item) => item.name))
1804
+ };
1805
+ var provenance = import_zod4.z.object({
1806
+ source: import_zod4.z.enum([
1807
+ "authored",
1808
+ "imported"
1809
+ ]),
1810
+ sourceVersion: identifier.optional()
1811
+ }).strict();
1812
+ var license = import_zod4.z.object({
1813
+ identifier
1814
+ }).strict();
1815
+ var workforceDefinitionSchema = import_zod4.z.object({
1816
+ schemaVersion: import_zod4.z.literal(1),
1817
+ ...contentShape,
1818
+ secretReferences: contentShape.secretReferences.optional(),
1819
+ provenance: provenance.optional(),
1820
+ license: license.optional()
1821
+ }).strict();
1822
+ var createBase = {
1823
+ operationId: uuid,
1824
+ owner: workforceOwnerSchema,
1825
+ // Equality precondition only: the server authenticates the actor and refuses
1826
+ // a changed account. This field never selects or grants an acting identity.
1827
+ expectedActorAccountId: uuid.optional(),
1828
+ name: text(200).transform((value) => value.trim()),
1829
+ description: text(4096, true).optional()
1830
+ };
1831
+ var workforceCreateResourceSchema = import_zod4.z.discriminatedUnion("kind", [
1832
+ import_zod4.z.object({
1833
+ ...createBase,
1834
+ kind: import_zod4.z.literal("agent"),
1835
+ definition: workforceDefinitionSchema
1836
+ }).strict(),
1837
+ import_zod4.z.object({
1838
+ ...createBase,
1839
+ kind: import_zod4.z.literal("team")
1840
+ }).strict()
1841
+ ]);
1842
+ var workforceReadOperationSchema = import_zod4.z.object({
1843
+ operationId: uuid,
1844
+ owner: workforceOwnerSchema,
1845
+ expectedActorAccountId: uuid.optional()
1846
+ }).strict();
1847
+ var catalogCursor = import_zod4.z.string().min(1).max(2048).regex(/^[A-Za-z0-9_-]+$/);
1848
+ var workforceListOwnedResourcesSchema = import_zod4.z.object({
1849
+ owner: workforceOwnerSchema,
1850
+ expectedActorAccountId: uuid,
1851
+ limit: import_zod4.z.number().int().min(1).max(100).optional(),
1852
+ kind: import_zod4.z.enum([
1853
+ "agent",
1854
+ "team"
1855
+ ]).optional(),
1856
+ status: import_zod4.z.enum([
1857
+ "active",
1858
+ "archived"
1859
+ ]).optional(),
1860
+ cursor: catalogCursor.optional()
1861
+ }).strict();
1862
+ var resource = import_zod4.z.object({
1863
+ id: uuid,
1864
+ kind: import_zod4.z.enum([
1865
+ "agent",
1866
+ "team"
1867
+ ]),
1868
+ owner: workforceOwnerSchema,
1869
+ createdByUserId: uuid.nullable(),
1870
+ name: text(200),
1871
+ description: text(4096, true),
1872
+ status: import_zod4.z.enum([
1873
+ "active",
1874
+ "archived"
1875
+ ]),
1876
+ revision,
1877
+ createdAt: timestamp3,
1878
+ updatedAt: timestamp3
1879
+ }).strict();
1880
+ var ownedCatalog = import_zod4.z.object({
1881
+ success: import_zod4.z.literal(true),
1882
+ schemaVersion: import_zod4.z.literal(1),
1883
+ scope: import_zod4.z.literal("owned"),
1884
+ owner: workforceOwnerSchema,
1885
+ items: import_zod4.z.array(resource).max(100),
1886
+ nextCursor: catalogCursor.nullable()
1887
+ }).strict();
1888
+ var version = import_zod4.z.object({
1889
+ resourceId: uuid,
1890
+ version: import_zod4.z.number().int().positive(),
1891
+ schemaVersion: import_zod4.z.literal(1),
1892
+ content: import_zod4.z.object(contentShape).strict(),
1893
+ contentHash: hash,
1894
+ provenance: import_zod4.z.union([
1895
+ provenance,
1896
+ import_zod4.z.object({}).strict()
1897
+ ]),
1898
+ license: import_zod4.z.union([
1899
+ license,
1900
+ import_zod4.z.object({}).strict()
1901
+ ]),
1902
+ createdByUserId: uuid.nullable(),
1903
+ createdAt: timestamp3
1904
+ }).strict();
1905
+ var operation = import_zod4.z.object({
1906
+ schemaVersion: import_zod4.z.literal(1),
1907
+ operationId: uuid,
1908
+ action: import_zod4.z.literal("agent.resource.create"),
1909
+ state: import_zod4.z.literal("committed"),
1910
+ owner: workforceOwnerSchema,
1911
+ resourceId: uuid,
1912
+ resourceRevision: revision,
1913
+ agentVersion: import_zod4.z.number().int().positive().nullable(),
1914
+ committedAt: timestamp3
1915
+ }).strict();
1916
+ var committed = import_zod4.z.object({
1917
+ success: import_zod4.z.literal(true),
1918
+ state: import_zod4.z.literal("committed"),
1919
+ operation,
1920
+ resource: resource.nullable(),
1921
+ version: version.nullable(),
1922
+ replayed: import_zod4.z.boolean(),
1923
+ resourceAccess: import_zod4.z.discriminatedUnion("allowed", [
1924
+ import_zod4.z.object({
1925
+ allowed: import_zod4.z.literal(true)
1926
+ }).strict(),
1927
+ import_zod4.z.object({
1928
+ allowed: import_zod4.z.literal(false),
1929
+ reason: import_zod4.z.literal("no_access")
1930
+ }).strict()
1931
+ ])
1932
+ }).strict();
1933
+ var notObserved = import_zod4.z.object({
1934
+ success: import_zod4.z.literal(true),
1935
+ state: import_zod4.z.literal("not-observed"),
1936
+ operation: import_zod4.z.null(),
1937
+ resource: import_zod4.z.null(),
1938
+ version: import_zod4.z.null(),
1939
+ replayed: import_zod4.z.literal(false)
1940
+ }).strict();
1941
+ var WorkforceResourceMutationError = class extends AccountError {
1942
+ static {
1943
+ __name(this, "WorkforceResourceMutationError");
1944
+ }
1945
+ operationId;
1946
+ outcome = "uncertain";
1947
+ reason = "mutation_outcome_unverified";
1948
+ source = "client-observation";
1949
+ owner;
1950
+ constructor(operationId, owner, cause) {
1951
+ super({
1952
+ code: cause instanceof AccountError ? cause.code : "PLATFORM_ERROR",
1953
+ message: "Workforce creation acknowledgement is unverified. Read back the same operation before retrying.",
1954
+ httpStatus: cause instanceof AccountError ? cause.httpStatus : null,
1955
+ retryable: false
1956
+ }), this.operationId = operationId;
1957
+ this.name = "WorkforceResourceMutationError";
1958
+ this.owner = Object.freeze({
1959
+ ...owner
1960
+ });
1961
+ }
1962
+ };
1963
+ var sameOwner = /* @__PURE__ */ __name((left, right) => left.type === right.type && left.id === right.id, "sameOwner");
1964
+ var invalidResponse = /* @__PURE__ */ __name(() => new AccountError({
1965
+ code: "INVALID_RESPONSE",
1966
+ message: "Invalid workforce operation response."
1967
+ }), "invalidResponse");
1968
+ var invalidInput = /* @__PURE__ */ __name(() => new AccountError({
1969
+ code: "BAD_REQUEST",
1970
+ message: "Invalid workforce operation request."
1971
+ }), "invalidInput");
1972
+ function assertData(value, depth = 0, budget = {
1973
+ remaining: 4096
1974
+ }) {
1975
+ if (--budget.remaining < 0 || depth > 8) throw invalidInput();
1976
+ if (value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number") return;
1977
+ if (!value || typeof value !== "object") throw invalidInput();
1978
+ const array = Array.isArray(value);
1979
+ if (array ? Object.getPrototypeOf(value) !== Array.prototype : ![
1980
+ Object.prototype,
1981
+ null
1982
+ ].includes(Object.getPrototypeOf(value))) throw invalidInput();
1983
+ const keys = Reflect.ownKeys(value);
1984
+ if (keys.length > 4096 || array && keys.length !== value.length + 1) throw invalidInput();
1985
+ for (const key of keys) {
1986
+ if (array && key === "length") continue;
1987
+ if (typeof key !== "string" || array && !/^(0|[1-9][0-9]*)$/.test(key)) throw invalidInput();
1988
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
1989
+ if (!descriptor.enumerable || !Object.hasOwn(descriptor, "value")) throw invalidInput();
1990
+ assertData(descriptor.value, depth + 1, budget);
1991
+ }
1992
+ }
1993
+ __name(assertData, "assertData");
1994
+ function parseInput(schema, value) {
1995
+ assertData(value);
1996
+ const parsed = schema.safeParse(value);
1997
+ if (!parsed.success) throw invalidInput();
1998
+ if (new TextEncoder().encode(JSON.stringify(parsed.data)).length > 256 * 1024) throw invalidInput();
1999
+ return parsed.data;
2000
+ }
2001
+ __name(parseInput, "parseInput");
2002
+ var WorkforceClient = class {
2003
+ static {
2004
+ __name(this, "WorkforceClient");
2005
+ }
2006
+ transport;
2007
+ authorize;
2008
+ base;
2009
+ constructor(base2, transport, authorize) {
2010
+ this.transport = transport;
2011
+ this.authorize = authorize;
2012
+ const origin = new URL(base2);
2013
+ if (origin.protocol !== "https:" || origin.username || origin.password || origin.search || origin.hash || origin.pathname !== "/") {
2014
+ throw new AccountError({
2015
+ code: "BAD_REQUEST",
2016
+ message: "Workforce API requires an HTTPS origin."
2017
+ });
2018
+ }
2019
+ this.base = origin.origin;
2020
+ }
2021
+ /** This catalog lists one explicitly owned scope only. It is not an aggregate
2022
+ * of assigned, shared or rented resources and contains no agent definitions. */
2023
+ async listOwnedResources(value) {
2024
+ const input = parseInput(workforceListOwnedResourcesSchema, value);
2025
+ const url = `${this.base}/api/workforce/resources/list`;
2026
+ const raw = await this.transport.request({
2027
+ method: "POST",
2028
+ url,
2029
+ body: input,
2030
+ authorization: /* @__PURE__ */ __name(async () => {
2031
+ const auth = await this.authorize("POST", url, {
2032
+ scopes: [
2033
+ "workforce:read"
2034
+ ],
2035
+ silent: true
2036
+ });
2037
+ if (!auth) throw new AccountError({
2038
+ code: "INVALID_TOKEN",
2039
+ message: "Sign in with workforce read access."
2040
+ });
2041
+ return auth;
2042
+ }, "authorization")
2043
+ });
2044
+ const parsed = ownedCatalog.safeParse(raw);
2045
+ if (!parsed.success) throw invalidResponse();
2046
+ const result = parsed.data;
2047
+ if (!sameOwner(result.owner, input.owner) || result.items.length > (input.limit ?? 50) || !unique(result.items, (item) => item.id) || result.items.some((item) => !sameOwner(item.owner, input.owner) || input.kind !== void 0 && item.kind !== input.kind || item.status !== (input.status ?? "active")) || result.nextCursor !== null && (result.items.length === 0 || result.nextCursor === input.cursor)) throw invalidResponse();
2048
+ return result;
2049
+ }
2050
+ validate(raw, input, creating) {
2051
+ const parsed = (creating ? committed : import_zod4.z.union([
2052
+ committed,
2053
+ notObserved
2054
+ ])).safeParse(raw);
2055
+ if (!parsed.success) throw invalidResponse();
2056
+ const result = parsed.data;
2057
+ if (result.state === "not-observed") return result;
2058
+ const op = result.operation;
2059
+ if (op.operationId !== input.operationId || !sameOwner(op.owner, input.owner)) throw invalidResponse();
2060
+ if (!result.resourceAccess.allowed) {
2061
+ if (result.resource !== null || result.version !== null) throw invalidResponse();
2062
+ return result;
2063
+ }
2064
+ const r = result.resource, v = result.version;
2065
+ if (!r || r.id !== op.resourceId || !sameOwner(r.owner, input.owner) || BigInt(r.revision) < BigInt(op.resourceRevision)) throw invalidResponse();
2066
+ if (r.kind === "team" ? op.agentVersion !== null || v !== null : op.agentVersion === null || !v || v.resourceId !== r.id || v.version !== op.agentVersion) throw invalidResponse();
2067
+ return result;
2068
+ }
2069
+ async createResource(value) {
2070
+ const input = parseInput(workforceCreateResourceSchema, value);
2071
+ let authorizationCompleted = false;
2072
+ try {
2073
+ const url = `${this.base}/api/workforce/resources`;
2074
+ const raw = await this.transport.request({
2075
+ method: "POST",
2076
+ url,
2077
+ body: input,
2078
+ authorization: /* @__PURE__ */ __name(async () => {
2079
+ const auth = await this.authorize("POST", url, {
2080
+ scopes: [
2081
+ "workforce:manage"
2082
+ ],
2083
+ silent: true
2084
+ });
2085
+ if (!auth) throw new AccountError({
2086
+ code: "INVALID_TOKEN",
2087
+ message: "Sign in with workforce management access."
2088
+ });
2089
+ authorizationCompleted = true;
2090
+ return auth;
2091
+ }, "authorization")
2092
+ });
2093
+ const result = this.validate(raw, input, true);
2094
+ if (result.resource && result.resource.kind !== input.kind) throw invalidResponse();
2095
+ if (input.kind === "agent" !== (result.operation.agentVersion !== null)) throw invalidResponse();
2096
+ return result;
2097
+ } catch (error) {
2098
+ if (!authorizationCompleted) throw error;
2099
+ throw new WorkforceResourceMutationError(input.operationId, input.owner, error);
2100
+ }
2101
+ }
2102
+ async readOperation(value) {
2103
+ const input = parseInput(workforceReadOperationSchema, value);
2104
+ const url = `${this.base}/api/workforce/resource-operations/read`;
2105
+ const raw = await this.transport.request({
2106
+ method: "POST",
2107
+ url,
2108
+ body: input,
2109
+ authorization: /* @__PURE__ */ __name(async () => {
2110
+ const auth = await this.authorize("POST", url, {
2111
+ scopes: [
2112
+ "workforce:read"
2113
+ ],
2114
+ silent: true
2115
+ });
2116
+ if (!auth) throw new AccountError({
2117
+ code: "INVALID_TOKEN",
2118
+ message: "Sign in with workforce read access."
2119
+ });
2120
+ return auth;
2121
+ }, "authorization")
2122
+ });
2123
+ return this.validate(raw, input, false);
2124
+ }
2125
+ };
2126
+
2127
+ // src/notifications.ts
2128
+ var import_zod5 = require("zod");
2129
+ var id3 = import_zod5.z.string().uuid();
2130
+ var localId = import_zod5.z.string().regex(/^[a-z0-9_:-]{1,240}$/i);
2131
+ var timestamp4 = import_zod5.z.string().datetime({
2132
+ offset: true
2133
+ });
2134
+ var revision2 = import_zod5.z.union([
2135
+ import_zod5.z.literal("0"),
2136
+ id3
2137
+ ]);
2138
+ var httpsUrl = import_zod5.z.string().max(2048).url().refine((value) => {
2139
+ const parsed = new URL(value);
2140
+ return parsed.protocol === "https:" && !parsed.username && !parsed.password && !parsed.hash;
2141
+ }, "Notification destinations require credential-free HTTPS URLs");
2142
+ var notificationEventSchema = import_zod5.z.enum([
2143
+ "agent.finished",
2144
+ "agent.failed",
2145
+ "agent.cancelled"
2146
+ ]);
2147
+ var notificationChannelSchema = import_zod5.z.enum([
2148
+ "webhook",
2149
+ "slack",
2150
+ "discord"
2151
+ ]);
2152
+ var notificationScopeSchema = import_zod5.z.object({
2153
+ workspaceId: localId,
2154
+ workspaceCreatedAt: timestamp4.transform((value) => new Date(value).toISOString()),
2155
+ teamId: localId.optional(),
2156
+ agentId: localId.optional()
2157
+ }).strict().refine((scope) => !scope.agentId || !!scope.teamId, "Agent requires owning team");
2158
+ var notificationRuleSchema = import_zod5.z.object({
2159
+ id: import_zod5.z.string().regex(/^[a-f0-9]{64}$/).optional(),
2160
+ event: notificationEventSchema,
2161
+ channel: notificationChannelSchema,
2162
+ destinationId: id3,
2163
+ enabled: import_zod5.z.boolean()
2164
+ }).strict();
2165
+ var deliverySchema = import_zod5.z.object({
2166
+ id: id3,
2167
+ destination_id: id3,
2168
+ event: notificationEventSchema,
2169
+ state: import_zod5.z.enum([
2170
+ "queued",
2171
+ "leased",
2172
+ "delivered",
2173
+ "failed",
2174
+ "cancelled"
2175
+ ]),
2176
+ attempt: import_zod5.z.number().int().nonnegative(),
2177
+ max_attempts: import_zod5.z.number().int().positive(),
2178
+ status_code: import_zod5.z.number().int().min(100).max(599).nullable().optional(),
2179
+ error_code: import_zod5.z.string().max(128).nullable().optional(),
2180
+ created_at: timestamp4,
2181
+ delivered_at: timestamp4.nullable().optional(),
2182
+ next_retry_at: timestamp4.nullable().optional(),
2183
+ cancelled_at: timestamp4.nullable().optional()
2184
+ });
2185
+ var notificationSettingsDestinationSchema = import_zod5.z.object({
2186
+ id: id3,
2187
+ label: import_zod5.z.string().min(1).max(253).refine((value) => value === "Unavailable webhook" || /^[a-z0-9.:[\]-]+$/i.test(value)),
2188
+ channel: notificationChannelSchema,
2189
+ ready: import_zod5.z.boolean(),
2190
+ enabled: import_zod5.z.boolean(),
2191
+ updated_at: timestamp4
2192
+ }).strict().transform(({ updated_at, ...value }) => ({
2193
+ ...value,
2194
+ updatedAt: updated_at
2195
+ }));
2196
+ var notificationSettingsSchema = import_zod5.z.object({
2197
+ success: import_zod5.z.literal(true),
2198
+ channelVersion: import_zod5.z.literal(2),
2199
+ revision: revision2,
2200
+ rules: import_zod5.z.array(notificationRuleSchema).max(20),
2201
+ destinations: import_zod5.z.array(notificationSettingsDestinationSchema),
2202
+ deliveries: import_zod5.z.array(deliverySchema).max(50),
2203
+ channels: import_zod5.z.array(import_zod5.z.object({
2204
+ id: import_zod5.z.enum([
2205
+ "webhook",
2206
+ "email",
2207
+ "slack",
2208
+ "discord"
2209
+ ]),
2210
+ available: import_zod5.z.boolean()
2211
+ })),
2212
+ digestFrequencies: import_zod5.z.tuple([
2213
+ import_zod5.z.literal("realtime")
2214
+ ])
2215
+ });
2216
+ var eventInputSchema = import_zod5.z.object({
2217
+ eventId: import_zod5.z.string().regex(/^[a-f0-9]{64}$/),
2218
+ event: notificationEventSchema,
2219
+ occurredAt: timestamp4.transform((value) => new Date(value).toISOString()),
2220
+ scope: notificationScopeSchema,
2221
+ conversationId: localId,
2222
+ requestId: localId
2223
+ }).strict();
2224
+ var notificationDestinationActionSchema = import_zod5.z.discriminatedUnion("action", [
2225
+ import_zod5.z.object({
2226
+ action: import_zod5.z.literal("create"),
2227
+ url: httpsUrl
2228
+ }).strict(),
2229
+ import_zod5.z.object({
2230
+ action: import_zod5.z.literal("update"),
2231
+ destination_id: id3,
2232
+ expected_updated_at: timestamp4,
2233
+ url: httpsUrl.optional(),
2234
+ enabled: import_zod5.z.boolean().optional()
2235
+ }).strict().refine((value) => value.url !== void 0 || value.enabled !== void 0, "An update requires a changed field"),
2236
+ import_zod5.z.object({
2237
+ action: import_zod5.z.literal("delete"),
2238
+ destination_id: id3,
2239
+ expected_updated_at: timestamp4
2240
+ }).strict(),
2241
+ import_zod5.z.object({
2242
+ action: import_zod5.z.literal("delivery-control"),
2243
+ destination_id: id3,
2244
+ delivery_id: id3,
2245
+ operation: import_zod5.z.enum([
2246
+ "retry",
2247
+ "cancel"
2248
+ ])
2249
+ }).strict()
2250
+ ]);
2251
+ var notificationDestinationSchema = import_zod5.z.object({
2252
+ id: id3,
2253
+ label: import_zod5.z.string().min(1).max(253),
2254
+ channel: import_zod5.z.literal("webhook"),
2255
+ ready: import_zod5.z.boolean(),
2256
+ enabled: import_zod5.z.boolean(),
2257
+ updated_at: timestamp4
2258
+ }).strict();
2259
+ var notificationDeliveryOperationResultSchema = import_zod5.z.object({
2260
+ id: id3,
2261
+ state: import_zod5.z.string().min(1).max(64),
2262
+ attempt: import_zod5.z.number().int().nonnegative(),
2263
+ max_attempts: import_zod5.z.number().int().positive()
2264
+ }).strict();
2265
+ var notificationDestinationOperationSchema = import_zod5.z.object({
2266
+ operation_id: id3,
2267
+ workspace_id: id3,
2268
+ actor_user_id: id3,
2269
+ client_id: import_zod5.z.string().min(1).max(128),
2270
+ action: import_zod5.z.enum([
2271
+ "create",
2272
+ "update",
2273
+ "delete",
2274
+ "delivery-control"
2275
+ ]),
2276
+ state: import_zod5.z.enum([
2277
+ "prepared",
2278
+ "committed",
2279
+ "rejected"
2280
+ ]),
2281
+ prepared_at: timestamp4,
2282
+ committed_at: timestamp4.optional(),
2283
+ destination: notificationDestinationSchema.optional(),
2284
+ delivery: notificationDeliveryOperationResultSchema.optional(),
2285
+ rejection: import_zod5.z.enum([
2286
+ "notification_destination_not_found",
2287
+ "notification_destination_generation_conflict",
2288
+ "notification_delivery_transition_unavailable"
2289
+ ]).optional()
2290
+ }).strict().superRefine((value, context) => {
2291
+ if (value.state === "rejected" && !value.rejection) context.addIssue({
2292
+ code: "custom",
2293
+ message: "Rejected operation requires a rejection."
2294
+ });
2295
+ if (value.state === "committed" && !value.committed_at) context.addIssue({
2296
+ code: "custom",
2297
+ message: "Committed operation requires a timestamp."
2298
+ });
2299
+ });
2300
+ var destinationOperationMutationResponseSchema = import_zod5.z.object({
2301
+ state: import_zod5.z.enum([
2302
+ "prepared",
2303
+ "committed",
2304
+ "rejected"
2305
+ ]),
2306
+ operation: notificationDestinationOperationSchema,
2307
+ replayed: import_zod5.z.boolean()
2308
+ }).strict();
2309
+ var destinationOperationLookupResponseSchema = import_zod5.z.union([
2310
+ import_zod5.z.object({
2311
+ state: import_zod5.z.literal("not-observed"),
2312
+ operation: import_zod5.z.null()
2313
+ }).strict(),
2314
+ import_zod5.z.object({
2315
+ state: import_zod5.z.enum([
2316
+ "prepared",
2317
+ "committed",
2318
+ "rejected"
2319
+ ]),
2320
+ operation: notificationDestinationOperationSchema
2321
+ }).strict()
2322
+ ]);
2323
+ var destinationOperationExecuteResponseSchema = destinationOperationMutationResponseSchema.extend({
2324
+ secret: import_zod5.z.string().regex(/^[a-f0-9]{64}$/).optional()
2325
+ }).strict();
2326
+ var NotificationsClient = class {
2327
+ static {
2328
+ __name(this, "NotificationsClient");
2329
+ }
2330
+ transport;
2331
+ authorize;
2332
+ origin;
2333
+ constructor(origin, transport, authorize) {
2334
+ this.transport = transport;
2335
+ this.authorize = authorize;
2336
+ const url = new URL(origin);
2337
+ if (url.protocol !== "https:" || url.username || url.password || url.search || url.hash || url.pathname !== "/") throw new AccountError({
2338
+ code: "BAD_REQUEST",
2339
+ message: "Notifications API requires an HTTPS origin."
2340
+ });
2341
+ this.origin = url.origin;
2342
+ }
2343
+ async call(workspaceId, method, suffix, schema, body) {
2344
+ const url = `${this.origin}/api/workspaces/${id3.parse(workspaceId)}/notifications${suffix}`;
2345
+ const response = await this.transport.request({
2346
+ method,
2347
+ url,
2348
+ ...body === void 0 ? {} : {
2349
+ body
2350
+ },
2351
+ authorization: /* @__PURE__ */ __name(async () => {
2352
+ const value = await this.authorize(method, url, {
2353
+ scopes: [
2354
+ method === "GET" ? "team:read" : "team:manage"
2355
+ ],
2356
+ silent: true
2357
+ });
2358
+ if (!value) throw new AccountError({
2359
+ code: "INVALID_TOKEN",
2360
+ message: "Sign in to manage notifications."
2361
+ });
2362
+ return value;
2363
+ }, "authorization")
2364
+ });
2365
+ const parsed = schema.safeParse(response);
2366
+ if (!parsed.success) throw new AccountError({
2367
+ code: "INVALID_RESPONSE",
2368
+ message: "Invalid notification response."
2369
+ });
2370
+ return parsed.data;
2371
+ }
2372
+ read(workspaceId, scope) {
2373
+ return this.call(workspaceId, "GET", `/v2?scope=${encodeURIComponent(JSON.stringify(notificationScopeSchema.parse(scope)))}`, notificationSettingsSchema);
2374
+ }
2375
+ save(workspaceId, input) {
2376
+ const body = import_zod5.z.object({
2377
+ scope: notificationScopeSchema,
2378
+ expectedRevision: revision2,
2379
+ rules: import_zod5.z.array(notificationRuleSchema).max(20)
2380
+ }).strict().parse(input);
2381
+ return this.call(workspaceId, "POST", "/v2/settings", notificationSettingsSchema, body);
2382
+ }
2383
+ emit(workspaceId, input) {
2384
+ return this.call(workspaceId, "POST", "/events", import_zod5.z.object({
2385
+ success: import_zod5.z.literal(true),
2386
+ admitted: import_zod5.z.literal(true),
2387
+ duplicate: import_zod5.z.boolean()
2388
+ }), eventInputSchema.parse(input));
2389
+ }
2390
+ async prepareDestinationOperation(workspaceId, operationId, action) {
2391
+ const workspace = id3.parse(workspaceId), operation3 = id3.parse(operationId), request = notificationDestinationActionSchema.parse(action);
2392
+ const result = await this.call(workspace, "PUT", `/destination-operations/${operation3}`, destinationOperationMutationResponseSchema, request);
2393
+ if (result.operation.operation_id !== operation3 || result.operation.workspace_id !== workspace || result.operation.action !== request.action || result.operation.state !== result.state) throw new AccountError({
2394
+ code: "INVALID_RESPONSE",
2395
+ message: "Mismatched notification operation receipt."
2396
+ });
2397
+ return result;
2398
+ }
2399
+ async lookupDestinationOperation(workspaceId, operationId) {
2400
+ const workspace = id3.parse(workspaceId), operation3 = id3.parse(operationId);
2401
+ const result = await this.call(workspace, "GET", `/destination-operations/${operation3}`, destinationOperationLookupResponseSchema);
2402
+ if (result.operation && (result.operation.operation_id !== operation3 || result.operation.workspace_id !== workspace || result.operation.state !== result.state)) throw new AccountError({
2403
+ code: "INVALID_RESPONSE",
2404
+ message: "Mismatched notification operation receipt."
2405
+ });
2406
+ return result;
2407
+ }
2408
+ async executeDestinationOperation(workspaceId, operationId) {
2409
+ const workspace = id3.parse(workspaceId), operation3 = id3.parse(operationId);
2410
+ const result = await this.call(workspace, "POST", `/destination-operations/${operation3}`, destinationOperationExecuteResponseSchema);
2411
+ if (result.operation.operation_id !== operation3 || result.operation.workspace_id !== workspace || result.operation.state !== result.state || result.secret !== void 0 && (result.operation.action !== "create" || result.state !== "committed" || result.replayed)) throw new AccountError({
2412
+ code: "INVALID_RESPONSE",
2413
+ message: "Mismatched notification operation receipt."
2414
+ });
2415
+ return result;
2416
+ }
2417
+ };
2418
+
2419
+ // src/integrations.ts
2420
+ var import_zod6 = require("zod");
2421
+ var id4 = import_zod6.z.string().uuid();
2422
+ var provider = import_zod6.z.enum([
2423
+ "google",
2424
+ "github",
2425
+ "twitter"
2426
+ ]);
2427
+ var linked = import_zod6.z.object({
2428
+ provider,
2429
+ email: import_zod6.z.string().email().nullable(),
2430
+ username: import_zod6.z.string().nullable(),
2431
+ created_at: import_zod6.z.string().datetime({
2432
+ offset: true
2433
+ }).optional()
2434
+ }).passthrough();
2435
+ var integration = import_zod6.z.object({
2436
+ provider,
2437
+ available: import_zod6.z.boolean(),
2438
+ scopes: import_zod6.z.array(import_zod6.z.string().min(1)).max(16),
2439
+ linked: linked.nullable()
2440
+ }).strict();
2441
+ var operation2 = import_zod6.z.object({
2442
+ operationId: id4,
2443
+ actorAccountId: id4.optional(),
2444
+ clientId: import_zod6.z.string().optional(),
2445
+ provider: provider.optional(),
2446
+ scopes: import_zod6.z.array(import_zod6.z.string()).optional(),
2447
+ state: import_zod6.z.enum([
2448
+ "not-observed",
2449
+ "waiting",
2450
+ "exchanging",
2451
+ "committed",
2452
+ "rejected",
2453
+ "cancelled"
2454
+ ]),
2455
+ authorizationUrl: import_zod6.z.string().url().optional(),
2456
+ expiresAt: import_zod6.z.string().datetime({
2457
+ offset: true
2458
+ }).optional(),
2459
+ linked: linked.optional(),
2460
+ rejection: import_zod6.z.string().optional(),
2461
+ replayed: import_zod6.z.boolean().optional()
2462
+ }).strict();
2463
+ var AccountIntegrationClient = class {
2464
+ static {
2465
+ __name(this, "AccountIntegrationClient");
2466
+ }
2467
+ transport;
2468
+ authorize;
2469
+ base;
2470
+ constructor(base2, transport, authorize) {
2471
+ this.transport = transport;
2472
+ this.authorize = authorize;
2473
+ this.base = new URL(base2).origin;
2474
+ }
2475
+ async call(method, path, schema, body, idempotencyKey) {
2476
+ const url = `${this.base}/api/account-integrations${path}`, raw = await this.transport.request({
2477
+ method,
2478
+ url,
2479
+ ...body === void 0 ? {} : {
2480
+ body
2481
+ },
2482
+ ...idempotencyKey ? {
2483
+ idempotencyKey
2484
+ } : {},
2485
+ authorization: /* @__PURE__ */ __name(async () => {
2486
+ const value = await this.authorize(method, url, {
2487
+ scopes: [
2488
+ "openid"
2489
+ ],
2490
+ silent: true
2491
+ });
2492
+ if (!value) throw new AccountError({
2493
+ code: "INVALID_TOKEN",
2494
+ message: "Sign in to manage account integrations."
2495
+ });
2496
+ return value;
2497
+ }, "authorization")
2498
+ });
2499
+ const parsed = schema.safeParse(raw);
2500
+ if (!parsed.success) throw new AccountError({
2501
+ code: "INVALID_RESPONSE",
2502
+ message: "Invalid account integration response."
2503
+ });
2504
+ return parsed.data;
2505
+ }
2506
+ async list() {
2507
+ return (await this.call("GET", "", import_zod6.z.object({
2508
+ success: import_zod6.z.literal(true),
2509
+ providers: import_zod6.z.array(integration)
2510
+ }).strict())).providers;
2511
+ }
2512
+ async operation(operationId) {
2513
+ return (await this.call("GET", `/operations/${id4.parse(operationId)}`, import_zod6.z.object({
2514
+ success: import_zod6.z.literal(true),
2515
+ operation: operation2
2516
+ }).strict())).operation;
2517
+ }
2518
+ async start(operationId, value) {
2519
+ const operationIdValue = id4.parse(operationId), result = (await this.call("POST", `/${provider.parse(value)}/operations/${operationIdValue}/start`, import_zod6.z.object({
2520
+ success: import_zod6.z.literal(true),
2521
+ operation: operation2
2522
+ }).strict(), {}, operationIdValue)).operation;
2523
+ if (result.operationId !== operationIdValue || result.provider !== value || result.state !== "waiting" || !result.authorizationUrl) throw new AccountError({
2524
+ code: "INVALID_RESPONSE",
2525
+ message: "Invalid provider authorization operation."
2526
+ });
2527
+ const url = new URL(result.authorizationUrl);
2528
+ if (url.protocol !== "https:" || url.username || url.password) throw new AccountError({
2529
+ code: "INVALID_RESPONSE",
2530
+ message: "Untrusted provider authorization URL."
2531
+ });
2532
+ return result;
2533
+ }
2534
+ async cancel(operationId) {
2535
+ return (await this.call("POST", `/operations/${id4.parse(operationId)}/cancel`, import_zod6.z.object({
2536
+ success: import_zod6.z.literal(true),
2537
+ operation: operation2
2538
+ }).strict(), {})).operation;
2539
+ }
2540
+ };
2541
+
2542
+ // src/verification.ts
2543
+ var jwksCache = /* @__PURE__ */ new Map();
2544
+ function bytes(value) {
2545
+ const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
2546
+ const bin = atob(normalized + "=".repeat((4 - normalized.length % 4) % 4));
2547
+ return Uint8Array.from(bin, (char) => char.charCodeAt(0));
2548
+ }
2549
+ __name(bytes, "bytes");
2550
+ function decode(token) {
2551
+ const parts = token.split(".");
2552
+ if (parts.length !== 3 || !parts[0] || !parts[1] || !parts[2]) throw invalid("malformed JWT");
2553
+ try {
2554
+ return {
2555
+ header: JSON.parse(new TextDecoder().decode(bytes(parts[0]))),
2556
+ payload: JSON.parse(new TextDecoder().decode(bytes(parts[1]))),
2557
+ signingInput: new TextEncoder().encode(`${parts[0]}.${parts[1]}`),
2558
+ signature: bytes(parts[2])
2559
+ };
2560
+ } catch {
2561
+ throw invalid("malformed JWT");
2562
+ }
2563
+ }
2564
+ __name(decode, "decode");
2565
+ function invalid(message) {
2566
+ return new AccountError({
2567
+ code: "INVALID_RESPONSE",
2568
+ message: `OIDC verification failed: ${message}`
2569
+ });
2570
+ }
2571
+ __name(invalid, "invalid");
2572
+ function audience(value, expected) {
2573
+ return value === expected || Array.isArray(value) && value.includes(expected);
2574
+ }
2575
+ __name(audience, "audience");
2576
+ async function fetchJwks(transport, issuer, jwksUrl, force = false) {
2577
+ const url = jwksUrl ?? `${issuer.replace(/\/+$/, "")}/api/oauth2/jwks`;
2578
+ const cached = jwksCache.get(url);
2579
+ if (!force && cached && cached.expiresAt > Date.now()) return cached.keys;
2580
+ const response = await transport.request({
2581
+ method: "GET",
2582
+ url
2583
+ });
2584
+ if (!Array.isArray(response.keys) || response.keys.length === 0) throw invalid("empty JWKS");
2585
+ jwksCache.set(url, {
2586
+ keys: response.keys,
2587
+ expiresAt: Date.now() + 5 * 6e4
2588
+ });
2589
+ return response.keys;
2590
+ }
2591
+ __name(fetchJwks, "fetchJwks");
2592
+ async function verifySignature(decoded, keys) {
2593
+ if (decoded.header.alg !== "ES256" || typeof decoded.header.kid !== "string") return "invalid";
2594
+ const jwk = keys.find((candidate) => candidate.kid === decoded.header.kid && candidate.kty === "EC" && candidate.crv === "P-256");
2595
+ if (!jwk) return "unknown-kid";
2596
+ try {
2597
+ const key = await globalThis.crypto.subtle.importKey("jwk", jwk, {
2598
+ name: "ECDSA",
2599
+ namedCurve: "P-256"
2600
+ }, false, [
2601
+ "verify"
2602
+ ]);
2603
+ return await globalThis.crypto.subtle.verify({
2604
+ name: "ECDSA",
2605
+ hash: "SHA-256"
2606
+ }, key, decoded.signature, decoded.signingInput) ? "valid" : "invalid";
2607
+ } catch {
2608
+ return "invalid";
2609
+ }
2610
+ }
2611
+ __name(verifySignature, "verifySignature");
2612
+ async function verifiedPayload(token, transport, issuer, jwksUrl) {
2613
+ const decoded = decode(token);
2614
+ let keys = await fetchJwks(transport, issuer, jwksUrl);
2615
+ let result = await verifySignature(decoded, keys);
2616
+ if (result === "unknown-kid") {
2617
+ keys = await fetchJwks(transport, issuer, jwksUrl, true);
2618
+ result = await verifySignature(decoded, keys);
2619
+ }
2620
+ if (result !== "valid") throw invalid("signature or algorithm");
2621
+ return decoded;
2622
+ }
2623
+ __name(verifiedPayload, "verifiedPayload");
2624
+ function temporal(payload, now) {
2625
+ if (!Number.isInteger(payload.exp) || Number(payload.exp) <= now) throw invalid("token expired");
2626
+ if (!Number.isInteger(payload.iat) || Number(payload.iat) > now + 60) throw invalid("invalid issued-at time");
2627
+ if (payload.nbf !== void 0 && (!Number.isInteger(payload.nbf) || Number(payload.nbf) > now + 60)) throw invalid("token not yet valid");
2628
+ }
2629
+ __name(temporal, "temporal");
2630
+ var XENO_ISSUER_PAIR = [
2631
+ "https://xenostudio.ai",
2632
+ "https://xenosystem.ai"
2633
+ ];
2634
+ function issuerAccepted(iss, configured) {
2635
+ if (typeof iss !== "string") return false;
2636
+ const want = configured.replace(/\/+$/, "");
2637
+ if (iss === configured || iss === want) return true;
2638
+ return XENO_ISSUER_PAIR.includes(want) && XENO_ISSUER_PAIR.includes(iss);
2639
+ }
2640
+ __name(issuerAccepted, "issuerAccepted");
2641
+ async function verifyAccessToken(args) {
2642
+ const decoded = await verifiedPayload(args.token, args.transport, args.issuer, args.jwksUrl);
2643
+ const p = decoded.payload;
2644
+ const now = Math.floor(Date.now() / 1e3);
2645
+ temporal(p, now);
2646
+ if (decoded.header.typ !== "at+jwt" || p.typ !== "at+jwt" || !issuerAccepted(p.iss, args.issuer) || !audience(p.aud, "xeno-api")) throw invalid("access-token profile");
2647
+ if (p.client_id !== args.clientId || p.azp !== args.clientId) throw invalid("client binding");
2648
+ if (typeof p.sub !== "string" || typeof p.sid !== "string" || !Number.isInteger(p.auth_epoch)) throw invalid("session claims");
2649
+ if (!p.cnf || typeof p.cnf !== "object" || p.cnf.jkt !== args.dpopJkt) throw invalid("DPoP binding");
2650
+ if (p.act !== void 0) {
2651
+ const act = p.act;
2652
+ if (act.client_id !== "xeno-hub" || typeof act.installation_id_hash !== "string" || !act.installation_id_hash) throw invalid("broker actor");
2653
+ }
2654
+ if (args.requireBrokerActor && p.act === void 0) throw invalid("missing broker actor");
2655
+ const held = new Set(String(p.scope ?? "").split(/\s+/).filter(Boolean));
2656
+ for (const scope of args.expectedScopes ?? []) if (!held.has(scope)) throw invalid(`missing scope ${scope}`);
2657
+ return p;
2658
+ }
2659
+ __name(verifyAccessToken, "verifyAccessToken");
2660
+ async function verifyIdToken(args) {
2661
+ const decoded = await verifiedPayload(args.token, args.transport, args.issuer, args.jwksUrl);
2662
+ const p = decoded.payload;
2663
+ temporal(p, Math.floor(Date.now() / 1e3));
2664
+ if (!issuerAccepted(p.iss, args.issuer) || !audience(p.aud, args.clientId) || typeof p.sub !== "string" || typeof p.sid !== "string" || !Number.isInteger(p.auth_time)) throw invalid("ID-token profile");
2665
+ if (args.expectedNonce !== void 0 && p.nonce !== args.expectedNonce) throw invalid("nonce mismatch");
2666
+ if (args.expectedSubject !== void 0 && p.sub !== args.expectedSubject) throw invalid("subject mismatch");
2667
+ return p;
2668
+ }
2669
+ __name(verifyIdToken, "verifyIdToken");
2670
+ async function verifyLogoutToken(args) {
2671
+ const decoded = await verifiedPayload(args.token, args.transport, args.issuer, args.jwksUrl);
2672
+ const p = decoded.payload;
2673
+ temporal(p, Math.floor(Date.now() / 1e3));
2674
+ const event = "http://schemas.openid.net/event/backchannel-logout";
2675
+ if (decoded.header.typ !== "logout+jwt" || !issuerAccepted(p.iss, args.issuer) || !audience(p.aud, args.clientId)) throw invalid("logout-token profile");
2676
+ if (typeof p.jti !== "string" || !p.jti || p.nonce !== void 0) throw invalid("logout-token claims");
2677
+ if (typeof p.sid !== "string" && typeof p.sub !== "string") throw invalid("logout subject");
2678
+ if (!p.events || typeof p.events !== "object" || !(event in p.events)) throw invalid("logout event");
2679
+ return p;
2680
+ }
2681
+ __name(verifyLogoutToken, "verifyLogoutToken");
2682
+
2683
+ // src/oidc.ts
2684
+ async function generatePkce() {
2685
+ const verifierBytes = new Uint8Array(32);
2686
+ globalThis.crypto.getRandomValues(verifierBytes);
2687
+ const verifier = base64url(verifierBytes);
2688
+ const digest = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier));
2689
+ return {
2690
+ verifier,
2691
+ challenge: base64url(new Uint8Array(digest))
2692
+ };
2693
+ }
2694
+ __name(generatePkce, "generatePkce");
2695
+ function generateState() {
2696
+ const b = new Uint8Array(24);
2697
+ globalThis.crypto.getRandomValues(b);
2698
+ return base64url(b);
2699
+ }
2700
+ __name(generateState, "generateState");
2701
+ function base64url(bytes2) {
2702
+ let bin = "";
2703
+ for (let i = 0; i < bytes2.length; i += 1) bin += String.fromCharCode(bytes2[i]);
2704
+ const b64 = typeof btoa === "function" ? btoa(bin) : Buffer.from(bytes2).toString("base64");
2705
+ return b64.replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
2706
+ }
2707
+ __name(base64url, "base64url");
2708
+ function endpoints(cfg) {
2709
+ const base2 = cfg.issuer.replace(/\/+$/, "");
2710
+ return {
2711
+ authorize: cfg.authorizeUrl ?? `${base2}/api/oauth2/authorize`,
2712
+ token: cfg.tokenUrl ?? `${base2}/api/oauth2/token`,
2713
+ device: cfg.deviceAuthorizationUrl ?? `${base2}/api/oauth2/device_authorization`
2714
+ };
2715
+ }
2716
+ __name(endpoints, "endpoints");
2717
+ var DEFAULT_SCOPES = [
2718
+ "openid",
2719
+ "profile",
2720
+ "email",
2721
+ "ledger"
2722
+ ];
2723
+ function buildAuthorizeUrl(cfg, args) {
2724
+ const redirectUri = args.redirectUri ?? cfg.redirectUri;
2725
+ if (!redirectUri) {
2726
+ throw new AccountError({
2727
+ code: "BAD_REQUEST",
2728
+ message: "redirectUri required for authorize"
2729
+ });
2730
+ }
2731
+ const url = new URL(endpoints(cfg).authorize);
2732
+ url.searchParams.set("response_type", "code");
2733
+ url.searchParams.set("client_id", cfg.clientId);
2734
+ url.searchParams.set("redirect_uri", redirectUri);
2735
+ url.searchParams.set("scope", (args.scopes ?? cfg.scopes ?? DEFAULT_SCOPES).join(" "));
2736
+ url.searchParams.set("state", args.state);
2737
+ url.searchParams.set("code_challenge", args.codeChallenge);
2738
+ url.searchParams.set("code_challenge_method", "S256");
2739
+ if (args.nonce) url.searchParams.set("nonce", args.nonce);
2740
+ if (args.prompt) url.searchParams.set("prompt", args.prompt);
2741
+ if (args.maxAge !== void 0) url.searchParams.set("max_age", String(args.maxAge));
2742
+ if (args.acrValues) url.searchParams.set("acr_values", args.acrValues);
2743
+ return url.toString();
2744
+ }
2745
+ __name(buildAuthorizeUrl, "buildAuthorizeUrl");
2746
+ async function exchangeCode(cfg, transport, args) {
2747
+ const redirectUri = args.redirectUri ?? cfg.redirectUri;
2748
+ if (!redirectUri) {
2749
+ throw new AccountError({
2750
+ code: "BAD_REQUEST",
2751
+ message: "redirectUri required for code exchange"
2752
+ });
2753
+ }
2754
+ const body = new URLSearchParams({
2755
+ grant_type: "authorization_code",
2756
+ code: args.code,
2757
+ redirect_uri: redirectUri,
2758
+ client_id: cfg.clientId,
2759
+ code_verifier: args.codeVerifier
2760
+ });
2761
+ if (cfg.clientSecret) body.set("client_secret", cfg.clientSecret);
2762
+ return postToken(cfg, transport, body, {
2763
+ requireIdToken: true,
2764
+ expectedNonce: args.expectedNonce,
2765
+ expectedScopes: args.expectedScopes,
2766
+ signal: args.signal
2767
+ });
2768
+ }
2769
+ __name(exchangeCode, "exchangeCode");
2770
+ async function refreshTokens(cfg, transport, refreshToken, rotationId) {
2771
+ const body = new URLSearchParams({
2772
+ grant_type: "refresh_token",
2773
+ refresh_token: refreshToken,
2774
+ client_id: cfg.clientId
2775
+ });
2776
+ if (cfg.clientSecret) body.set("client_secret", cfg.clientSecret);
2777
+ if (rotationId) body.set("rotation_id", rotationId);
2778
+ return postToken(cfg, transport, body);
2779
+ }
2780
+ __name(refreshTokens, "refreshTokens");
2781
+ async function startDeviceAuthorization(cfg, transport, scopes) {
2782
+ const body = new URLSearchParams({
2783
+ client_id: cfg.clientId,
2784
+ scope: (scopes ?? cfg.scopes ?? DEFAULT_SCOPES).join(" ")
2785
+ });
2786
+ const raw = await transport.request({
2787
+ method: "POST",
2788
+ url: endpoints(cfg).device,
2789
+ headers: {
2790
+ "content-type": "application/x-www-form-urlencoded"
2791
+ },
2792
+ body: body.toString()
2793
+ });
2794
+ const expiresIn = Number(raw["expires_in"] ?? 600);
2795
+ return {
2796
+ deviceCode: String(raw["device_code"] ?? ""),
2797
+ userCode: String(raw["user_code"] ?? ""),
2798
+ verificationUri: String(raw["verification_uri"] ?? ""),
2799
+ verificationUriComplete: typeof raw["verification_uri_complete"] === "string" ? raw["verification_uri_complete"] : null,
2800
+ expiresAt: new Date(Date.now() + expiresIn * 1e3),
2801
+ intervalSeconds: Number(raw["interval"] ?? 5)
2802
+ };
2803
+ }
2804
+ __name(startDeviceAuthorization, "startDeviceAuthorization");
2805
+ async function pollDeviceToken(cfg, transport, device, opts = {}) {
2806
+ const sleep2 = opts.sleep ?? ((ms) => new Promise((resolve) => {
2807
+ const signal = opts.signal;
2808
+ const timer = setTimeout(done, ms);
2809
+ function done() {
2810
+ clearTimeout(timer);
2811
+ signal?.removeEventListener("abort", done);
2812
+ resolve();
2813
+ }
2814
+ __name(done, "done");
2815
+ signal?.addEventListener("abort", done, {
2816
+ once: true
2817
+ });
2818
+ if (signal?.aborted) done();
2819
+ }));
2820
+ let intervalMs = device.intervalSeconds * 1e3;
2821
+ while (Date.now() < device.expiresAt.getTime()) {
2822
+ if (opts.signal?.aborted) {
2823
+ throw new AccountError({
2824
+ code: "BAD_REQUEST",
2825
+ message: "device authorization aborted"
2826
+ });
2827
+ }
2828
+ await sleep2(intervalMs);
2829
+ if (opts.signal?.aborted) {
2830
+ throw new AccountError({
2831
+ code: "BAD_REQUEST",
2832
+ message: "device authorization aborted"
2833
+ });
2834
+ }
2835
+ if (Date.now() >= device.expiresAt.getTime()) break;
2836
+ const body = new URLSearchParams({
2837
+ grant_type: "urn:ietf:params:oauth:grant-type:device_code",
2838
+ device_code: device.deviceCode,
2839
+ client_id: cfg.clientId
2840
+ });
2841
+ try {
2842
+ const tokens = await postToken(cfg, transport, body, {
2843
+ requireIdToken: true,
2844
+ signal: opts.signal
2845
+ });
2846
+ if (opts.signal?.aborted) throw new AccountError({
2847
+ code: "BAD_REQUEST",
2848
+ message: "device authorization aborted"
2849
+ });
2850
+ return tokens;
2851
+ } catch (err) {
2852
+ if (!(err instanceof AccountError)) throw err;
2853
+ const oauthErr = err.oauthError;
2854
+ if (err.httpStatus === 400 && oauthErr === "authorization_pending") continue;
2855
+ if (err.httpStatus === 400 && oauthErr === "slow_down") {
2856
+ intervalMs += 5e3;
2857
+ continue;
2858
+ }
2859
+ throw err;
2860
+ }
2861
+ }
2862
+ throw new AccountError({
2863
+ code: "BAD_REQUEST",
2864
+ message: "device code expired before approval"
2865
+ });
2866
+ }
2867
+ __name(pollDeviceToken, "pollDeviceToken");
2868
+ async function postToken(cfg, transport, body, verify = {}) {
2869
+ const tokenUrl = endpoints(cfg).token;
2870
+ const dpop = await cfg.dpopSigner.createProof({
2871
+ method: "POST",
2872
+ url: tokenUrl
2873
+ });
2874
+ if (verify.signal?.aborted) throw new AccountError({
2875
+ code: "BAD_REQUEST",
2876
+ message: "Account sign-in was cancelled",
2877
+ retryable: false
2878
+ });
2879
+ const raw = await transport.request({
2880
+ method: "POST",
2881
+ url: tokenUrl,
2882
+ headers: {
2883
+ "content-type": "application/x-www-form-urlencoded",
2884
+ dpop
2885
+ },
2886
+ body: body.toString(),
2887
+ oauthErrorResponse: true,
2888
+ signal: verify.signal
2889
+ });
2890
+ const parsed = oauthTokenResponseSchema.safeParse(raw);
2891
+ if (!parsed.success) {
2892
+ throw new AccountError({
2893
+ code: "INVALID_RESPONSE",
2894
+ message: "token endpoint returned an unrecognised shape"
2895
+ });
2896
+ }
2897
+ const t = parsed.data;
2898
+ if (t.token_type.toLowerCase() !== "dpop") throw new AccountError({
2899
+ code: "INVALID_RESPONSE",
2900
+ message: "token endpoint did not issue a DPoP token"
2901
+ });
2902
+ if (verify.requireIdToken && !t.id_token) throw new AccountError({
2903
+ code: "INVALID_RESPONSE",
2904
+ message: "token endpoint omitted id_token"
2905
+ });
2906
+ const accessClaims = await verifyAccessToken({
2907
+ token: t.access_token,
2908
+ transport,
2909
+ issuer: cfg.issuer,
2910
+ clientId: cfg.clientId,
2911
+ dpopJkt: cfg.dpopSigner.jkt,
2912
+ jwksUrl: cfg.jwksUrl,
2913
+ expectedScopes: verify.expectedScopes
2914
+ });
2915
+ const idClaims = t.id_token ? await verifyIdToken({
2916
+ token: t.id_token,
2917
+ transport,
2918
+ issuer: cfg.issuer,
2919
+ clientId: cfg.clientId,
2920
+ jwksUrl: cfg.jwksUrl,
2921
+ expectedNonce: verify.expectedNonce,
2922
+ expectedSubject: accessClaims.sub
2923
+ }) : null;
2924
+ return tokenSetSchema.parse({
2925
+ accessToken: t.access_token,
2926
+ tokenType: t.token_type,
2927
+ expiresAt: t.expires_in ? new Date(Date.now() + t.expires_in * 1e3) : null,
2928
+ refreshToken: t.refresh_token ?? null,
2929
+ idToken: t.id_token ?? null,
2930
+ scope: t.scope ? t.scope.split(/\s+/).filter(Boolean) : [],
2931
+ sid: idClaims?.sid ?? accessClaims.sid,
2932
+ accessClaims,
2933
+ idClaims
2934
+ });
2935
+ }
2936
+ __name(postToken, "postToken");
2937
+
2938
+ // src/tokenStore.ts
2939
+ function memoryStore() {
2940
+ const m = /* @__PURE__ */ new Map();
2941
+ const locks = /* @__PURE__ */ new Map();
2942
+ return {
2943
+ async withExclusive(key, work) {
2944
+ const prior = locks.get(key) ?? Promise.resolve();
2945
+ let release;
2946
+ const held = new Promise((resolve) => {
2947
+ release = resolve;
2948
+ });
2949
+ const tail = prior.then(() => held);
2950
+ locks.set(key, tail);
2951
+ await prior;
2952
+ try {
2953
+ return await work();
2954
+ } finally {
2955
+ release();
2956
+ if (locks.get(key) === tail) locks.delete(key);
2957
+ }
2958
+ },
2959
+ async get(k) {
2960
+ return m.get(k) ?? null;
2961
+ },
2962
+ async set(k, v) {
2963
+ m.set(k, v);
2964
+ },
2965
+ async delete(k) {
2966
+ m.delete(k);
2967
+ }
2968
+ };
2969
+ }
2970
+ __name(memoryStore, "memoryStore");
2971
+ function keychainStore(kc) {
2972
+ return {
2973
+ ...kc.withExclusive ? {
2974
+ withExclusive: /* @__PURE__ */ __name((key, work) => kc.withExclusive(key, work), "withExclusive")
2975
+ } : {},
2976
+ async get(k) {
2977
+ return await kc.get(k) ?? null;
2978
+ },
2979
+ async set(k, v) {
2980
+ await kc.set(k, v);
2981
+ },
2982
+ async delete(k) {
2983
+ await kc.delete(k);
2984
+ }
2985
+ };
2986
+ }
2987
+ __name(keychainStore, "keychainStore");
2988
+
2989
+ // src/client.ts
2990
+ var XenoAccountClient = class {
2991
+ static {
2992
+ __name(this, "XenoAccountClient");
2993
+ }
2994
+ surface;
2995
+ account;
2996
+ ledger;
2997
+ authz;
2998
+ oidcConfig;
2999
+ issuer;
3000
+ authorities = {};
3001
+ transport;
3002
+ store;
3003
+ apiKey;
3004
+ broker;
3005
+ refreshStoreKey;
3006
+ refreshPendingKey;
3007
+ access = null;
3008
+ user = null;
3009
+ interactive;
3010
+ resolutionFlight = null;
3011
+ generation = 0;
3012
+ locallySignedOut = false;
3013
+ listeners = /* @__PURE__ */ new Set();
3014
+ constructor(cfg) {
3015
+ this.surface = surfaceSchema.parse(cfg.surface);
3016
+ this.transport = new Transport(cfg.transport);
3017
+ this.oidcConfig = {
3018
+ issuer: cfg.issuer,
3019
+ ...cfg.oidc
3020
+ };
3021
+ this.refreshStoreKey = `xeno.account/${this.oidcConfig.clientId}/refresh`;
3022
+ this.refreshPendingKey = `${this.refreshStoreKey}/pending`;
3023
+ this.account = new AccountClient(cfg.issuer, this.transport);
3024
+ this.ledger = new LedgerClient(cfg.apiBase, this.transport);
3025
+ this.authz = new AuthzClient(cfg.apiBase, this.transport);
3026
+ this.issuer = cfg.issuer;
3027
+ this.store = cfg.store ?? memoryStore();
3028
+ this.apiKey = cfg.apiKey ?? (typeof process !== "undefined" ? process.env?.XENO_API_KEY : void 0) ?? void 0;
3029
+ this.broker = cfg.broker;
3030
+ }
3031
+ // ─── Workspace, workforce, notification and integration authorities ───────
3032
+ //
3033
+ // They live on the issuer origin and authorise every request through `authorization()`, so each
3034
+ // attempt carries its own sender-constrained proof for its exact method and URL. Each is built on
3035
+ // first use: the workspace-line authorities refuse a non-HTTPS or path-bearing origin, and that
3036
+ // refusal belongs to the caller who uses them, not to every client constructed for local
3037
+ // development or for ledger-only use.
3038
+ get workspaces() {
3039
+ return this.authorities.workspaces ??= new WorkspaceClient(this.issuer, this.transport, (method, url, opts) => this.authorization(method, url, opts));
3040
+ }
3041
+ get workforce() {
3042
+ return this.authorities.workforce ??= new WorkforceClient(this.issuer, this.transport, (method, url, opts) => this.authorization(method, url, opts));
3043
+ }
3044
+ get notifications() {
3045
+ return this.authorities.notifications ??= new NotificationsClient(this.issuer, this.transport, (method, url, opts) => this.authorization(method, url, opts));
3046
+ }
3047
+ get integrations() {
3048
+ return this.authorities.integrations ??= new AccountIntegrationClient(this.issuer, this.transport, (method, url, opts) => this.authorization(method, url, opts));
3049
+ }
3050
+ // ─── Session workhorse (priority chain, XENO AUTH §5) ───────────────────
3051
+ /**
3052
+ * Return a valid Bearer for the gate, walking the chain:
3053
+ * 1 in-memory access token → 2 explicit override (apiKey/XENO_API_KEY) →
3054
+ * 3 [broker — host-wired] → 4 this product's own refresh token →
3055
+ * 5 interactive sign-in (host-provided; skipped when `silent`) → null.
3056
+ */
3057
+ async getAccessToken(opts = {}) {
3058
+ const generation = this.generation;
3059
+ const scopes = opts.scopes ? [
3060
+ ...opts.scopes
3061
+ ] : void 0;
3062
+ if (this.access && this.access.expiresAtMs - 6e4 > Date.now() && containsScopes(this.access.scopes, scopes)) {
3063
+ const held = this.access;
3064
+ if (await this.cacheCurrent(held) && this.generation === generation) return held.token;
3065
+ }
3066
+ if (this.apiKey) return this.apiKey;
3067
+ if (this.locallySignedOut && opts.silent) return null;
3068
+ if (!this.resolutionFlight) {
3069
+ const flight = this.resolveSession({
3070
+ scopes,
3071
+ silent: opts.silent
3072
+ }, generation);
3073
+ this.resolutionFlight = flight;
3074
+ void flight.finally(() => {
3075
+ if (this.resolutionFlight === flight) this.resolutionFlight = null;
3076
+ }).catch(() => {
3077
+ });
3078
+ }
3079
+ await this.resolutionFlight;
3080
+ if (this.generation !== generation || !this.access) return null;
3081
+ if (!await this.cacheCurrent(this.access) || this.generation !== generation || !this.access) return null;
3082
+ if (!containsScopes(this.access.scopes, scopes)) throw new AccountError({
3083
+ code: "INVALID_TOKEN",
3084
+ message: "Current account session lacks required scope",
3085
+ retryable: false
3086
+ });
3087
+ if (this.access.expiresAtMs <= Date.now()) return null;
3088
+ return this.access.token;
3089
+ }
3090
+ async resolveSession(opts, generation) {
3091
+ if (this.locallySignedOut) {
3092
+ if (!opts.silent && this.interactive) await this.resolveInteractive(opts.scopes, generation);
3093
+ return;
3094
+ }
3095
+ const pending = await this.storeRead(this.refreshPendingKey) ?? await this.legacyRefreshMarker();
3096
+ if (this.generation !== generation) return;
3097
+ const interruptedRotation = abandonedRotation(pending);
3098
+ if (pending && !interruptedRotation && !/^ready:v1:[A-Za-z0-9_-]{32}$/.test(pending)) {
3099
+ if (!opts.silent && this.interactive) {
3100
+ await this.resolveInteractive(opts.scopes, generation);
3101
+ return;
3102
+ }
3103
+ if (pending === "signed-out:v1") {
3104
+ this.setUnauthenticated();
3105
+ if (!await this.storeRead(this.refreshStoreKey)) return;
3106
+ } else {
3107
+ throw new AccountError({
3108
+ code: "CONFLICT",
3109
+ message: "Previous account transition is unconfirmed; explicit sign-in recovery required",
3110
+ retryable: false
3111
+ });
3112
+ }
3113
+ if (pending === "signed-out:v1") throw transitionConflict();
3114
+ }
3115
+ if (this.broker) {
3116
+ try {
3117
+ const brokerToken = await this.broker.getToken({
3118
+ clientId: this.oidcConfig.clientId,
3119
+ scopes: opts.scopes ?? this.oidcConfig.scopes ?? [],
3120
+ resource: "https://api.xenostudio.ai",
3121
+ childDpopJkt: this.oidcConfig.dpopSigner.jkt
3122
+ });
3123
+ if (brokerToken) {
3124
+ const claims = await verifyAccessToken({
3125
+ token: brokerToken.accessToken,
3126
+ transport: this.transport,
3127
+ issuer: this.oidcConfig.issuer,
3128
+ clientId: this.oidcConfig.clientId,
3129
+ dpopJkt: this.oidcConfig.dpopSigner.jkt,
3130
+ jwksUrl: this.oidcConfig.jwksUrl,
3131
+ expectedScopes: opts.scopes,
3132
+ requireBrokerActor: true
3133
+ });
3134
+ if (brokerToken.refreshToken) throw new AccountError({
3135
+ code: "INVALID_RESPONSE",
3136
+ message: "Broker cannot transfer refresh credentials",
3137
+ retryable: false
3138
+ });
3139
+ await this.applyTokenSet({
3140
+ ...brokerToken,
3141
+ accessClaims: claims,
3142
+ idClaims: null
3143
+ }, generation, pending, true);
3144
+ return;
3145
+ }
3146
+ } catch {
3147
+ }
3148
+ }
3149
+ if (this.generation !== generation) return;
3150
+ const rotationId = interruptedRotation ?? generateState();
3151
+ const transition = rotationMarker(rotationId);
3152
+ const rt = await this.exclusiveStore(async () => {
3153
+ if (this.generation !== generation) return null;
3154
+ if (await this.store.get(this.refreshPendingKey) !== pending) throw transitionConflict();
3155
+ const value = await this.store.get(this.refreshStoreKey);
3156
+ if (value) await this.store.set(this.refreshPendingKey, transition);
3157
+ return value;
3158
+ });
3159
+ if (this.generation !== generation) return;
3160
+ if (interruptedRotation && !rt) throw transitionConflict();
3161
+ if (rt) {
3162
+ try {
3163
+ const tokens = await this.refresh(rt, rotationId);
3164
+ if (!tokens.refreshToken) throw new AccountError({
3165
+ code: "INVALID_RESPONSE",
3166
+ message: "Rotating refresh response omitted successor credential",
3167
+ retryable: false
3168
+ });
3169
+ await this.applyTokenSet(tokens, generation, transition);
3170
+ return;
3171
+ } catch (error) {
3172
+ if (this.generation !== generation) return;
3173
+ if (!(error instanceof AccountError && error.httpStatus === 400 && error.oauthError === "invalid_grant")) {
3174
+ throw new AccountError({
3175
+ code: error instanceof AccountError ? error.code : "UNREACHABLE",
3176
+ message: "Account refresh outcome is unconfirmed; explicit recovery required",
3177
+ retryable: false,
3178
+ ...error instanceof AccountError ? {
3179
+ httpStatus: error.httpStatus
3180
+ } : {}
3181
+ });
3182
+ }
3183
+ await this.exclusiveStore(async () => {
3184
+ if (this.generation !== generation) return;
3185
+ if (await this.store.get(this.refreshPendingKey) !== transition) throw transitionConflict();
3186
+ await this.store.delete(this.refreshStoreKey);
3187
+ await this.store.set(this.refreshPendingKey, "signed-out:v1");
3188
+ });
3189
+ if (this.generation !== generation) return;
3190
+ this.setUnauthenticated();
3191
+ }
3192
+ }
3193
+ if (!opts.silent && this.interactive) {
3194
+ await this.resolveInteractive(opts.scopes, generation);
3195
+ }
3196
+ return;
3197
+ }
3198
+ /** Register the host's interactive sign-in (loopback PKCE / device grant). */
3199
+ setInteractiveSignIn(fn) {
3200
+ this.interactive = fn;
3201
+ }
3202
+ isAuthenticated() {
3203
+ return !!this.access && this.access.expiresAtMs > Date.now();
3204
+ }
3205
+ currentUser() {
3206
+ return this.user;
3207
+ }
3208
+ /** Subscribe to login/refresh/logout/backchannel. Returns an unsubscribe fn. */
3209
+ onAuthChanged(cb) {
3210
+ this.listeners.add(cb);
3211
+ return () => this.listeners.delete(cb);
3212
+ }
3213
+ /** Local wipe only, used after durable host-side invalidation/reconciliation. */
3214
+ async signOutLocal() {
3215
+ this.generation++;
3216
+ this.locallySignedOut = true;
3217
+ this.resolutionFlight = null;
3218
+ this.setUnauthenticated();
3219
+ await this.exclusiveStore(async () => {
3220
+ await this.store.set(this.refreshPendingKey, "signed-out:v1");
3221
+ await this.store.delete(this.refreshStoreKey);
3222
+ });
3223
+ }
3224
+ /** Revoke this subject-owned session, then always clear local state. */
3225
+ async signOut() {
3226
+ const original = this.access;
3227
+ const local = this.signOutLocal();
3228
+ void local.catch(() => {
3229
+ });
3230
+ let serverRevoked = false;
3231
+ try {
3232
+ if (original?.tokenType === "DPoP") {
3233
+ const url = `${this.oidcConfig.issuer.replace(/\/+$/, "")}/api/oauth2/end_session`;
3234
+ const dpop = await this.createProof({
3235
+ method: "POST",
3236
+ url,
3237
+ accessToken: original.token
3238
+ });
3239
+ await this.transport.request({
3240
+ method: "POST",
3241
+ url,
3242
+ token: original.token,
3243
+ tokenType: "DPoP",
3244
+ headers: {
3245
+ dpop
3246
+ },
3247
+ idempotencyKey: `logout:${original.sid ?? "current"}`
3248
+ });
3249
+ serverRevoked = true;
3250
+ }
3251
+ } finally {
3252
+ await local;
3253
+ }
3254
+ return {
3255
+ serverRevoked
3256
+ };
3257
+ }
3258
+ /** Step-up protected, subject-keyed global logout. Only authorized clients can call it. */
3259
+ async signOutEverywhere() {
3260
+ if (!this.access || this.access.tokenType !== "DPoP") throw new Error("fresh DPoP session required");
3261
+ const original = this.access, generation = this.generation;
3262
+ const url = `${this.oidcConfig.issuer.replace(/\/+$/, "")}/api/oauth2/logout_everywhere`;
3263
+ const dpop = await this.createProof({
3264
+ method: "POST",
3265
+ url,
3266
+ accessToken: original.token
3267
+ });
3268
+ if (this.generation !== generation || this.access !== original) throw new AccountError({
3269
+ code: "CONFLICT",
3270
+ message: "Account session changed before global revocation",
3271
+ retryable: false
3272
+ });
3273
+ await this.transport.request({
3274
+ method: "POST",
3275
+ url,
3276
+ token: original.token,
3277
+ tokenType: "DPoP",
3278
+ headers: {
3279
+ dpop
3280
+ },
3281
+ idempotencyKey: `logout-all:${original.sid ?? "current"}`
3282
+ });
3283
+ try {
3284
+ await this.broker?.logout?.();
3285
+ } finally {
3286
+ if (this.generation === generation) {
3287
+ this.generation++;
3288
+ this.locallySignedOut = true;
3289
+ this.resolutionFlight = null;
3290
+ this.setUnauthenticated();
3291
+ await this.exclusiveStore(async () => {
3292
+ if (await this.store.get(this.refreshPendingKey) !== original.storeTransition) return;
3293
+ await this.store.set(this.refreshPendingKey, "signed-out:v1");
3294
+ await this.store.delete(this.refreshStoreKey);
3295
+ });
3296
+ }
3297
+ }
3298
+ }
3299
+ setUnauthenticated() {
3300
+ this.access = null;
3301
+ this.user = null;
3302
+ this.emit(null);
3303
+ }
3304
+ emit(a) {
3305
+ for (const cb of [
3306
+ ...this.listeners
3307
+ ]) {
3308
+ try {
3309
+ cb(a);
3310
+ } catch {
3311
+ }
3312
+ }
3313
+ }
3314
+ /**
3315
+ * The 0.2.0 workforce builds (shipped vendored, never published) marked an in-flight refresh at
3316
+ * `<refresh key>-uncertain` and never named the rotation. An install upgrading with that marker
3317
+ * present may hold a token the origin already rotated, so sending it would be a replay — the
3318
+ * zero-grace reuse that revokes the whole family. It is therefore an unconfirmed transition like any
3319
+ * other v1 marker: refused silently, recoverable only by explicit sign-in (which writes this
3320
+ * version's own marker, after which the legacy one is never consulted again).
3321
+ */
3322
+ async legacyRefreshMarker() {
3323
+ return await this.storeRead(`${this.refreshStoreKey}-uncertain`) ? "legacy-refresh-uncertain:v1" : null;
3324
+ }
3325
+ async storeRead(key) {
3326
+ try {
3327
+ return await this.store.get(key);
3328
+ } catch {
3329
+ throw new AccountError({
3330
+ code: "UNREACHABLE",
3331
+ message: "Secure account store is unavailable",
3332
+ retryable: false
3333
+ });
3334
+ }
3335
+ }
3336
+ async cacheCurrent(held) {
3337
+ const transition = await this.storeRead(this.refreshPendingKey);
3338
+ if (this.access === held && transition === held.storeTransition) return true;
3339
+ if (this.access === held) this.setUnauthenticated();
3340
+ return false;
3341
+ }
3342
+ async exclusiveStore(work) {
3343
+ if (!this.store.withExclusive) throw new AccountError({
3344
+ code: "UNREACHABLE",
3345
+ message: "Secure account store exclusion is unavailable",
3346
+ retryable: false
3347
+ });
3348
+ try {
3349
+ return await this.store.withExclusive(this.refreshStoreKey, work);
3350
+ } catch (error) {
3351
+ if (error instanceof AccountError) throw error;
3352
+ throw new AccountError({
3353
+ code: "UNREACHABLE",
3354
+ message: "Secure account state commit is unavailable",
3355
+ retryable: false
3356
+ });
3357
+ }
3358
+ }
3359
+ async reserveSignIn(generation) {
3360
+ const transition = `sign-in:v1:${generateState()}`;
3361
+ await this.exclusiveStore(async () => {
3362
+ if (this.generation !== generation) throw transitionConflict();
3363
+ await this.store.set(this.refreshPendingKey, transition);
3364
+ });
3365
+ return transition;
3366
+ }
3367
+ async resolveInteractive(scopes, generation) {
3368
+ const transition = await this.reserveSignIn(generation);
3369
+ await this.applyTokenSet(await this.interactive(scopes), generation, transition);
3370
+ }
3371
+ /** Cache the access token, persist the rotated refresh token, update the user. */
3372
+ async applyTokenSet(ts, generation, transition, preserveRefresh = false, signal) {
3373
+ if (this.generation !== generation) return;
3374
+ const claims = await verifyAccessToken({
3375
+ token: ts.accessToken,
3376
+ transport: this.transport,
3377
+ issuer: this.oidcConfig.issuer,
3378
+ clientId: this.oidcConfig.clientId,
3379
+ dpopJkt: this.oidcConfig.dpopSigner.jkt,
3380
+ jwksUrl: this.oidcConfig.jwksUrl
3381
+ });
3382
+ const idClaims = ts.idToken ? await verifyIdToken({
3383
+ token: ts.idToken,
3384
+ transport: this.transport,
3385
+ issuer: this.oidcConfig.issuer,
3386
+ clientId: this.oidcConfig.clientId,
3387
+ jwksUrl: this.oidcConfig.jwksUrl,
3388
+ expectedSubject: claims.sub
3389
+ }) : null;
3390
+ if (idClaims && idClaims.sid !== claims.sid) throw new AccountError({
3391
+ code: "INVALID_RESPONSE",
3392
+ message: "ID and access session binding differ",
3393
+ retryable: false
3394
+ });
3395
+ if (ts.tokenType.toLowerCase() !== "dpop") throw new AccountError({
3396
+ code: "INVALID_RESPONSE",
3397
+ message: "Canonical session requires DPoP token type",
3398
+ retryable: false
3399
+ });
3400
+ if (this.generation !== generation) return;
3401
+ const expMs = Math.min(claims.exp * 1e3, ts.expiresAt?.getTime() ?? claims.exp * 1e3);
3402
+ const storeTransition = `ready:v1:${generateState()}`;
3403
+ await this.exclusiveStore(async () => {
3404
+ if (this.generation !== generation) return;
3405
+ if (await this.store.get(this.refreshPendingKey) !== transition) throw transitionConflict();
3406
+ if (ts.refreshToken) {
3407
+ await this.store.set(this.refreshStoreKey, ts.refreshToken);
3408
+ } else if (!preserveRefresh) await this.store.delete(this.refreshStoreKey);
3409
+ if (this.generation !== generation || signal?.aborted) throw transitionConflict();
3410
+ await this.store.set(this.refreshPendingKey, storeTransition);
3411
+ if (signal?.aborted) {
3412
+ if (await this.store.get(this.refreshPendingKey) === storeTransition) {
3413
+ await this.store.set(this.refreshPendingKey, "signed-out:v1");
3414
+ await this.store.delete(this.refreshStoreKey);
3415
+ }
3416
+ throw transitionConflict();
3417
+ }
3418
+ });
3419
+ if (this.generation !== generation) {
3420
+ if (signal?.aborted) await this.cancelCommittedSignIn(storeTransition);
3421
+ return;
3422
+ }
3423
+ this.access = {
3424
+ token: ts.accessToken,
3425
+ tokenType: ts.tokenType.toLowerCase() === "dpop" ? "DPoP" : "Bearer",
3426
+ expiresAtMs: expMs,
3427
+ scopes: claims.scope.split(/\s+/).filter(Boolean),
3428
+ sid: claims.sid,
3429
+ storeTransition
3430
+ };
3431
+ this.locallySignedOut = false;
3432
+ if (idClaims) {
3433
+ const u = accountFromVerifiedClaims(idClaims);
3434
+ if (u) this.user = u;
3435
+ } else if (this.user?.id !== claims.sub) this.user = null;
3436
+ this.emit(this.user);
3437
+ return storeTransition;
3438
+ }
3439
+ async cancelCommittedSignIn(transition) {
3440
+ await this.exclusiveStore(async () => {
3441
+ if (await this.store.get(this.refreshPendingKey) !== transition) return;
3442
+ await this.store.set(this.refreshPendingKey, "signed-out:v1");
3443
+ await this.store.delete(this.refreshStoreKey);
3444
+ });
3445
+ }
3446
+ // ─── OIDC sign-in (Authorization Code + PKCE) ───────────────────────────
3447
+ /**
3448
+ * Begin "Continue with XENO". Returns the authorize URL to redirect to, plus
3449
+ * the `{ state, verifier }` the caller MUST persist (encrypted) to complete
3450
+ * the flow in {@link completeSignIn}.
3451
+ */
3452
+ async beginSignIn(args = {}) {
3453
+ const state = generateState();
3454
+ const nonce = generateState();
3455
+ const pkce = await generatePkce();
3456
+ const url = buildAuthorizeUrl(this.oidcConfig, {
3457
+ state,
3458
+ codeChallenge: pkce.challenge,
3459
+ redirectUri: args.redirectUri,
3460
+ scopes: args.scopes,
3461
+ nonce,
3462
+ ...args.fresh ? {
3463
+ prompt: "login",
3464
+ maxAge: 60,
3465
+ acrValues: "urn:xeno:acr:fresh"
3466
+ } : {}
3467
+ });
3468
+ return {
3469
+ url,
3470
+ state,
3471
+ nonce,
3472
+ pkce
3473
+ };
3474
+ }
3475
+ /** Complete the code flow: exchange `code` (with the saved verifier) for tokens,
3476
+ * then cache the access token + persist the refresh token + set the user. */
3477
+ async completeSignIn(args) {
3478
+ const generation = ++this.generation;
3479
+ this.resolutionFlight = null;
3480
+ const invalidate = this.bindSignInCancellation(generation, args.signal);
3481
+ try {
3482
+ if (args.signal?.aborted) throw transitionConflict();
3483
+ const transition = await this.reserveSignIn(generation);
3484
+ if (args.signal?.aborted || this.generation !== generation) throw transitionConflict();
3485
+ const ts = await exchangeCode(this.oidcConfig, this.transport, args);
3486
+ const committed2 = await this.applyTokenSet(ts, generation, transition, false, args.signal);
3487
+ if (this.generation !== generation || args.signal?.aborted) {
3488
+ if (committed2 && args.signal?.aborted) await this.cancelCommittedSignIn(committed2);
3489
+ throw transitionConflict();
3490
+ }
3491
+ return ts;
3492
+ } catch (error) {
3493
+ if (args.signal?.aborted) throw transitionConflict();
3494
+ throw error;
3495
+ } finally {
3496
+ invalidate();
3497
+ }
3498
+ }
3499
+ bindSignInCancellation(generation, signal) {
3500
+ const cancelled = /* @__PURE__ */ __name(() => {
3501
+ if (this.generation !== generation) return;
3502
+ this.generation++;
3503
+ this.resolutionFlight = null;
3504
+ this.setUnauthenticated();
3505
+ }, "cancelled");
3506
+ signal?.addEventListener("abort", cancelled, {
3507
+ once: true
3508
+ });
3509
+ if (signal?.aborted) cancelled();
3510
+ return () => signal?.removeEventListener("abort", cancelled);
3511
+ }
3512
+ /** Headers for one sender-constrained resource request. */
3513
+ async authorization(method, url, opts = {}) {
3514
+ const generation = this.generation;
3515
+ const token = await this.getAccessToken(opts);
3516
+ if (!token || this.generation !== generation) return null;
3517
+ if (this.apiKey && token === this.apiKey) return {
3518
+ token,
3519
+ tokenType: "Bearer"
3520
+ };
3521
+ if (!this.access || this.access.token !== token || this.access.tokenType !== "DPoP") return {
3522
+ token,
3523
+ tokenType: "Bearer"
3524
+ };
3525
+ const dpop = await this.createProof({
3526
+ method,
3527
+ url,
3528
+ accessToken: token
3529
+ });
3530
+ if (this.generation !== generation || this.access?.token !== token || this.access.expiresAtMs <= Date.now()) return null;
3531
+ if (!await this.cacheCurrent(this.access) || this.generation !== generation || this.access?.token !== token) return null;
3532
+ return {
3533
+ token,
3534
+ tokenType: "DPoP",
3535
+ headers: {
3536
+ dpop
3537
+ }
3538
+ };
3539
+ }
3540
+ /** Verify and sender-constrain a previously persisted access token. Server
3541
+ * consumers use this for encrypted per-workspace sessions without placing
3542
+ * those tokens into the process-global client cache. */
3543
+ async authorizationForToken(token, method, url, expectedScopes) {
3544
+ await verifyAccessToken({
3545
+ token,
3546
+ transport: this.transport,
3547
+ issuer: this.oidcConfig.issuer,
3548
+ clientId: this.oidcConfig.clientId,
3549
+ dpopJkt: this.oidcConfig.dpopSigner.jkt,
3550
+ jwksUrl: this.oidcConfig.jwksUrl,
3551
+ expectedScopes
3552
+ });
3553
+ const dpop = await this.createProof({
3554
+ method,
3555
+ url,
3556
+ accessToken: token
3557
+ });
3558
+ return {
3559
+ token,
3560
+ tokenType: "DPoP",
3561
+ headers: {
3562
+ dpop
3563
+ }
3564
+ };
3565
+ }
3566
+ /** Verify a provider-originated Back-Channel Logout Token. */
3567
+ verifyBackchannelLogout(token) {
3568
+ return verifyLogoutToken({
3569
+ token,
3570
+ transport: this.transport,
3571
+ issuer: this.oidcConfig.issuer,
3572
+ clientId: this.oidcConfig.clientId,
3573
+ jwksUrl: this.oidcConfig.jwksUrl
3574
+ });
3575
+ }
3576
+ async createProof(args) {
3577
+ try {
3578
+ return await this.oidcConfig.dpopSigner.createProof(args);
3579
+ } catch {
3580
+ throw new AccountError({
3581
+ code: "UNREACHABLE",
3582
+ message: "Host account request signing is unavailable",
3583
+ retryable: false
3584
+ });
3585
+ }
3586
+ }
3587
+ /** Rotate tokens. Persist the returned refreshToken; a failure means re-auth. */
3588
+ refresh(refreshToken, rotationId) {
3589
+ return refreshTokens(this.oidcConfig, this.transport, refreshToken, rotationId);
3590
+ }
3591
+ // ─── Device grant (CLI / headless) ──────────────────────────────────────
3592
+ startDeviceLogin(scopes) {
3593
+ return startDeviceAuthorization(this.oidcConfig, this.transport, scopes);
3594
+ }
3595
+ async awaitDeviceLogin(device, opts) {
3596
+ const generation = ++this.generation;
3597
+ this.resolutionFlight = null;
3598
+ const invalidate = this.bindSignInCancellation(generation, opts?.signal);
3599
+ try {
3600
+ if (opts?.signal?.aborted) throw transitionConflict();
3601
+ const transition = await this.reserveSignIn(generation);
3602
+ if (opts?.signal?.aborted || this.generation !== generation) throw transitionConflict();
3603
+ const ts = await pollDeviceToken(this.oidcConfig, this.transport, device, opts);
3604
+ const committed2 = await this.applyTokenSet(ts, generation, transition, false, opts?.signal);
3605
+ if (this.generation !== generation || opts?.signal?.aborted) {
3606
+ if (committed2 && opts?.signal?.aborted) await this.cancelCommittedSignIn(committed2);
3607
+ throw transitionConflict();
3608
+ }
3609
+ return ts;
3610
+ } catch (error) {
3611
+ if (opts?.signal?.aborted) throw transitionConflict();
3612
+ throw error;
3613
+ } finally {
3614
+ invalidate();
3615
+ }
3616
+ }
3617
+ };
3618
+ function accountFromVerifiedClaims(p) {
3619
+ if (!p.sub) return null;
3620
+ return {
3621
+ id: p.sub,
3622
+ email: p.email ?? "",
3623
+ username: p.preferred_username ?? null,
3624
+ displayName: p.name ?? null,
3625
+ avatarUrl: p.picture ?? null,
3626
+ emailVerified: p.email_verified === true,
3627
+ linkedSurfaces: []
3628
+ };
3629
+ }
3630
+ __name(accountFromVerifiedClaims, "accountFromVerifiedClaims");
3631
+ function containsScopes(held, requested) {
3632
+ if (!requested?.length) return true;
3633
+ const set = new Set(held);
3634
+ return requested.every((scope) => set.has(scope));
3635
+ }
3636
+ __name(containsScopes, "containsScopes");
3637
+ var ROTATION_IN_FLIGHT_MS = 3e4;
3638
+ function rotationMarker(rotationId) {
3639
+ const pid = typeof process !== "undefined" && typeof process.pid === "number" ? process.pid : 0;
3640
+ return `refresh:v2:${rotationId}:${pid}:${Date.now()}`;
3641
+ }
3642
+ __name(rotationMarker, "rotationMarker");
3643
+ function abandonedRotation(marker, now = Date.now()) {
3644
+ const match = marker?.match(/^refresh:v2:([A-Za-z0-9_-]{32}):(\d{1,10}):(\d{1,15})$/);
3645
+ if (!match) return void 0;
3646
+ const pid = Number(match[2]), started = Number(match[3]);
3647
+ if (now - started > ROTATION_IN_FLIGHT_MS) return match[1];
3648
+ return pid > 0 && !processAlive(pid) ? match[1] : void 0;
3649
+ }
3650
+ __name(abandonedRotation, "abandonedRotation");
3651
+ function processAlive(pid) {
3652
+ if (typeof process === "undefined" || typeof process.kill !== "function") return true;
3653
+ try {
3654
+ process.kill(pid, 0);
3655
+ return true;
3656
+ } catch (error) {
3657
+ return error.code === "EPERM";
3658
+ }
3659
+ }
3660
+ __name(processAlive, "processAlive");
3661
+ function transitionConflict() {
3662
+ return new AccountError({
3663
+ code: "CONFLICT",
3664
+ message: "Account credential transition changed; explicit recovery required",
3665
+ retryable: false
3666
+ });
3667
+ }
3668
+ __name(transitionConflict, "transitionConflict");
3669
+
3670
+ // src/dpop.ts
3671
+ function normalizeDpopHtu(value) {
3672
+ const url = new URL(value);
3673
+ if (url.protocol !== "https:") throw new Error("DPoP htu must use HTTPS");
3674
+ url.hash = "";
3675
+ url.search = "";
3676
+ url.username = "";
3677
+ url.password = "";
3678
+ url.hostname = url.hostname.toLowerCase();
3679
+ if (url.port === "443") url.port = "";
3680
+ return url.toString();
3681
+ }
3682
+ __name(normalizeDpopHtu, "normalizeDpopHtu");
3683
+
3684
+ // src/bff.ts
3685
+ var BffSessionClient = class {
3686
+ static {
3687
+ __name(this, "BffSessionClient");
3688
+ }
3689
+ baseUrl;
3690
+ fetchImpl;
3691
+ csrf;
3692
+ constructor(baseUrl = "/api/session", fetchImpl = globalThis.fetch, csrf) {
3693
+ this.baseUrl = baseUrl;
3694
+ this.fetchImpl = fetchImpl;
3695
+ this.csrf = csrf;
3696
+ }
3697
+ loginUrl(returnUrl) {
3698
+ if (!returnUrl.startsWith("/") || returnUrl.startsWith("//")) throw new AccountError({
3699
+ code: "BAD_REQUEST",
3700
+ message: "returnUrl must be same-origin"
3701
+ });
3702
+ return `${this.baseUrl}/login/start?return_url=${encodeURIComponent(returnUrl)}`;
3703
+ }
3704
+ session() {
3705
+ return this.request("GET", "/session");
3706
+ }
3707
+ refresh(idempotencyKey) {
3708
+ return this.request("POST", "/refresh", idempotencyKey);
3709
+ }
3710
+ async logout() {
3711
+ await this.request("POST", "/logout");
3712
+ }
3713
+ async request(method, path, idempotencyKey) {
3714
+ const headers = {
3715
+ accept: "application/json"
3716
+ };
3717
+ if (method === "POST") {
3718
+ const csrf = this.csrf();
3719
+ if (!csrf) throw new AccountError({
3720
+ code: "BAD_REQUEST",
3721
+ message: "missing BFF CSRF value"
3722
+ });
3723
+ headers["x-xeno-csrf"] = csrf;
3724
+ if (idempotencyKey) headers["idempotency-key"] = idempotencyKey;
3725
+ }
3726
+ const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
3727
+ method,
3728
+ credentials: "include",
3729
+ headers
3730
+ });
3731
+ if (!response.ok) throw new AccountError({
3732
+ code: response.status === 401 ? "INVALID_TOKEN" : "PLATFORM_ERROR",
3733
+ message: `BFF session request failed: ${response.status}`,
3734
+ httpStatus: response.status
3735
+ });
3736
+ if (response.status === 204) return void 0;
3737
+ return response.json();
3738
+ }
3739
+ };
3740
+
3741
+ // src/redaction.ts
3742
+ var TOKEN_RE = /(eyJ[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{6,})|([A-Za-z0-9_-]{40,})/g;
3743
+ function redact(input) {
3744
+ const s = typeof input === "string" ? input : safeStringify(input);
3745
+ return s.replace(TOKEN_RE, (m) => `${m.slice(0, 6)}\u2026[redacted:${m.length}]`);
3746
+ }
3747
+ __name(redact, "redact");
3748
+ function safeStringify(v) {
3749
+ try {
3750
+ return JSON.stringify(v) ?? String(v);
3751
+ } catch {
3752
+ return String(v);
3753
+ }
3754
+ }
3755
+ __name(safeStringify, "safeStringify");
3756
+
3757
+ // src/resource-authorization.ts
3758
+ var MAX_JWT_BYTES = 16384;
3759
+ var PRIVATE_FIELDS = [
3760
+ "d",
3761
+ "p",
3762
+ "q",
3763
+ "dp",
3764
+ "dq",
3765
+ "qi",
3766
+ "oth",
3767
+ "k"
3768
+ ];
3769
+ function denied() {
3770
+ return new AccountError({
3771
+ code: "INVALID_TOKEN",
3772
+ message: "Resource authorization refused",
3773
+ retryable: false,
3774
+ httpStatus: 401
3775
+ });
3776
+ }
3777
+ __name(denied, "denied");
3778
+ function unavailable() {
3779
+ return new AccountError({
3780
+ code: "UNREACHABLE",
3781
+ message: "Resource authorization authority unavailable",
3782
+ retryable: true,
3783
+ httpStatus: 503
3784
+ });
3785
+ }
3786
+ __name(unavailable, "unavailable");
3787
+ function decodePart(part) {
3788
+ if (!/^[a-zA-Z0-9_-]+$/.test(part) || part.length % 4 === 1) throw denied();
3789
+ const padded = part.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - part.length % 4) % 4);
3790
+ try {
3791
+ return Uint8Array.from(atob(padded), (value) => value.charCodeAt(0));
3792
+ } catch {
3793
+ throw denied();
3794
+ }
3795
+ }
3796
+ __name(decodePart, "decodePart");
3797
+ function record(bytes2) {
3798
+ try {
3799
+ return parseJwtObject(new TextDecoder("utf-8", {
3800
+ fatal: true
3801
+ }).decode(bytes2));
3802
+ } catch {
3803
+ throw denied();
3804
+ }
3805
+ }
3806
+ __name(record, "record");
3807
+ async function sha(value) {
3808
+ const bytes2 = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value)));
3809
+ return btoa(String.fromCharCode(...bytes2)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
3810
+ }
3811
+ __name(sha, "sha");
3812
+ function frozenClaims(claims) {
3813
+ return Object.freeze({
3814
+ iss: claims.iss,
3815
+ sub: claims.sub,
3816
+ aud: claims.aud,
3817
+ exp: claims.exp,
3818
+ iat: claims.iat,
3819
+ sid: claims.sid,
3820
+ client_id: claims.client_id,
3821
+ azp: claims.azp,
3822
+ scope: claims.scope,
3823
+ typ: claims.typ,
3824
+ auth_epoch: claims.auth_epoch,
3825
+ ...claims.auth_time === void 0 ? {} : {
3826
+ auth_time: claims.auth_time
3827
+ },
3828
+ ...claims.acr ? {
3829
+ acr: claims.acr
3830
+ } : {},
3831
+ cnf: Object.freeze({
3832
+ jkt: claims.cnf.jkt
3833
+ }),
3834
+ ...Array.isArray(claims.aud) ? {
3835
+ aud: Object.freeze([
3836
+ ...claims.aud
3837
+ ])
3838
+ } : {},
3839
+ ...claims.act ? {
3840
+ act: Object.freeze({
3841
+ client_id: claims.act.client_id,
3842
+ installation_id_hash: claims.act.installation_id_hash,
3843
+ ...claims.act.sub ? {
3844
+ sub: claims.act.sub
3845
+ } : {}
3846
+ })
3847
+ } : {},
3848
+ ...claims.amr ? {
3849
+ amr: Object.freeze([
3850
+ ...claims.amr
3851
+ ])
3852
+ } : {}
3853
+ });
3854
+ }
3855
+ __name(frozenClaims, "frozenClaims");
3856
+ function createResourceRequestAuthorizer(options) {
3857
+ const issuer = normalizeDpopHtu(options.issuer);
3858
+ if (issuer.replace(/\/$/, "") !== options.issuer || !options.clientIds.length || options.clientIds.length > 128 || options.clientIds.some((id5) => !/^[a-zA-Z0-9._-]{1,128}$/.test(id5)) || new Set(options.clientIds).size !== options.clientIds.length) throw new TypeError("Explicit canonical issuer and unique clients required");
3859
+ const clients = new Set(options.clientIds);
3860
+ return {
3861
+ async authorize(request) {
3862
+ request = Object.freeze({
3863
+ ...request,
3864
+ ...request.scopes ? {
3865
+ scopes: [
3866
+ ...request.scopes
3867
+ ]
3868
+ } : {}
3869
+ });
3870
+ if (!/^[A-Z]{3,16}$/.test(request.method) || request.url.length > 8192 || request.authorization.length > MAX_JWT_BYTES + 5 || request.proof.length > MAX_JWT_BYTES || !request.proof || (request.scopes?.length ?? 0) > 128) throw denied();
3871
+ let url;
3872
+ try {
3873
+ const parsed = new URL(request.url);
3874
+ if (parsed.username || parsed.password || parsed.hash) throw denied();
3875
+ url = normalizeDpopHtu(request.url);
3876
+ } catch {
3877
+ throw denied();
3878
+ }
3879
+ const match = /^DPoP ([a-zA-Z0-9_.-]+)$/.exec(request.authorization);
3880
+ if (!match) throw denied();
3881
+ const token = match[1];
3882
+ const parts = request.proof.split(".");
3883
+ if (parts.length !== 3) throw denied();
3884
+ const header = record(decodePart(parts[0])), proof = record(decodePart(parts[1]));
3885
+ if (header.typ !== "dpop+jwt" || header.alg !== "ES256" || header.crit !== void 0 || header.b64 !== void 0 || !header.jwk || typeof header.jwk !== "object" || Array.isArray(header.jwk)) throw denied();
3886
+ const supplied = header.jwk;
3887
+ if (PRIVATE_FIELDS.some((field) => supplied[field] !== void 0) || supplied.kty !== "EC" || supplied.crv !== "P-256" || typeof supplied.x !== "string" || typeof supplied.y !== "string" || decodePart(supplied.x).length !== 32 || decodePart(supplied.y).length !== 32) throw denied();
3888
+ const jwk = {
3889
+ kty: "EC",
3890
+ crv: "P-256",
3891
+ x: supplied.x,
3892
+ y: supplied.y
3893
+ };
3894
+ const jkt = await sha(JSON.stringify({
3895
+ crv: jwk.crv,
3896
+ kty: jwk.kty,
3897
+ x: jwk.x,
3898
+ y: jwk.y
3899
+ }));
3900
+ const now = Math.floor(Date.now() / 1e3);
3901
+ if (typeof proof.jti !== "string" || !/^[a-zA-Z0-9._:-]{1,128}$/.test(proof.jti) || !Number.isSafeInteger(proof.iat) || Number(proof.iat) < now - 60 || Number(proof.iat) > now + 60 || proof.htm !== request.method || proof.htu !== url || proof.ath !== await sha(token) || (request.nonce === void 0 ? proof.nonce !== void 0 : proof.nonce !== request.nonce)) throw denied();
3902
+ try {
3903
+ const key = await crypto.subtle.importKey("jwk", jwk, {
3904
+ name: "ECDSA",
3905
+ namedCurve: "P-256"
3906
+ }, false, [
3907
+ "verify"
3908
+ ]);
3909
+ if (!await crypto.subtle.verify({
3910
+ name: "ECDSA",
3911
+ hash: "SHA-256"
3912
+ }, key, decodePart(parts[2]), new TextEncoder().encode(`${parts[0]}.${parts[1]}`))) throw denied();
3913
+ } catch {
3914
+ throw denied();
3915
+ }
3916
+ const tokenParts = token.split(".");
3917
+ if (tokenParts.length !== 3) throw denied();
3918
+ const tokenHeader = record(decodePart(tokenParts[0]));
3919
+ if (tokenHeader.alg !== "ES256" || tokenHeader.typ !== "at+jwt" || typeof tokenHeader.kid !== "string" || tokenHeader.kid.length > 128 || tokenHeader.crit !== void 0 || tokenHeader.b64 !== void 0 || tokenHeader.jku !== void 0 || tokenHeader.jwk !== void 0 || tokenHeader.x5u !== void 0) throw denied();
3920
+ const untrusted = record(decodePart(tokenParts[1]));
3921
+ if (untrusted.auth_time !== void 0 && (!Number.isSafeInteger(untrusted.auth_time) || Number(untrusted.auth_time) < 0 || Number(untrusted.auth_time) > now + 30)) throw denied();
3922
+ if (untrusted.acr !== void 0 && (typeof untrusted.acr !== "string" || untrusted.acr.length > 128)) throw denied();
3923
+ if (untrusted.amr !== void 0 && (!Array.isArray(untrusted.amr) || untrusted.amr.length > 16 || untrusted.amr.some((method) => typeof method !== "string" || !/^[a-zA-Z0-9._:-]{1,64}$/.test(method)))) throw denied();
3924
+ if (typeof untrusted.client_id !== "string" || !clients.has(untrusted.client_id)) throw denied();
3925
+ let verified;
3926
+ try {
3927
+ verified = await verifyAccessToken({
3928
+ token,
3929
+ transport: options.transport,
3930
+ issuer: options.issuer,
3931
+ clientId: untrusted.client_id,
3932
+ dpopJkt: jkt,
3933
+ expectedScopes: [
3934
+ ...request.scopes ?? []
3935
+ ]
3936
+ });
3937
+ } catch (error) {
3938
+ if (error instanceof AccountError && error.retryable) throw unavailable();
3939
+ throw denied();
3940
+ }
3941
+ if (!verified.sub || verified.sub.length > 256 || !verified.sid || verified.sid.length > 256 || !Number.isSafeInteger(verified.auth_epoch) || verified.auth_epoch < 0 || typeof verified.scope !== "string" || verified.scope.length > 8192) throw denied();
3942
+ const claims = frozenClaims(verified);
3943
+ const active = /* @__PURE__ */ __name(async () => {
3944
+ if (claims.exp <= Math.floor(Date.now() / 1e3)) throw denied();
3945
+ let current;
3946
+ try {
3947
+ current = await options.sessionActive(claims, token);
3948
+ } catch {
3949
+ throw unavailable();
3950
+ }
3951
+ if (current !== true) throw denied();
3952
+ }, "active");
3953
+ await active();
3954
+ let consumed;
3955
+ try {
3956
+ consumed = await options.replayStore.consume({
3957
+ keyThumbprint: jkt,
3958
+ proofId: proof.jti,
3959
+ method: request.method,
3960
+ url,
3961
+ expiresAtMs: Math.min(claims.exp * 1e3, (Number(proof.iat) + 61) * 1e3)
3962
+ });
3963
+ } catch {
3964
+ throw unavailable();
3965
+ }
3966
+ if (consumed !== true) throw denied();
3967
+ await active();
3968
+ return Object.freeze({
3969
+ claims,
3970
+ revalidate: active
3971
+ });
3972
+ }
3973
+ };
3974
+ }
3975
+ __name(createResourceRequestAuthorizer, "createResourceRequestAuthorizer");
3976
+ function createOidcIntrospectionSessionAuthority(options) {
3977
+ const base2 = new URL(options.issuer);
3978
+ const timeoutMs = options.timeoutMs ?? 5e3;
3979
+ if (base2.origin !== options.issuer || base2.protocol !== "https:" || !Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 3e4) throw new TypeError("Canonical HTTPS issuer and bounded introspection timeout required");
3980
+ const fetchImpl = options.fetchImpl ?? fetch;
3981
+ return async (claims, token) => {
3982
+ if (token.length > MAX_JWT_BYTES || !token) throw unavailable();
3983
+ const controller = new AbortController();
3984
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
3985
+ let response;
3986
+ try {
3987
+ response = await fetchBeforeAbort(fetchImpl, `${base2.origin}/api/oauth2/introspect`, {
3988
+ method: "POST",
3989
+ redirect: "error",
3990
+ cache: "no-store",
3991
+ credentials: "omit",
3992
+ signal: controller.signal,
3993
+ headers: {
3994
+ accept: "application/json",
3995
+ "content-type": "application/x-www-form-urlencoded"
3996
+ },
3997
+ body: new URLSearchParams({
3998
+ token
3999
+ }).toString()
4000
+ }, controller.signal);
4001
+ if (!response.ok || !response.body) throw unavailable();
4002
+ const value = parseJwtObject(await readBoundedText(response, controller.signal, 32768));
4003
+ if (value.active === false) return false;
4004
+ const canonicalAudience = Array.isArray(value.aud) ? value.aud.includes("xeno-api") : value.aud === "xeno-api";
4005
+ return value.active === true && value.token_type === "access_token" && value.iss === claims.iss && value.sub === claims.sub && value.sid === claims.sid && value.client_id === claims.client_id && value.exp === claims.exp && value.scope === claims.scope && canonicalAudience;
4006
+ } catch {
4007
+ throw unavailable();
4008
+ } finally {
4009
+ controller.abort();
4010
+ clearTimeout(timer);
4011
+ if (response) cancelBody(response);
4012
+ }
4013
+ };
4014
+ }
4015
+ __name(createOidcIntrospectionSessionAuthority, "createOidcIntrospectionSessionAuthority");
4016
+
4017
+ // src/index.ts
4018
+ var ACCOUNT_SDK_CONTRACT = Object.freeze({
4019
+ version: 1,
4020
+ workspaceAuthority: 1,
4021
+ workforceResourceOperations: 1,
4022
+ workforceActorBinding: 2,
4023
+ workforceOwnedCatalog: 1,
4024
+ workspaceKeyAuthority: 1,
4025
+ workspaceKeyOperations: 1,
4026
+ workspaceMembershipOperations: 1,
4027
+ workspaceOperationAbandonment: 1,
4028
+ accountOperations: 1,
4029
+ accountIntegrations: 1,
4030
+ notificationAuthority: 1,
4031
+ notificationDestinationOperations: 1,
4032
+ requestBoundAuthorization: 1,
4033
+ serializedRefresh: 1
4034
+ });
4035
+ // Annotate the CommonJS export names for ESM import in node:
4036
+ 0 && (module.exports = {
4037
+ ACCOUNT_SDK_CONTRACT,
4038
+ AccountClient,
4039
+ AccountError,
4040
+ AccountIntegrationClient,
4041
+ AccountMutationError,
4042
+ AuthzClient,
4043
+ BffSessionClient,
4044
+ LedgerClient,
4045
+ MICRO_PER_CREDIT,
4046
+ NotificationsClient,
4047
+ Transport,
4048
+ WorkforceClient,
4049
+ WorkforceResourceMutationError,
4050
+ WorkspaceClient,
4051
+ WorkspaceKeyMutationError,
4052
+ WorkspaceMembershipMutationError,
4053
+ XenoAccountClient,
4054
+ accountOperationIntentSchema,
4055
+ accountSchema,
4056
+ assertMembershipOperation,
4057
+ authzCheckSchema,
4058
+ authzResultSchema,
4059
+ balanceSchema,
4060
+ buildAuthorizeUrl,
4061
+ codeForStatus,
4062
+ createOidcIntrospectionSessionAuthority,
4063
+ createResourceRequestAuthorizer,
4064
+ exchangeCode,
4065
+ fromMicro,
4066
+ generatePkce,
4067
+ generateState,
4068
+ holdRequestSchema,
4069
+ holdSchema,
4070
+ keychainStore,
4071
+ membershipAbandonedSchema,
4072
+ membershipCommittedSchema,
4073
+ membershipDeliverySchema,
4074
+ membershipMutationSchema,
4075
+ membershipOperationSchema,
4076
+ membershipRejectedSchema,
4077
+ memoryStore,
4078
+ meterAggregationSchema,
4079
+ normalize,
4080
+ normalizeDpopHtu,
4081
+ notificationChannelSchema,
4082
+ notificationDestinationActionSchema,
4083
+ notificationDestinationOperationSchema,
4084
+ notificationEventSchema,
4085
+ notificationRuleSchema,
4086
+ notificationScopeSchema,
4087
+ notificationSettingsSchema,
4088
+ oauthTokenResponseSchema,
4089
+ pollDeviceToken,
4090
+ redact,
4091
+ refreshTokens,
4092
+ startDeviceAuthorization,
4093
+ surfaceSchema,
4094
+ toMicro,
4095
+ tokenSetSchema,
4096
+ usageEventSchema,
4097
+ usageResultSchema,
4098
+ verifyAccessToken,
4099
+ verifyIdToken,
4100
+ verifyLogoutToken,
4101
+ workforceCreateResourceSchema,
4102
+ workforceDefinitionSchema,
4103
+ workforceListOwnedResourcesSchema,
4104
+ workforceOwnerSchema,
4105
+ workforceReadOperationSchema,
4106
+ workspaceInviteRoleSchema,
4107
+ workspaceInviteSchema,
4108
+ workspaceKeyOperationSchema,
4109
+ workspaceKeyRejectionSchema,
4110
+ workspaceKeySchema,
4111
+ workspaceKeyScopeSchema,
4112
+ workspaceMemberSchema,
4113
+ workspaceRoleSchema,
4114
+ workspaceSchema
4115
+ });
4116
+ //# sourceMappingURL=index.js.map