@xano/sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (336) hide show
  1. package/CHANGELOG.md +788 -0
  2. package/LICENSE +21 -0
  3. package/README.md +541 -0
  4. package/dist/.build-fingerprint +1 -0
  5. package/dist/agent-file-refresh-ZEMK33AX.js +38 -0
  6. package/dist/answer-shape-K67TAAPY.js +33 -0
  7. package/dist/backend-dir-2U53CIAL.js +39 -0
  8. package/dist/backend-slot-7QXW2QYC.js +28 -0
  9. package/dist/bin.d.ts +1 -0
  10. package/dist/bin.js +255 -0
  11. package/dist/branch-NCRNWQBQ.js +61 -0
  12. package/dist/branch-commands-ACIRCEQJ.js +79 -0
  13. package/dist/bundle.d.ts +223 -0
  14. package/dist/bundle.js +153 -0
  15. package/dist/capture-WAXPD7DR.js +41 -0
  16. package/dist/chunk-27GWNP2I.js +23 -0
  17. package/dist/chunk-2CMJZDCL.js +177 -0
  18. package/dist/chunk-2EZ3ZJZZ.js +302 -0
  19. package/dist/chunk-2GNFDZA2.js +390 -0
  20. package/dist/chunk-2MNLRIOX.js +11 -0
  21. package/dist/chunk-2TFRR6JV.js +104 -0
  22. package/dist/chunk-2ZUEE4EK.js +408 -0
  23. package/dist/chunk-36JUQZVQ.js +22 -0
  24. package/dist/chunk-3DRXWLJ5.js +83 -0
  25. package/dist/chunk-3JDU4VRL.js +137 -0
  26. package/dist/chunk-3KZCLN4Z.js +241 -0
  27. package/dist/chunk-3LDULPRE.js +168 -0
  28. package/dist/chunk-3M4LFYNQ.js +111 -0
  29. package/dist/chunk-3XI5CTUE.js +22 -0
  30. package/dist/chunk-3YW23UFH.js +50 -0
  31. package/dist/chunk-45UIT5T2.js +862 -0
  32. package/dist/chunk-4BW2SG2N.js +46 -0
  33. package/dist/chunk-4KHEMC32.js +79 -0
  34. package/dist/chunk-4POWHT2K.js +321 -0
  35. package/dist/chunk-4Q2GN7NW.js +192 -0
  36. package/dist/chunk-5A2PLKZB.js +70 -0
  37. package/dist/chunk-5FBYXK5P.js +159 -0
  38. package/dist/chunk-5HVXPTU4.js +323 -0
  39. package/dist/chunk-5QU2P5CA.js +304 -0
  40. package/dist/chunk-5V5XU32D.js +191 -0
  41. package/dist/chunk-5ZSO4T2G.js +10 -0
  42. package/dist/chunk-622HUCZT.js +10 -0
  43. package/dist/chunk-65HWOMGV.js +177 -0
  44. package/dist/chunk-6ELFRN3P.js +365 -0
  45. package/dist/chunk-6HO3NCSJ.js +1055 -0
  46. package/dist/chunk-6IUMKYWI.js +457 -0
  47. package/dist/chunk-6KEB3C3U.js +65 -0
  48. package/dist/chunk-6MR5TI5V.js +987 -0
  49. package/dist/chunk-6NNTNXN7.js +157 -0
  50. package/dist/chunk-6PBR37LN.js +97 -0
  51. package/dist/chunk-6QXLMMT3.js +155 -0
  52. package/dist/chunk-6ZGJCBZS.js +224 -0
  53. package/dist/chunk-73IVBKMA.js +250 -0
  54. package/dist/chunk-7G3CTU7I.js +286 -0
  55. package/dist/chunk-A3UDOZB6.js +222 -0
  56. package/dist/chunk-A6E77GDW.js +85 -0
  57. package/dist/chunk-AHJWCYQO.js +660 -0
  58. package/dist/chunk-AKNCFVKZ.js +36 -0
  59. package/dist/chunk-AM4FKL4J.js +237 -0
  60. package/dist/chunk-AN6BL47T.js +26 -0
  61. package/dist/chunk-AOSYVMUS.js +147 -0
  62. package/dist/chunk-APWXY5SL.js +182 -0
  63. package/dist/chunk-AWEIIR2U.js +218 -0
  64. package/dist/chunk-AWQ7BQTQ.js +73 -0
  65. package/dist/chunk-BAUZOWGX.js +393 -0
  66. package/dist/chunk-BHACRS6R.js +940 -0
  67. package/dist/chunk-BWPNT55T.js +680 -0
  68. package/dist/chunk-C6RIMRU4.js +187 -0
  69. package/dist/chunk-CGVQZXYG.js +263 -0
  70. package/dist/chunk-CIMQZRRE.js +162 -0
  71. package/dist/chunk-CJHQKJU4.js +113 -0
  72. package/dist/chunk-CTMO46PK.js +1897 -0
  73. package/dist/chunk-D53J55C5.js +106 -0
  74. package/dist/chunk-D7VGG3WS.js +90 -0
  75. package/dist/chunk-DAD3ONIS.js +245 -0
  76. package/dist/chunk-DGWHAVRG.js +162 -0
  77. package/dist/chunk-DX4QR4B2.js +483 -0
  78. package/dist/chunk-EHP3WPEG.js +21 -0
  79. package/dist/chunk-ELP2HMXC.js +432 -0
  80. package/dist/chunk-ERVIASGL.js +21 -0
  81. package/dist/chunk-ET4Y4XCB.js +865 -0
  82. package/dist/chunk-ETO6LGLD.js +4750 -0
  83. package/dist/chunk-EUUUMY7J.js +24 -0
  84. package/dist/chunk-FQJ2TTHP.js +218 -0
  85. package/dist/chunk-FQOF7E2E.js +133 -0
  86. package/dist/chunk-FWD7AL6N.js +21 -0
  87. package/dist/chunk-FXFV3KU6.js +138 -0
  88. package/dist/chunk-FXRQOWTE.js +171 -0
  89. package/dist/chunk-G554NZNI.js +210 -0
  90. package/dist/chunk-GSGDWJB5.js +13 -0
  91. package/dist/chunk-H2V3N23D.js +66 -0
  92. package/dist/chunk-H5C7MBCR.js +159 -0
  93. package/dist/chunk-HHN734BU.js +371 -0
  94. package/dist/chunk-HRVBLCVJ.js +243 -0
  95. package/dist/chunk-HVRUQXGD.js +1264 -0
  96. package/dist/chunk-I4F5TCJH.js +130 -0
  97. package/dist/chunk-IDOTCMDV.js +57 -0
  98. package/dist/chunk-IGOLHKWF.js +427 -0
  99. package/dist/chunk-JGE7CAWB.js +148 -0
  100. package/dist/chunk-JTUKLCXS.js +92 -0
  101. package/dist/chunk-JZGVVJSI.js +66 -0
  102. package/dist/chunk-K4WX6UUU.js +923 -0
  103. package/dist/chunk-K5BBGTYZ.js +217 -0
  104. package/dist/chunk-K6RXBGUB.js +427 -0
  105. package/dist/chunk-KTSDSD36.js +165 -0
  106. package/dist/chunk-L5JYN3NM.js +1038 -0
  107. package/dist/chunk-LIEOKXKD.js +354 -0
  108. package/dist/chunk-LLNZGEFK.js +51 -0
  109. package/dist/chunk-LPECSJ2J.js +55 -0
  110. package/dist/chunk-LQCMKAJ7.js +413 -0
  111. package/dist/chunk-LRN4ZJCQ.js +1145 -0
  112. package/dist/chunk-MJ4ZVHKN.js +17 -0
  113. package/dist/chunk-MXHSQOC4.js +3061 -0
  114. package/dist/chunk-N5GKCWE5.js +367 -0
  115. package/dist/chunk-NA3PXMEF.js +10 -0
  116. package/dist/chunk-NAQDMEHV.js +76 -0
  117. package/dist/chunk-NWKXM5RD.js +109 -0
  118. package/dist/chunk-NZOWWHU5.js +196 -0
  119. package/dist/chunk-OHX6MIUZ.js +184 -0
  120. package/dist/chunk-OOXWYAA4.js +15 -0
  121. package/dist/chunk-OPHB5ORL.js +1990 -0
  122. package/dist/chunk-OXA6PSZT.js +1725 -0
  123. package/dist/chunk-P2HAGF6H.js +73 -0
  124. package/dist/chunk-PTHVMXZI.js +3036 -0
  125. package/dist/chunk-PZ5AY32C.js +10 -0
  126. package/dist/chunk-Q325JKYB.js +189 -0
  127. package/dist/chunk-Q7DGTQ5G.js +255 -0
  128. package/dist/chunk-QCNYHBL7.js +601 -0
  129. package/dist/chunk-QO6BVGS5.js +145 -0
  130. package/dist/chunk-QXTKSOFI.js +76 -0
  131. package/dist/chunk-ROY4YAEQ.js +66 -0
  132. package/dist/chunk-RTJRZFFY.js +447 -0
  133. package/dist/chunk-SAVJUS2X.js +128 -0
  134. package/dist/chunk-SFLHVCKX.js +173 -0
  135. package/dist/chunk-STSFNCY4.js +127 -0
  136. package/dist/chunk-SWBF2LTK.js +170 -0
  137. package/dist/chunk-T5KELPAR.js +109 -0
  138. package/dist/chunk-TFFGOFVZ.js +1481 -0
  139. package/dist/chunk-TLHIFK4M.js +256 -0
  140. package/dist/chunk-TLQE7ZN3.js +156 -0
  141. package/dist/chunk-TPHWJ7UG.js +1981 -0
  142. package/dist/chunk-TRJCALW3.js +291 -0
  143. package/dist/chunk-TTEIYD5P.js +133 -0
  144. package/dist/chunk-U64O2MXY.js +407 -0
  145. package/dist/chunk-UCQ2VUTG.js +630 -0
  146. package/dist/chunk-UTI5G6OJ.js +44 -0
  147. package/dist/chunk-UVHDMMIP.js +188 -0
  148. package/dist/chunk-UZ6QQWJT.js +120 -0
  149. package/dist/chunk-VAX3UZOY.js +686 -0
  150. package/dist/chunk-W3HBUKFO.js +57 -0
  151. package/dist/chunk-WKQLGKCL.js +2823 -0
  152. package/dist/chunk-WQFNASK4.js +560 -0
  153. package/dist/chunk-WRBKLYSJ.js +224 -0
  154. package/dist/chunk-WTPZRR4I.js +17 -0
  155. package/dist/chunk-WZDJ2LLX.js +2385 -0
  156. package/dist/chunk-X2NL4KUO.js +14 -0
  157. package/dist/chunk-X4DVXBFY.js +38 -0
  158. package/dist/chunk-X677DMZM.js +7050 -0
  159. package/dist/chunk-XBKMWY7F.js +612 -0
  160. package/dist/chunk-XNCP4KYO.js +78 -0
  161. package/dist/chunk-XVBGLISP.js +35 -0
  162. package/dist/chunk-XW6KISBB.js +1192 -0
  163. package/dist/chunk-YGZHHAAB.js +8156 -0
  164. package/dist/chunk-YHEFQUQB.js +186 -0
  165. package/dist/chunk-YLDALTWZ.js +653 -0
  166. package/dist/chunk-YU4HSQW7.js +229 -0
  167. package/dist/chunk-ZDPP6RKB.js +27 -0
  168. package/dist/chunk-ZFDZKNGG.js +194 -0
  169. package/dist/chunk-ZIY7RNUT.js +49 -0
  170. package/dist/chunk-ZYJP6BOO.js +30 -0
  171. package/dist/cli.d.ts +1111 -0
  172. package/dist/cli.js +165 -0
  173. package/dist/codegen-command-VR2GWR6C.js +173 -0
  174. package/dist/codegen.d.ts +115 -0
  175. package/dist/codegen.js +19 -0
  176. package/dist/commands-GJMJ4XYZ.js +76 -0
  177. package/dist/completion-ZQLO6PB6.js +738 -0
  178. package/dist/config-MBYGCAFK.js +136 -0
  179. package/dist/deploy-command-JVZPWHMK.js +180 -0
  180. package/dist/deploy-source-3W45CXMP.js +81 -0
  181. package/dist/dev-env-sync-HN44K4D5.js +188 -0
  182. package/dist/diagnostics-UEAAHWVF.js +30 -0
  183. package/dist/display-name-hint-ABBPVQIR.js +46 -0
  184. package/dist/emit-CyhBDxli.d.ts +7007 -0
  185. package/dist/env-example-refresh-ET5HMMDW.js +126 -0
  186. package/dist/env-pull-command-TNMNB3CV.js +323 -0
  187. package/dist/env-target-O4HRKTGZ.js +40 -0
  188. package/dist/env-var-command-ZIRDCAZA.js +427 -0
  189. package/dist/ephemeral-P7F3PMAD.js +54 -0
  190. package/dist/ephemeral-command-CLJJKOFT.js +592 -0
  191. package/dist/ephemeral-state-PYCBSOGX.js +61 -0
  192. package/dist/file-lock-PT74GWYW.js +10 -0
  193. package/dist/generate-command-AYEOLA26.js +510 -0
  194. package/dist/gitignore-3SJ3WNRG.js +51 -0
  195. package/dist/guards-4EBNCZDC.js +162 -0
  196. package/dist/hosted-file-PSHJB3HX.js +28 -0
  197. package/dist/impersonate-command-5JAS3WSV.js +152 -0
  198. package/dist/import-EQSFU6JC.js +19 -0
  199. package/dist/index.d.ts +5470 -0
  200. package/dist/index.js +371 -0
  201. package/dist/init-command-X2FR4UAK.js +125 -0
  202. package/dist/init-modules-RY7UHAOL.js +50 -0
  203. package/dist/init-web-M4YZSZK6.js +42 -0
  204. package/dist/internal.d.ts +179 -0
  205. package/dist/internal.js +2634 -0
  206. package/dist/io-RC56QSN5.js +26 -0
  207. package/dist/keep-data-merge-7MPLVAVI.js +1119 -0
  208. package/dist/lambda-config-reconcile-OUZ4OYAB.js +116 -0
  209. package/dist/landed-753YLJ5H.js +40 -0
  210. package/dist/landing-record-SU52SKXU.js +61 -0
  211. package/dist/live-diff-YONW2VI3.js +65 -0
  212. package/dist/local-engine-choice-CH5X3W7E.js +79 -0
  213. package/dist/local-engine-command-Z3OL7VOD.js +766 -0
  214. package/dist/local-engine-config-5U3SC434.js +39 -0
  215. package/dist/local-engine-deploy-PCQ4SNPB.js +39 -0
  216. package/dist/local-engine-process-EHTE5LLU.js +63 -0
  217. package/dist/local-engine-state-A4FTRFAF.js +32 -0
  218. package/dist/local-engine-update-check-6L645VBL.js +162 -0
  219. package/dist/lock-MRRHW5GS.js +87 -0
  220. package/dist/lock-commands-2QG25HL7.js +963 -0
  221. package/dist/login-command-QPYRWOXZ.js +538 -0
  222. package/dist/logout-command-WOIQLDP6.js +56 -0
  223. package/dist/loop-ALIZLOSX.js +191 -0
  224. package/dist/marketplace-command-K5YL42NO.js +977 -0
  225. package/dist/marketplace-resolve-LY32JES5.js +40 -0
  226. package/dist/meta-client-YXGPW53C.js +244 -0
  227. package/dist/module-manifest-JFGHU2TC.js +38 -0
  228. package/dist/near-key.d.ts +13 -0
  229. package/dist/near-key.js +8 -0
  230. package/dist/node.d.ts +95 -0
  231. package/dist/node.js +969 -0
  232. package/dist/operation-outcome-TZSESNC7.js +51 -0
  233. package/dist/output-target-AL3I44GG.js +47 -0
  234. package/dist/package-manager-PRAHUSCN.js +34 -0
  235. package/dist/plan-disclosure-6G4MLZKD.js +114 -0
  236. package/dist/plugin-contributions-WRNY5ABG.js +28 -0
  237. package/dist/plugin-prompt-4VA3B4FF.js +20 -0
  238. package/dist/plugin-questions-JTSYA74Q.js +24 -0
  239. package/dist/plugin.d.ts +396 -0
  240. package/dist/plugin.js +1 -0
  241. package/dist/preflight-command-2T5Z36MI.js +321 -0
  242. package/dist/profile-command-AH3PIM4X.js +800 -0
  243. package/dist/profile-pointer-GRWJU3YD.js +31 -0
  244. package/dist/profile-select-74TRDEPD.js +23 -0
  245. package/dist/project-dependency-KSH63ODT.js +35 -0
  246. package/dist/project-sdk-REPPOIBD.js +24 -0
  247. package/dist/promote-command-PCWT5N6S.js +140 -0
  248. package/dist/prompt-II3F3LND.js +27 -0
  249. package/dist/publish-command-TTDUUJI5.js +414 -0
  250. package/dist/pull-command-VBO7C4S3.js +161 -0
  251. package/dist/pull-superseded-GJWLG7XO.js +20 -0
  252. package/dist/release-command-N4ZPKMHR.js +146 -0
  253. package/dist/release-ns-command-3KFDMZ6G.js +1745 -0
  254. package/dist/response-HlXahv4K.d.ts +925 -0
  255. package/dist/retry-command-AS5EVREX.js +34 -0
  256. package/dist/routes-manifest-SNWUVBT6.js +43 -0
  257. package/dist/runtime-XETHVF33.js +14 -0
  258. package/dist/scaffold.d.ts +1911 -0
  259. package/dist/scaffold.js +107 -0
  260. package/dist/secrets-file-LVZD6IIM.js +56 -0
  261. package/dist/secrets-fill-command-TTCPSVXN.js +218 -0
  262. package/dist/seed-VU7C3QYS.js +46 -0
  263. package/dist/sent-writes-N7X4OVXT.js +22 -0
  264. package/dist/source-resolve-S2XA3XZF.js +83 -0
  265. package/dist/static-host-B2Y6AG3W.js +352 -0
  266. package/dist/status-command-RUDXTF7I.js +554 -0
  267. package/dist/store-6VNCD4D7.js +20 -0
  268. package/dist/store-ARM6VMO5.js +98 -0
  269. package/dist/store-DuYfzKlW.d.ts +3144 -0
  270. package/dist/suggest-6FOOYKHG.js +12 -0
  271. package/dist/sveltekit.d.ts +154 -0
  272. package/dist/sveltekit.js +109 -0
  273. package/dist/sync-contributions-UCEROO26.js +415 -0
  274. package/dist/table-ENAVMITR.js +42 -0
  275. package/dist/tables-command-GUPXXSB5.js +156 -0
  276. package/dist/tenant-IIHPOHGP.js +42 -0
  277. package/dist/tenant-command-D5HGI2X4.js +965 -0
  278. package/dist/test-command-TIKZMDPZ.js +476 -0
  279. package/dist/tests-BGGIOK3L.js +26 -0
  280. package/dist/token-NICJUTMT.js +72 -0
  281. package/dist/toolchain-hooks-GHKLUJOH.js +96 -0
  282. package/dist/toolchain-modules-5EAZUONB.js +24 -0
  283. package/dist/tracked-backend-EIBUMDZA.js +80 -0
  284. package/dist/update-check-2W2NLDTC.js +136 -0
  285. package/dist/upgrade-command-QHNFWM7O.js +531 -0
  286. package/dist/verify-rollout-DRCK5TDD.js +61 -0
  287. package/dist/whoami-command-STGINTXH.js +51 -0
  288. package/dist/workspace-2CLHU2LK.js +93 -0
  289. package/dist/workspace-binding-56PIIPCP.js +54 -0
  290. package/dist/workspace-command-JEXQETJD.js +535 -0
  291. package/dist/workspace-env-F2RFMSC5.js +70 -0
  292. package/dist/workspace-export-OJSH2HIW.js +21 -0
  293. package/dist/writable-VA7OISSK.js +25 -0
  294. package/dist/xano-ICFUSPFR.js +42 -0
  295. package/dist/xanosdk-import-GN42TO2B.js +56 -0
  296. package/dist/xanosdk-project-S6DXJONQ.js +41 -0
  297. package/dist/xdo-CxDr2Q1C.d.ts +1371 -0
  298. package/guides/README.md +33 -0
  299. package/guides/authoring.md +921 -0
  300. package/guides/cli.md +401 -0
  301. package/guides/codegen.md +177 -0
  302. package/guides/codes.md +404 -0
  303. package/guides/coverage.md +74 -0
  304. package/guides/deploying.md +1525 -0
  305. package/guides/environment.md +400 -0
  306. package/guides/marketplace.md +415 -0
  307. package/guides/module-contract.md +558 -0
  308. package/guides/object-kinds.md +433 -0
  309. package/guides/project-structure.md +43 -0
  310. package/guides/scaffold.md +351 -0
  311. package/guides/typed-frontend.md +242 -0
  312. package/llms/client.md +63 -0
  313. package/llms/errors.md +56 -0
  314. package/llms/fields.md +176 -0
  315. package/llms/filters.md +183 -0
  316. package/llms/kinds-agent-mcp.md +30 -0
  317. package/llms/kinds-core.md +100 -0
  318. package/llms/kinds-knowledge.md +20 -0
  319. package/llms/kinds-realtime.md +76 -0
  320. package/llms/lambda.md +94 -0
  321. package/llms/legacy.md +44 -0
  322. package/llms/lock.md +40 -0
  323. package/llms/object-kinds.md +34 -0
  324. package/llms/statements-calls.md +62 -0
  325. package/llms/statements-catalog.md +320 -0
  326. package/llms/statements-data.md +66 -0
  327. package/llms/statements-runtime.md +68 -0
  328. package/llms/tests.md +59 -0
  329. package/llms/toolchain.md +16 -0
  330. package/llms/triggers.md +36 -0
  331. package/llms/values.md +29 -0
  332. package/llms-full.txt +2085 -0
  333. package/llms.txt +493 -0
  334. package/manifest.json +11224 -0
  335. package/package.json +162 -0
  336. package/types/lambda-globals.d.ts +129 -0
@@ -0,0 +1,36 @@
1
+ // src/responses/raw-response.ts
2
+ var RAW_RESPONSE = /* @__PURE__ */ Symbol.for("xanosdk.response.rawEnvelope");
3
+ var CANONICAL_KEYS = ["filters", "name", "tag", "value", "_xsid", "disabled"];
4
+ function rawResponse(items) {
5
+ if (!Array.isArray(items)) {
6
+ throw new Error(
7
+ 'rawResponse() expects an array of stored result[] entries, e.g. `[{ name: "", tag: "input", value: "x", filters: [] }]` \u2014 but received ' + (items === null ? "null" : typeof items)
8
+ );
9
+ }
10
+ const stored = items.map((item, i) => {
11
+ if (item == null || typeof item !== "object" || Array.isArray(item)) {
12
+ throw new Error(
13
+ `rawResponse() item ${i} is not a stored result envelope object \u2014 received ` + (item === null ? "null" : Array.isArray(item) ? "an array" : typeof item)
14
+ );
15
+ }
16
+ const out = {};
17
+ for (const key of CANONICAL_KEYS) {
18
+ if (Object.hasOwn(item, key)) out[key] = item[key];
19
+ }
20
+ for (const key of Object.keys(item)) {
21
+ if (!Object.hasOwn(out, key)) out[key] = item[key];
22
+ }
23
+ return out;
24
+ });
25
+ return { [RAW_RESPONSE]: stored };
26
+ }
27
+ function rawResponseItems(response) {
28
+ if (response == null || typeof response !== "object") return void 0;
29
+ return response[RAW_RESPONSE];
30
+ }
31
+
32
+ export {
33
+ rawResponse,
34
+ rawResponseItems
35
+ };
36
+ //# sourceMappingURL=chunk-AKNCFVKZ.js.map
@@ -0,0 +1,237 @@
1
+ import {
2
+ readEnvVar
3
+ } from "./chunk-X2NL4KUO.js";
4
+
5
+ // src/deploy/local-engine-config.ts
6
+ import { existsSync, readdirSync } from "fs";
7
+ import { homedir } from "os";
8
+ import { isAbsolute, join, resolve } from "path";
9
+
10
+ // src/deploy/local-engine-handshake.ts
11
+ var LOOPBACK_HOSTS = ["127.0.0.1", "::1", "localhost"];
12
+ var ALLOWED_PROTOCOLS = ["http:", "https:"];
13
+ function isLoopbackUrl(url) {
14
+ let parsed;
15
+ try {
16
+ parsed = new URL(url);
17
+ } catch {
18
+ return false;
19
+ }
20
+ if (!ALLOWED_PROTOCOLS.includes(parsed.protocol)) return false;
21
+ const host = parsed.hostname.replace(/^\[|\]$/g, "");
22
+ if (!LOOPBACK_HOSTS.includes(host)) return false;
23
+ return /^[0-9]+$/.test(parsed.port);
24
+ }
25
+ function assertLoopbackUrl(url, what) {
26
+ if (isLoopbackUrl(url)) return;
27
+ throw new Error(
28
+ `${what} reports a url this SDK will not send a token to: ${url}
29
+ A local engine has to serve loopback over http on a port of its own \u2014 ${LOOPBACK_HOSTS.join(", ")} \u2014 and anything else is reachable from off this machine. Stop that engine and start a fresh one without binding it to all interfaces.`
30
+ );
31
+ }
32
+ function requireString(raw, key, source) {
33
+ const value = raw[key];
34
+ if (typeof value !== "string" || value === "") {
35
+ throw new Error(
36
+ `${source} is missing \`${key}\`, or gave it as something other than text.
37
+ That is not an engine this SDK knows how to drive \u2014 the engine on this machine is older or newer than the one it was built against. Move to a current one with \`xanosdk local-engine update\`.`
38
+ );
39
+ }
40
+ return value;
41
+ }
42
+ function requireNumber(raw, key, source) {
43
+ const value = raw[key];
44
+ if (typeof value !== "number" || !Number.isFinite(value)) {
45
+ throw new Error(
46
+ `${source} is missing \`${key}\`, or gave it as something other than a number.
47
+ That is not an engine this SDK knows how to drive \u2014 the engine on this machine is older or newer than the one it was built against. Move to a current one with \`xanosdk local-engine update\`.`
48
+ );
49
+ }
50
+ return value;
51
+ }
52
+ function readEngine(value, source) {
53
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
54
+ throw new Error(
55
+ `${source} did not print an engine description.
56
+ Re-run, and if it happens again fetch a fresh copy with \`xanosdk local-engine cache clear\`, then \`xanosdk deploy --local-engine\`.`
57
+ );
58
+ }
59
+ const raw = value;
60
+ return {
61
+ name: requireString(raw, "name", source),
62
+ url: requireString(raw, "url", source),
63
+ workspaceId: requireNumber(raw, "workspace_id", source),
64
+ token: requireString(raw, "access_token", source),
65
+ pid: requireNumber(raw, "pid", source),
66
+ signInUrl: requireString(raw, "sign_in_url", source),
67
+ loginLinkEndpoint: requireString(raw, "login_link_endpoint", source),
68
+ logPath: requireString(raw, "log", source)
69
+ };
70
+ }
71
+ var HANDSHAKE_SOURCE = "The engine's start handshake";
72
+ var LISTING_SOURCE = "The engine's list of running engines";
73
+ function parseEngineHandshake(stdout) {
74
+ let value;
75
+ try {
76
+ value = JSON.parse(stdout.trim());
77
+ } catch {
78
+ throw new Error(
79
+ `${HANDSHAKE_SOURCE} did not print an engine description.
80
+ Re-run, and if it happens again fetch a fresh copy with \`xanosdk local-engine cache clear\`, then \`xanosdk deploy --local-engine\`.`
81
+ );
82
+ }
83
+ const engine = readEngine(value, HANDSHAKE_SOURCE);
84
+ assertLoopbackUrl(engine.url, "The engine that just started");
85
+ return engine;
86
+ }
87
+ function parseEngineListing(stdout) {
88
+ const text = stdout.trim();
89
+ if (text === "") return [];
90
+ let value;
91
+ try {
92
+ value = JSON.parse(text);
93
+ } catch {
94
+ throw new Error(
95
+ `${LISTING_SOURCE} was not readable.
96
+ Re-run, and if it happens again fetch a fresh copy with \`xanosdk local-engine cache clear\`, then \`xanosdk deploy --local-engine\`.`
97
+ );
98
+ }
99
+ if (!Array.isArray(value)) {
100
+ throw new Error(
101
+ `${LISTING_SOURCE} was not a list.
102
+ Re-run, and if it happens again fetch a fresh copy with \`xanosdk local-engine cache clear\`, then \`xanosdk deploy --local-engine\`.`
103
+ );
104
+ }
105
+ return value.filter((entry) => !isForeignEngine(entry)).map((entry) => readEngine(entry, LISTING_SOURCE));
106
+ }
107
+ function isForeignEngine(entry) {
108
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return false;
109
+ const raw = entry;
110
+ return raw.workspace_id === void 0 && raw.access_token === void 0;
111
+ }
112
+
113
+ // src/deploy/local-engine-config.ts
114
+ var SUPPORTED_PLATFORMS = [
115
+ "darwin-arm64",
116
+ "linux-x64",
117
+ "linux-arm64"
118
+ ];
119
+ function resolveEnginePlatform(platform = process.platform, arch = process.arch) {
120
+ const pair = `${platform}-${arch}`;
121
+ return SUPPORTED_PLATFORMS.find((p) => p === pair);
122
+ }
123
+ var LOCAL_ENGINE_HOME_ENV = "XANOSDK_LOCAL_ENGINE_HOME";
124
+ function localEngineHome(env = process.env) {
125
+ return readEnvVar(LOCAL_ENGINE_HOME_ENV, env) ?? join(homedir(), ".xanosdk", "local-engine");
126
+ }
127
+ function engineRunHome(env = process.env) {
128
+ return join(localEngineHome(env), "engine");
129
+ }
130
+ function engineCacheDir(env = process.env, platform = process.platform) {
131
+ return join(engineRunHome(env), ...platform === "darwin" ? ["Library", "Caches"] : [".cache"]);
132
+ }
133
+ function legacyRuntimeDirs(env = process.env, platform = process.platform) {
134
+ const home = env.HOME !== void 0 && env.HOME !== "" ? env.HOME : homedir();
135
+ const cache = join(home, ...platform === "darwin" ? ["Library", "Caches"] : [".cache"]);
136
+ if (resolve(cache) === resolve(engineCacheDir(env, platform))) return [];
137
+ let names;
138
+ try {
139
+ names = readdirSync(cache, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name);
140
+ } catch {
141
+ return [];
142
+ }
143
+ return names.map((name) => join(cache, name)).filter((dir) => ["dist", "instances", "logs"].every((sub) => existsSync(join(dir, sub))));
144
+ }
145
+ function localEngineBinDir(env = process.env) {
146
+ return join(localEngineHome(env), "bin");
147
+ }
148
+ var LOCAL_ENGINE_OVERRIDE_ENV = "XANOSDK_LOCAL_ENGINE_OVERRIDE";
149
+ var OVERRIDE_VERSION = /^v?\d+\.\d+\.\d+$/;
150
+ function overrideSpec(value) {
151
+ if (OVERRIDE_VERSION.test(value)) {
152
+ return { kind: "release", version: value.startsWith("v") ? value : `v${value}` };
153
+ }
154
+ return { kind: "override", source: value };
155
+ }
156
+ function isTrustedEngineUrl(value) {
157
+ let url;
158
+ try {
159
+ url = new URL(value);
160
+ } catch {
161
+ return true;
162
+ }
163
+ if (url.protocol === "https:") return true;
164
+ return url.protocol === "http:" && LOOPBACK_HOSTS.includes(url.hostname.replace(/^\[|\]$/g, ""));
165
+ }
166
+ function expandArchivePath(source, env = process.env) {
167
+ const home = env["HOME"] ?? homedir();
168
+ const expanded = source === "~" ? home : source.startsWith("~/") ? home + source.slice(1) : source;
169
+ return isAbsolute(expanded) ? expanded : resolve(expanded);
170
+ }
171
+ var ARCHIVE_SUFFIX = /\.(tar\.gz|tgz|gz|tar|zip)$/i;
172
+ function engineOverrideRefusal(value, where, env = process.env) {
173
+ if (/^https?:\/\//i.test(value)) {
174
+ if (isTrustedEngineUrl(value)) return void 0;
175
+ return `${where} names an engine over plain http on a host that is not this machine. An engine is a program this command runs, so fetched that way anyone on the network path could swap it (and read XANOSDK_LOCAL_ENGINE_TOKEN if it is set). Nothing was requested.
176
+ Serve the archive over https://, or over http:// from 127.0.0.1, ::1 or localhost.`;
177
+ }
178
+ const scheme = /^([a-z][a-z0-9+.-]*):\/\//i.exec(value);
179
+ if (scheme !== null) {
180
+ return `${where} names a URL with the ${scheme[1].toLowerCase()}:// scheme, and an engine is fetched only over https:// (or http:// from this machine). Nothing was requested.
181
+ Pass ${where} an https:// URL, a version like v0.1.5, or the path to an engine archive.`;
182
+ }
183
+ if (OVERRIDE_VERSION.test(value)) return void 0;
184
+ const looksLikeVersion = !/[\\/~]/.test(value) && !ARCHIVE_SUFFIX.test(value) && (/^v[0-9a-z.+-]*$/i.test(value) || /^\d+(\.[0-9a-z+-]*)*$/i.test(value));
185
+ if (looksLikeVersion && !existsSync(value)) {
186
+ return `"${value}" is not an engine version \u2014 they are written vMAJOR.MINOR.PATCH, like v0.1.5 \u2014 and no archive file has that name here.
187
+ Pass ${where} a version in that form, an https:// URL, or the path to an engine archive.`;
188
+ }
189
+ const path = expandArchivePath(value, env);
190
+ if (!existsSync(path)) {
191
+ return `${MISSING_ARCHIVE} ${path}.
192
+ Check the path \u2014 ${where} is read exactly as passed, with \`~\` and relative paths resolved from where the command ran.`;
193
+ }
194
+ return void 0;
195
+ }
196
+ var MISSING_ARCHIVE = "There is no engine archive to read at";
197
+ function engineSourceRefusal(flagValue, env = process.env) {
198
+ if (flagValue !== void 0 && flagValue !== "") return engineOverrideRefusal(flagValue, "`--local-engine`", env);
199
+ const fromEnv = readEnvVar(LOCAL_ENGINE_OVERRIDE_ENV, env)?.trim();
200
+ if (fromEnv === void 0) return void 0;
201
+ return engineOverrideRefusal(fromEnv, LOCAL_ENGINE_OVERRIDE_ENV, env);
202
+ }
203
+ function engineOverrideFromEnv(env = process.env) {
204
+ const value = readEnvVar(LOCAL_ENGINE_OVERRIDE_ENV, env)?.trim();
205
+ return value === void 0 ? void 0 : overrideSpec(value);
206
+ }
207
+ function resolveEngineSource(flagValue, env = process.env, pinned) {
208
+ if (flagValue !== void 0 && flagValue !== "") return overrideSpec(flagValue);
209
+ const fromEnv = engineOverrideFromEnv(env);
210
+ if (fromEnv !== void 0) return fromEnv;
211
+ return pinned === void 0 ? { kind: "release" } : { kind: "release", version: pinned };
212
+ }
213
+
214
+ export {
215
+ LOOPBACK_HOSTS,
216
+ isLoopbackUrl,
217
+ assertLoopbackUrl,
218
+ parseEngineHandshake,
219
+ parseEngineListing,
220
+ SUPPORTED_PLATFORMS,
221
+ resolveEnginePlatform,
222
+ LOCAL_ENGINE_HOME_ENV,
223
+ localEngineHome,
224
+ engineRunHome,
225
+ engineCacheDir,
226
+ legacyRuntimeDirs,
227
+ localEngineBinDir,
228
+ LOCAL_ENGINE_OVERRIDE_ENV,
229
+ isTrustedEngineUrl,
230
+ expandArchivePath,
231
+ engineOverrideRefusal,
232
+ MISSING_ARCHIVE,
233
+ engineSourceRefusal,
234
+ engineOverrideFromEnv,
235
+ resolveEngineSource
236
+ };
237
+ //# sourceMappingURL=chunk-AM4FKL4J.js.map
@@ -0,0 +1,26 @@
1
+ import {
2
+ httpFailure
3
+ } from "./chunk-YLDALTWZ.js";
4
+
5
+ // src/deploy/import.ts
6
+ var ImportHttpError = class extends Error {
7
+ constructor(status, action, statusText, body, aftermath) {
8
+ const head = httpFailure(action, { status, statusText }, body);
9
+ super(aftermath === void 0 ? head : `${head}
10
+ ${aftermath}`);
11
+ this.status = status;
12
+ this.body = body;
13
+ this.name = "ImportHttpError";
14
+ }
15
+ status;
16
+ body;
17
+ };
18
+ function isSignatureRefusal(err) {
19
+ return err instanceof ImportHttpError && /invalid workspace signature/i.test(err.body);
20
+ }
21
+
22
+ export {
23
+ ImportHttpError,
24
+ isSignatureRefusal
25
+ };
26
+ //# sourceMappingURL=chunk-AN6BL47T.js.map
@@ -0,0 +1,147 @@
1
+ import {
2
+ exportWorkspaceBundle
3
+ } from "./chunk-CJHQKJU4.js";
4
+ import {
5
+ encodeWorkspaceArchive,
6
+ readArchiveEntries
7
+ } from "./chunk-3DRXWLJ5.js";
8
+ import {
9
+ tarGz
10
+ } from "./chunk-X4DVXBFY.js";
11
+ import {
12
+ resolveSource
13
+ } from "./chunk-QCNYHBL7.js";
14
+ import {
15
+ downloadRelease
16
+ } from "./chunk-2ZUEE4EK.js";
17
+ import {
18
+ backendDirIn
19
+ } from "./chunk-5A2PLKZB.js";
20
+ import {
21
+ BARE,
22
+ UsageError,
23
+ isKindShaped,
24
+ parseSource,
25
+ relForwardSlash
26
+ } from "./chunk-PTHVMXZI.js";
27
+ import {
28
+ calcSignatureJson
29
+ } from "./chunk-LQCMKAJ7.js";
30
+
31
+ // src/emit/deploy-source.ts
32
+ import { existsSync } from "fs";
33
+ import { join } from "path";
34
+ var DEPLOY_SOURCE_KINDS = [
35
+ "release",
36
+ "ephemeral",
37
+ "tenant",
38
+ "workspace",
39
+ "local-engine"
40
+ ];
41
+ var ENTRY_FILE = "index.ts";
42
+ function looksLikeSource(raw) {
43
+ return isKindShaped(raw) || BARE.includes(raw);
44
+ }
45
+ function resolveProjectEntry(cwd) {
46
+ const entry = join(backendDirIn(cwd), ENTRY_FILE);
47
+ if (!existsSync(entry)) return void 0;
48
+ return `./${relForwardSlash(cwd, entry)}`;
49
+ }
50
+ async function fetchSourceArchive(credential, raw, cwd = process.cwd(), deps = {}) {
51
+ const source = parseSource(raw, DEPLOY_SOURCE_KINDS, { command: "deploy" });
52
+ const resolved = await resolveSource(source, credential, { ...deps, cwd });
53
+ if (resolved.kind === "release" && resolved.backend.kind === "hosted") {
54
+ const { auth } = resolved.backend;
55
+ const release = resolved.release;
56
+ if (release?.id === void 0) {
57
+ throw new UsageError(`Release "${raw}" carries no id, so it cannot be deployed.`, {
58
+ helpFor: { command: "deploy" }
59
+ });
60
+ }
61
+ return {
62
+ archive: asWorkspaceArchive(
63
+ await downloadRelease(auth, { workspaceId: auth.workspaceId, id: release.id }),
64
+ release.name
65
+ ),
66
+ provenance: resolved.provenance,
67
+ label: release.name
68
+ };
69
+ }
70
+ const exported = await exportWorkspaceBundle(resolved.bearer, resolved.target);
71
+ const display = resolved.target.display;
72
+ return {
73
+ archive: encodeWorkspaceArchive(JSON.stringify(exported)),
74
+ provenance: resolved.provenance,
75
+ label: resolved.target.label,
76
+ ...display !== void 0 && display !== "" && display !== resolved.target.label ? { display } : {}
77
+ };
78
+ }
79
+ var WORKSPACE_JSON = "workspace.json";
80
+ function passwordSeedColumns(archive) {
81
+ const entries = readArchiveEntries(archive);
82
+ const raw = entries[WORKSPACE_JSON];
83
+ if (raw === void 0) return [];
84
+ const payload = JSON.parse(raw.toString("utf8")).payload;
85
+ const tables = Array.isArray(payload?.dbo) ? payload.dbo : [];
86
+ const out = [];
87
+ for (const table of tables) {
88
+ const { guid, name, schema } = table;
89
+ if (typeof guid !== "string" || typeof name !== "string" || !Array.isArray(schema)) continue;
90
+ const columns = schema.filter((c) => c.type === "password" && typeof c.name === "string").map((c) => c.name);
91
+ if (columns.length === 0) continue;
92
+ const rows = Object.entries(entries).filter(([file]) => file.startsWith(`content/${guid}-`)).flatMap(([, data]) => {
93
+ const rowsIn = JSON.parse(data.toString("utf8")).payload;
94
+ return Array.isArray(rowsIn) ? rowsIn : [];
95
+ });
96
+ for (const column of columns) {
97
+ if (rows.some((r) => typeof r[column] === "string" && r[column] !== "")) out.push(`${name}.${column}`);
98
+ }
99
+ }
100
+ return out;
101
+ }
102
+ function archiveSeedContent(archive) {
103
+ return Object.entries(readArchiveEntries(archive)).filter(([name]) => name.startsWith("content/") && name.endsWith(".json")).map(([name, data]) => ({ name, content: data.toString("utf8") }));
104
+ }
105
+ function gatedApiGroups(bundle) {
106
+ const rows = bundle?.payload?.app;
107
+ if (!Array.isArray(rows)) return [];
108
+ const out = [];
109
+ for (const row of rows) {
110
+ if (row === null || typeof row !== "object") continue;
111
+ const group = row;
112
+ const doc = group.documentation;
113
+ const gated = group.swagger === true && doc?.require_token === true && typeof doc.token === "string" && doc.token !== "";
114
+ if (gated && typeof group.name === "string") out.push(group.name);
115
+ }
116
+ return out;
117
+ }
118
+ function asWorkspaceArchive(archive, label) {
119
+ const entries = readArchiveEntries(archive);
120
+ const raw = entries[WORKSPACE_JSON];
121
+ if (raw === void 0) {
122
+ throw new Error(`Release "${label}" has no ${WORKSPACE_JSON}, so it cannot be deployed.`);
123
+ }
124
+ const envelope = JSON.parse(raw.toString("utf8"));
125
+ if (envelope.type === "workspace") return archive;
126
+ const { sig: _stored, ...unsigned } = envelope;
127
+ const retyped = { ...unsigned, type: "workspace" };
128
+ const files = [
129
+ { name: WORKSPACE_JSON, data: Buffer.from(JSON.stringify({ ...retyped, sig: calcSignatureJson(retyped) }), "utf8") }
130
+ ];
131
+ for (const [name, data] of Object.entries(entries)) {
132
+ if (name !== WORKSPACE_JSON) files.push({ name, data });
133
+ }
134
+ return tarGz(files);
135
+ }
136
+
137
+ export {
138
+ DEPLOY_SOURCE_KINDS,
139
+ looksLikeSource,
140
+ resolveProjectEntry,
141
+ fetchSourceArchive,
142
+ passwordSeedColumns,
143
+ archiveSeedContent,
144
+ gatedApiGroups,
145
+ asWorkspaceArchive
146
+ };
147
+ //# sourceMappingURL=chunk-AOSYVMUS.js.map
@@ -0,0 +1,182 @@
1
+ import {
2
+ LOOPBACK_HOSTS
3
+ } from "./chunk-AM4FKL4J.js";
4
+ import {
5
+ TransportError,
6
+ describeTransportFailure,
7
+ fetchOrExplain
8
+ } from "./chunk-YLDALTWZ.js";
9
+ import {
10
+ readEnvVar
11
+ } from "./chunk-X2NL4KUO.js";
12
+
13
+ // src/deploy/local-engine-releases.ts
14
+ var DEFAULT_ENGINE_RELEASES_URL = "https://xo2z-4vn5-mdxv.dev.xano.io/api:engine-mirror";
15
+ var ENGINE_RELEASES_URL_ENV = "XANOSDK_ENGINE_RELEASES_URL";
16
+ function usesCustomReleaseManager(env = process.env) {
17
+ const raw = readEnvVar(ENGINE_RELEASES_URL_ENV, env);
18
+ if (raw === void 0) return false;
19
+ return raw.replace(/\/+$/, "") !== DEFAULT_ENGINE_RELEASES_URL;
20
+ }
21
+ var RELEASES_TIMEOUT_MS = 3e4;
22
+ var MAX_LATEST_PAGES = 4;
23
+ var VERSION_PATTERN = /^v?\d+\.\d+\.\d+$/;
24
+ var SHA256_PATTERN = /^[0-9a-f]{64}$/;
25
+ function normalizeEngineVersion(version) {
26
+ const trimmed = version.trim();
27
+ if (!VERSION_PATTERN.test(trimmed)) {
28
+ throw new Error(
29
+ `"${version}" is not an engine version \u2014 they are written vMAJOR.MINOR.PATCH, like v0.1.5.
30
+ Pass a version in that form, or \`latest\`.`
31
+ );
32
+ }
33
+ return trimmed.startsWith("v") ? trimmed : `v${trimmed}`;
34
+ }
35
+ function isLoopback(url) {
36
+ return LOOPBACK_HOSTS.includes(url.hostname.replace(/^\[|\]$/g, ""));
37
+ }
38
+ function isTrustedUrl(url) {
39
+ return url.protocol === "https:" || url.protocol === "http:" && isLoopback(url);
40
+ }
41
+ function parseUrl(value) {
42
+ try {
43
+ return new URL(value);
44
+ } catch {
45
+ return void 0;
46
+ }
47
+ }
48
+ function releasesBase(env) {
49
+ const set = readEnvVar(ENGINE_RELEASES_URL_ENV, env);
50
+ const raw = set ?? DEFAULT_ENGINE_RELEASES_URL;
51
+ const url = parseUrl(raw);
52
+ if (url === void 0 || !isTrustedUrl(url)) {
53
+ throw new Error(
54
+ `${ENGINE_RELEASES_URL_ENV} must be an https URL, and is not \u2014 so no engine release was looked up.
55
+ Set it to the release manager's https address, or unset it to use the default.`
56
+ );
57
+ }
58
+ const base = `${url.origin}${url.pathname}`.replace(/\/+$/, "");
59
+ return { base, display: base, fromEnv: set !== void 0 };
60
+ }
61
+ function unreachableRemedy(where) {
62
+ return where.fromEnv ? `Check the network, and ${ENGINE_RELEASES_URL_ENV} (set to ${where.display}), then re-run.` : "Check the network and re-run.";
63
+ }
64
+ function notListingRemedy(where) {
65
+ return where.fromEnv ? `${ENGINE_RELEASES_URL_ENV} is set to ${where.display} \u2014 check it addresses the release manager's API, or unset it for the default, then re-run.` : "Re-run in a moment; if it keeps failing, the release index is down.";
66
+ }
67
+ function pickAsset(body, platform) {
68
+ if (body === null || typeof body !== "object") return void 0;
69
+ const { version, assets } = body;
70
+ if (typeof version !== "string" || !VERSION_PATTERN.test(version) || !Array.isArray(assets)) return void 0;
71
+ for (const a of assets) {
72
+ if (a === null || typeof a !== "object") continue;
73
+ const { platform: p, filename, sha256, download_url } = a;
74
+ if (p !== platform) continue;
75
+ if (typeof filename !== "string" || filename === "") continue;
76
+ if (typeof sha256 !== "string" || !SHA256_PATTERN.test(sha256)) continue;
77
+ if (typeof download_url !== "string") continue;
78
+ const dl = parseUrl(download_url);
79
+ if (dl === void 0 || !isTrustedUrl(dl)) continue;
80
+ return { version: normalizeEngineVersion(version), filename, sha256, downloadUrl: download_url };
81
+ }
82
+ return void 0;
83
+ }
84
+ async function getJson(url, where, fetch) {
85
+ const { display } = where;
86
+ let res;
87
+ try {
88
+ res = await fetch(url, {
89
+ method: "GET",
90
+ // No Authorization, deliberately: the index is public.
91
+ headers: { accept: "application/json" },
92
+ signal: AbortSignal.timeout(RELEASES_TIMEOUT_MS)
93
+ });
94
+ } catch (err) {
95
+ const reason = err instanceof TransportError && err.timeout ? `it did not answer within ${Math.round(RELEASES_TIMEOUT_MS / 1e3)}s` : describeTransportFailure(err instanceof TransportError && err.cause !== void 0 ? err.cause : err);
96
+ throw new Error(
97
+ `The engine release manager at ${display} could not be reached: ${reason.replace(/\.$/, "")}. Nothing was changed.
98
+ ` + unreachableRemedy(where),
99
+ { cause: err }
100
+ );
101
+ }
102
+ if (!res.ok) return { status: res.status, body: void 0 };
103
+ try {
104
+ return { status: res.status, body: await res.json() };
105
+ } catch {
106
+ throw new Error(
107
+ `The engine release manager at ${display} answered with something that is not a release listing.
108
+ ` + notListingRemedy(where)
109
+ );
110
+ }
111
+ }
112
+ var EngineReleaseNotFoundError = class extends Error {
113
+ name = "EngineReleaseNotFoundError";
114
+ exitCode = 8;
115
+ };
116
+ function failed(status, display) {
117
+ const err = new Error(
118
+ `The engine release manager at ${display} failed (HTTP ${status}).
119
+ Re-run in a moment; if it keeps failing, the release index is down.`
120
+ );
121
+ if (status >= 500) Object.defineProperty(err, "exitCode", { value: 8, enumerable: true });
122
+ return err;
123
+ }
124
+ async function resolveEngineRelease(opts) {
125
+ const env = opts.env ?? process.env;
126
+ const { platform } = opts;
127
+ const wanted = opts.version === void 0 || opts.version === "latest" ? void 0 : normalizeEngineVersion(opts.version);
128
+ const where = releasesBase(env);
129
+ const { base, display } = where;
130
+ const fetch = opts.fetch ?? ((url, init) => fetchOrExplain(url, init, "resolve the engine release", RELEASES_TIMEOUT_MS, display));
131
+ if (wanted !== void 0) {
132
+ const { status, body } = await getJson(
133
+ `${base}/releases/${encodeURIComponent(wanted)}?product=engine`,
134
+ where,
135
+ fetch
136
+ );
137
+ if (status === 404) {
138
+ throw new EngineReleaseNotFoundError(
139
+ `There is no published engine release ${wanted}.
140
+ Check the version, or run \`xanosdk local-engine update\` to move to the latest one.`
141
+ );
142
+ }
143
+ if (body === void 0) throw failed(status, display);
144
+ const asset = pickAsset(body, platform);
145
+ if (asset === void 0) {
146
+ throw new Error(
147
+ `Engine release ${wanted} has no archive for ${platform}, so nothing was downloaded.
148
+ Run \`xanosdk local-engine update\` to move to a release built for ${platform}.`
149
+ );
150
+ }
151
+ return asset;
152
+ }
153
+ for (let pageNo = 1; pageNo <= MAX_LATEST_PAGES; pageNo++) {
154
+ const { status, body } = await getJson(`${base}/releases?product=engine&page=${pageNo}`, where, fetch);
155
+ if (body === void 0) throw failed(status, display);
156
+ const { items, nextPage } = body ?? {};
157
+ if (!Array.isArray(items)) {
158
+ throw new Error(
159
+ `The engine release manager at ${display} answered with something that is not a release listing.
160
+ ` + notListingRemedy(where)
161
+ );
162
+ }
163
+ for (const item of items) {
164
+ const asset = pickAsset(item, platform);
165
+ if (asset !== void 0) return asset;
166
+ }
167
+ if (typeof nextPage !== "number") break;
168
+ }
169
+ throw new Error(
170
+ `No published engine release has an archive for ${platform}, so nothing was downloaded.
171
+ Deploy from a machine the engine is published for, or wait for a release built for ${platform}.`
172
+ );
173
+ }
174
+
175
+ export {
176
+ ENGINE_RELEASES_URL_ENV,
177
+ usesCustomReleaseManager,
178
+ normalizeEngineVersion,
179
+ EngineReleaseNotFoundError,
180
+ resolveEngineRelease
181
+ };
182
+ //# sourceMappingURL=chunk-APWXY5SL.js.map