@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,800 @@
1
+ import {
2
+ confirmDanglingRemoval,
3
+ revocableRecord,
4
+ revokeFields,
5
+ revokeProfileSession,
6
+ signInAgain
7
+ } from "./chunk-ELP2HMXC.js";
8
+ import {
9
+ promptLine,
10
+ readStdin
11
+ } from "./chunk-65HWOMGV.js";
12
+ import {
13
+ ensureGitignoredOrWarn
14
+ } from "./chunk-YHEFQUQB.js";
15
+ import "./chunk-DAD3ONIS.js";
16
+ import {
17
+ projectDirFrom
18
+ } from "./chunk-6NNTNXN7.js";
19
+ import {
20
+ ProfileNotFoundError,
21
+ credentialRejected,
22
+ environmentCredentialVars,
23
+ notSignedIn,
24
+ warnIfReadableByOthers
25
+ } from "./chunk-ET4Y4XCB.js";
26
+ import {
27
+ readEphemeralState
28
+ } from "./chunk-5QU2P5CA.js";
29
+ import "./chunk-ZYJP6BOO.js";
30
+ import "./chunk-QO6BVGS5.js";
31
+ import "./chunk-JZGVVJSI.js";
32
+ import {
33
+ pipedYes,
34
+ retryCommand
35
+ } from "./chunk-T5KELPAR.js";
36
+ import "./chunk-622HUCZT.js";
37
+ import "./chunk-NAQDMEHV.js";
38
+ import "./chunk-5A2PLKZB.js";
39
+ import "./chunk-AHJWCYQO.js";
40
+ import "./chunk-DX4QR4B2.js";
41
+ import "./chunk-6QXLMMT3.js";
42
+ import "./chunk-ZFDZKNGG.js";
43
+ import "./chunk-FWD7AL6N.js";
44
+ import "./chunk-2GNFDZA2.js";
45
+ import "./chunk-JTUKLCXS.js";
46
+ import "./chunk-4KHEMC32.js";
47
+ import "./chunk-ROY4YAEQ.js";
48
+ import "./chunk-TLQE7ZN3.js";
49
+ import "./chunk-WRBKLYSJ.js";
50
+ import "./chunk-3LDULPRE.js";
51
+ import {
52
+ addProfileHint,
53
+ assertCredentialFileWritable,
54
+ assertHttpsOrigin,
55
+ assertInstanceOrigin,
56
+ buildTokenCredential,
57
+ credentialFileFlag,
58
+ describeProfile,
59
+ dropProfile,
60
+ emptyCredentialFile,
61
+ globalAuthFilePath,
62
+ isSafeIdText,
63
+ loginCommand,
64
+ profileNames,
65
+ projectAuthFilePath,
66
+ readCredentialFile,
67
+ readProfile,
68
+ removeEmptyProjectCacheDir,
69
+ resolveAuthFilePath,
70
+ withCredentialLock,
71
+ writeCredentialFile,
72
+ writeOrRemoveCredentialFile
73
+ } from "./chunk-XW6KISBB.js";
74
+ import "./chunk-AWQ7BQTQ.js";
75
+ import "./chunk-EUUUMY7J.js";
76
+ import {
77
+ fetchOrExplain,
78
+ httpFailure,
79
+ redirectedUnresolvedHost
80
+ } from "./chunk-YLDALTWZ.js";
81
+ import {
82
+ POINTER_FILE,
83
+ findPointerFile,
84
+ findProjectPointer,
85
+ projectRootFor,
86
+ resolveProjectProfile,
87
+ writePointerFile
88
+ } from "./chunk-5FBYXK5P.js";
89
+ import "./chunk-LLNZGEFK.js";
90
+ import {
91
+ DEFAULT_PROFILE,
92
+ assertValidProfileName,
93
+ describeProfileSelection,
94
+ resolveActiveProfile
95
+ } from "./chunk-QXTKSOFI.js";
96
+ import {
97
+ readEnvVar
98
+ } from "./chunk-X2NL4KUO.js";
99
+ import "./chunk-UCQ2VUTG.js";
100
+ import "./chunk-DGWHAVRG.js";
101
+ import {
102
+ UsageError,
103
+ detail,
104
+ formatFields,
105
+ info,
106
+ isMachineOutput,
107
+ missingArgument,
108
+ printHuman,
109
+ quotedNames,
110
+ safeText,
111
+ stdoutStyle,
112
+ step,
113
+ success,
114
+ unknownSubcommand,
115
+ warn,
116
+ writeJson
117
+ } from "./chunk-PTHVMXZI.js";
118
+ import "./chunk-GSGDWJB5.js";
119
+ import {
120
+ suggest,
121
+ suggestAll
122
+ } from "./chunk-UTI5G6OJ.js";
123
+ import "./chunk-2EZ3ZJZZ.js";
124
+ import "./chunk-6MR5TI5V.js";
125
+ import {
126
+ shellQuote
127
+ } from "./chunk-5ZSO4T2G.js";
128
+ import "./chunk-XNCP4KYO.js";
129
+ import "./chunk-TFFGOFVZ.js";
130
+ import "./chunk-NZOWWHU5.js";
131
+ import "./chunk-4BW2SG2N.js";
132
+ import "./chunk-CIMQZRRE.js";
133
+ import "./chunk-OHX6MIUZ.js";
134
+ import "./chunk-36JUQZVQ.js";
135
+ import "./chunk-PZ5AY32C.js";
136
+
137
+ // src/emit/profile-command.ts
138
+ import { resolve } from "path";
139
+ async function runProfileCommand(args) {
140
+ switch (args.subcommand) {
141
+ case "list":
142
+ return listProfiles(args);
143
+ case "show":
144
+ return showProfile(args);
145
+ case "use":
146
+ return useProfile(args);
147
+ case "set-default":
148
+ return setDefaultProfile(args);
149
+ case "add":
150
+ return addProfile(args);
151
+ case "delete":
152
+ return deleteProfile(args);
153
+ default:
154
+ throw unknownSubcommand("profile", args.subcommand);
155
+ }
156
+ }
157
+ function profileFilePath(args) {
158
+ return resolveAuthFilePath(args, "read");
159
+ }
160
+ function openFile(args) {
161
+ const path = profileFilePath(args);
162
+ const file = readCredentialFile(path);
163
+ if (file !== null) warnIfReadableByOthers(path);
164
+ return { path, file: file ?? emptyCredentialFile() };
165
+ }
166
+ function activeSelection(args, file, path) {
167
+ return resolveActiveProfile({
168
+ flag: args.profile,
169
+ fileDefault: file.default,
170
+ defaultIn: path === globalAuthFilePath() ? void 0 : path,
171
+ readPointer: () => resolveProjectProfile(process.cwd())
172
+ });
173
+ }
174
+ function isDefaultProfile(file, name) {
175
+ return (file.default ?? DEFAULT_PROFILE) === name;
176
+ }
177
+ function environmentsFor(profile) {
178
+ const state = readEphemeralState(projectDirFrom(process.cwd()) ?? process.cwd());
179
+ return Object.entries(state.environments).filter(([key]) => key.startsWith(`${profile}/`)).map(([key, record]) => {
180
+ const [, host = "", workspace = ""] = key.split("/");
181
+ return { name: record.name, host, workspace };
182
+ });
183
+ }
184
+ function profileReaching(profiles, host, workspace) {
185
+ for (const [profile, raw] of Object.entries(profiles)) {
186
+ const record = raw;
187
+ const instance = record?.instance ?? record?.instance_base_url;
188
+ if (typeof instance !== "string" || String(record?.workspace_id) !== workspace) continue;
189
+ try {
190
+ if (new URL(instance).host === host) return profile;
191
+ } catch {
192
+ }
193
+ }
194
+ return void 0;
195
+ }
196
+ function requiredName(args, verb) {
197
+ const name = args.positionals[0];
198
+ if (name === void 0) {
199
+ throw missingArgument("name", { command: "profile", subcommand: verb });
200
+ }
201
+ validName(name, verb);
202
+ return name;
203
+ }
204
+ function validName(name, verb) {
205
+ try {
206
+ assertValidProfileName(name, `xanosdk profile ${verb}`);
207
+ } catch (err) {
208
+ throw new UsageError(err instanceof Error ? err.message : String(err), {
209
+ hintFor: { command: "profile", subcommand: verb }
210
+ });
211
+ }
212
+ }
213
+ function defaultOf(path) {
214
+ return path === globalAuthFilePath() ? "this machine's default" : `the default profile in ${path}`;
215
+ }
216
+ function assertAnyProfiles(file, path) {
217
+ if (profileNames(file).length > 0) return;
218
+ throw new ProfileNotFoundError(`No credential profiles are stored in ${path}. ${signInLine(path)}`);
219
+ }
220
+ function existingName(file, name, path, verb) {
221
+ if (hasProfile(file, name)) return;
222
+ const have = profileNames(file);
223
+ const near = suggest(name, have);
224
+ const err = new ProfileNotFoundError(
225
+ `No credential profile "${name}" in ${path}.` + (have.length === 0 ? "" : ` Stored profiles: ${quotedNames(have)}.`) + (near === void 0 ? "" : ` Did you mean "${safeText(near)}"? \`xanosdk profile ${verb} ${shellQuote(near)}${credentialFileFlag(path)}\`.`) + ` Add it with ${addProfileHint(name, { path })}.`
226
+ );
227
+ if (near !== void 0) Object.defineProperty(err, "suggestion", { value: near, enumerable: true });
228
+ throw err;
229
+ }
230
+ function hasProfile(file, name) {
231
+ return Object.prototype.hasOwnProperty.call(file.profiles, name);
232
+ }
233
+ function storedNamesLine(file, path) {
234
+ const have = profileNames(file);
235
+ return have.length === 0 ? signInLine(path) : `Stored profiles: ${quotedNames(have)}.`;
236
+ }
237
+ function signInLine(path) {
238
+ const flag = credentialFileFlag(path);
239
+ return `Run \`xanosdk login${flag}\` to sign in, or \`xanosdk profile add <name>${flag}\` to store a meta API token.`;
240
+ }
241
+ function usableName(file, name, path, verb) {
242
+ const described = describeProfile(file, name, path);
243
+ let problem = "error" in described ? described.error : void 0;
244
+ if ("record" in described) {
245
+ const r = described.record;
246
+ try {
247
+ assertHttpsOrigin(r.type === "token" ? r.instance_base_url : r.instance, "Its instance");
248
+ } catch (err) {
249
+ problem = err.message;
250
+ }
251
+ }
252
+ if (problem === void 0) return;
253
+ const raw = file.profiles[name];
254
+ const fix = raw?.type === "token" ? `\`xanosdk profile add ${name}${credentialFileFlag(path)} --instance <url> --workspace-id <id> --force\`` : `\`${loginCommand(name, { path }, ["--force"])}\``;
255
+ throw new UsageError(
256
+ `Profile "${name}" cannot be used, so it was not made ${defaultOf(path)}: ${problem.replace(/\s+$/, "")}
257
+ Repair it with ${fix}, or pick another from \`xanosdk profile list${credentialFileFlag(path)}\`.`,
258
+ { hintFor: { command: "profile", subcommand: verb } }
259
+ );
260
+ }
261
+ function rowsFor(file, path, activeName) {
262
+ return profileNames(file).map((name) => {
263
+ const base = { name, isDefault: isDefaultProfile(file, name), isActive: activeName === name };
264
+ const described = describeProfile(file, name, path);
265
+ if ("error" in described) return { ...base, invalid: described.error };
266
+ const record = described.record;
267
+ return {
268
+ ...base,
269
+ instance: record.type === "token" ? record.instance_base_url : record.instance,
270
+ workspaceId: record.workspace_id,
271
+ credentialType: record.type
272
+ };
273
+ });
274
+ }
275
+ async function listProfiles(args) {
276
+ const { path, file } = openFile(args);
277
+ const envCredential = environmentCredentialVars();
278
+ const env = envCredential.complete ? envCredential.vars : void 0;
279
+ const active = activeSelection(args, file, path);
280
+ const rows = rowsFor(file, path, env === void 0 ? active.name : void 0);
281
+ if (isMachineOutput(args) && env !== void 0) {
282
+ writeJson({
283
+ path,
284
+ default: file.default ?? null,
285
+ active: null,
286
+ source: "environment",
287
+ environmentCredential: true,
288
+ environmentVariables: env,
289
+ profiles: rows
290
+ });
291
+ return;
292
+ }
293
+ if (isMachineOutput(args)) {
294
+ const stored = hasProfile(file, active.name);
295
+ noteMissingSelection(file, active, path);
296
+ writeJson({
297
+ path,
298
+ default: file.default ?? null,
299
+ active: stored ? active.name : null,
300
+ source: active.source,
301
+ ...stored || active.source === "implicit" ? {} : { missing: active.name },
302
+ profiles: rows
303
+ });
304
+ return;
305
+ }
306
+ const envLine = () => {
307
+ if (env !== void 0) {
308
+ info(`The environment credential (${env.join(", ")}) is in use; stored profiles are ignored.`);
309
+ }
310
+ };
311
+ if (rows.length === 0) {
312
+ info(`No credential profiles are stored in ${path}.`);
313
+ if (env !== void 0) return envLine();
314
+ detail(signInLine(path));
315
+ noteMissingSelection(file, active, path);
316
+ return;
317
+ }
318
+ const s = stdoutStyle();
319
+ const meta = (row) => `workspace ${row.workspaceId} \xB7 ${row.credentialType}`;
320
+ const valid = rows.filter((row) => row.invalid === void 0);
321
+ const instanceWidth = Math.max(0, ...valid.map((row) => String(row.instance).length));
322
+ const metaWidth = Math.max(0, ...valid.map((row) => meta(row).length));
323
+ printHuman(
324
+ "\n" + formatFields(
325
+ rows.map((row) => {
326
+ const marks = [row.isActive ? s.green("active") : void 0, row.isDefault ? s.dim("default") : void 0].filter(Boolean).join(s.dim(", "));
327
+ const body = row.invalid !== void 0 ? s.yellow(`invalid \u2014 ${row.invalid}`) : marks === "" ? `${String(row.instance).padEnd(instanceWidth)} ${s.dim(meta(row))}` : `${String(row.instance).padEnd(instanceWidth)} ${s.dim(meta(row).padEnd(metaWidth))}`;
328
+ return [row.name, marks === "" ? body : `${body} ${s.dim("(")}${marks}${s.dim(")")}`];
329
+ })
330
+ )
331
+ );
332
+ detail(`From ${path}`);
333
+ if (env !== void 0) return envLine();
334
+ noteMissingSelection(file, active, path);
335
+ }
336
+ function noteMissingSelection(file, active, path) {
337
+ if (active.source === "implicit" || hasProfile(file, active.name)) return;
338
+ warn(
339
+ `${describeProfileSelection(active)} is selected here but not stored in ${path}, so no profile is active \u2014 commands here fail until it is added or another is selected.`,
340
+ "profile.missing"
341
+ );
342
+ }
343
+ async function showProfile(args) {
344
+ const { path, file } = openFile(args);
345
+ if (args.positionals[0] !== void 0) assertAnyProfiles(file, path);
346
+ if (args.positionals[0] === void 0 && environmentCredentialVars().complete) return showEnvironmentCredential(args);
347
+ const active = activeSelection(args, file, path);
348
+ const name = args.positionals[0] ?? active.name;
349
+ validName(name, "show");
350
+ if (args.positionals[0] === void 0 && !hasProfile(file, name)) throw notSignedIn(path, file, active);
351
+ existingName(file, name, path, "show");
352
+ const record = readProfile(file, name, path);
353
+ const view = {
354
+ name,
355
+ path,
356
+ // Deliberately no token field of any kind, in either mode. The command that
357
+ // displays a credential is the last place one should reach a CI log.
358
+ credentialType: record.type,
359
+ instance: record.type === "token" ? record.instance_base_url : record.instance,
360
+ workspaceId: record.workspace_id,
361
+ isDefault: isDefaultProfile(file, name),
362
+ isActive: active.name === name,
363
+ ...record.type === "oauth" ? { expiresAt: record.expires_at, scope: record.scope ?? null } : {}
364
+ };
365
+ if (isMachineOutput(args)) {
366
+ writeJson(view);
367
+ return;
368
+ }
369
+ const s = stdoutStyle();
370
+ printHuman(
371
+ "\n" + formatFields([
372
+ ["Profile", s.bold(name) + (view.isActive ? s.dim(" (active)") : "")],
373
+ ["Instance", s.bold(s.cyan(view.instance))],
374
+ ["Workspace", String(view.workspaceId)],
375
+ ["Credential", record.type === "token" ? "meta API token" : "OAuth"],
376
+ ["Default", view.isDefault ? "yes" : "no"]
377
+ ])
378
+ );
379
+ detail(`From ${path}`);
380
+ }
381
+ function showEnvironmentCredential(args) {
382
+ const { vars } = environmentCredentialVars();
383
+ const instance = readEnvVar("XANO_INSTANCE_URL") ?? null;
384
+ const workspace = readEnvVar("XANO_WORKSPACE_ID");
385
+ const view = {
386
+ name: null,
387
+ source: "environment",
388
+ environmentVariables: vars,
389
+ credentialType: vars.includes("XANO_META_TOKEN") ? "token" : "oauth",
390
+ instance,
391
+ workspaceId: workspace === void 0 || !isSafeIdText(workspace) ? workspace ?? null : Number(workspace),
392
+ isActive: true
393
+ };
394
+ if (isMachineOutput(args)) {
395
+ writeJson(view);
396
+ return;
397
+ }
398
+ const s = stdoutStyle();
399
+ printHuman(
400
+ "\n" + formatFields([
401
+ ["Credential", `${view.credentialType === "token" ? "meta API token" : "OAuth"} ${s.dim("(environment, active)")}`],
402
+ ...instance === null ? [] : [["Instance", s.bold(s.cyan(instance))]],
403
+ ...workspace === void 0 ? [] : [["Workspace", workspace]]
404
+ ])
405
+ );
406
+ detail(`From ${vars.join(", ")} \u2014 stored profiles are ignored while they are set.`);
407
+ }
408
+ async function useProfile(args) {
409
+ const name = requiredName(args, "use");
410
+ const { path, file } = openFile(args);
411
+ existingName(file, name, path, "use");
412
+ const root = projectRootFor(process.cwd());
413
+ if (root === void 0) {
414
+ throw new UsageError(
415
+ `\`profile use\` pins a project, and ${process.cwd()} is not inside one \u2014 no package.json, .git or ${POINTER_FILE} above it short of the home directory. Run it from the project's directory, or make "${name}" this machine's default with \`xanosdk profile set-default ${name}${credentialFileFlag(path)}\`.`
416
+ );
417
+ }
418
+ const written = writePointerFile(root, name);
419
+ success(`This project now uses profile "${name}".`);
420
+ detail(`Wrote ${written} \u2014 commit it so the rest of the project uses it too.`);
421
+ detail(
422
+ `It holds a profile name and no credentials. To change ${defaultOf(path)} instead, run \`xanosdk profile set-default ${name}${credentialFileFlag(path)}\`.`
423
+ );
424
+ if (isMachineOutput(args)) writeJson({ verb: "use", profile: name, pointer: written });
425
+ }
426
+ async function setDefaultProfile(args) {
427
+ const name = requiredName(args, "set-default");
428
+ const path = profileFilePath(args);
429
+ existingName(readCredentialFile(path) ?? emptyCredentialFile(), name, path, "set-default");
430
+ let changed = false;
431
+ await withCredentialLock(path, (file) => {
432
+ existingName(file, name, path, "set-default");
433
+ usableName(file, name, path, "set-default");
434
+ changed = file.default !== name;
435
+ if (!changed) return;
436
+ file.default = name;
437
+ writeCredentialFile(path, file);
438
+ });
439
+ const pointer = pinOtherThan(name);
440
+ if (changed) {
441
+ success(`Profile "${name}" is now ${defaultOf(path)}.`);
442
+ if (path === globalAuthFilePath()) detail(`Set in ${path}.`);
443
+ } else {
444
+ info(`Profile "${name}" is already ${defaultOf(path)} \u2014 nothing changed.`);
445
+ }
446
+ if (pointer !== void 0) warnPinWins(pointer, name, path);
447
+ if (isMachineOutput(args)) {
448
+ writeJson({ verb: "set-default", profile: name, path, changed, shadowedByPointer: pointer ?? null });
449
+ }
450
+ }
451
+ function warnPinWins(pointer, name, path) {
452
+ warn(
453
+ `This project pins its own profile in ${pointer}, which still wins here. Run \`xanosdk profile use ${name}${credentialFileFlag(path)}\` to change the project too.`,
454
+ "profile.project-pin-wins"
455
+ );
456
+ }
457
+ function pinOtherThan(name) {
458
+ try {
459
+ const pin = findProjectPointer(process.cwd());
460
+ return pin !== void 0 && pin.profile !== name ? pin.path : void 0;
461
+ } catch {
462
+ return findPointerFile(process.cwd());
463
+ }
464
+ }
465
+ async function addProfile(args) {
466
+ const name = requiredName(args, "add");
467
+ const path = profileFilePath(args);
468
+ const credential = (token) => buildTokenCredential(
469
+ {
470
+ instance: args.instance,
471
+ // The raw string is passed through on a bad parse so the rejection quotes
472
+ // what was typed rather than `NaN` — the env triple's reason, unchanged.
473
+ workspaceId: args.workspaceId !== void 0 && isSafeIdText(args.workspaceId) ? Number(args.workspaceId.trim()) : args.workspaceId,
474
+ token
475
+ },
476
+ {
477
+ at: `for \`xanosdk profile add ${name}\``,
478
+ labels: { instance: "--instance", workspace: "--workspace-id", token: "the token" },
479
+ fix: `Pipe the token alone, on one line: \`printf %s "$TOKEN" | ${retryCommand(args, { command: `profile add ${name}` }).command}\`.`
480
+ }
481
+ );
482
+ try {
483
+ if (typeof args.instance === "string") {
484
+ assertInstanceOrigin(args.instance.trim(), `\`--instance\` for \`xanosdk profile add ${name}\``);
485
+ }
486
+ credential("x");
487
+ } catch (err) {
488
+ throw new UsageError(err instanceof Error ? err.message : String(err), {
489
+ hintFor: { command: "profile", subcommand: "add" }
490
+ });
491
+ }
492
+ assertCredentialFileWritable(path);
493
+ const existingFile = readCredentialFile(path) ?? emptyCredentialFile();
494
+ const displaced = Object.prototype.hasOwnProperty.call(existingFile.profiles, name);
495
+ if (displaced && !args.force) {
496
+ throw new UsageError(
497
+ `Profile "${name}" already exists in ${path}. Pass \`--force\` to replace it, or choose another name. Run \`xanosdk profile show ${name}${credentialFileFlag(path)}\` to see what it addresses.`
498
+ );
499
+ }
500
+ const record = credential(await readToken(name, args));
501
+ await verifyToken(record, name);
502
+ await verifyWorkspace(record, name);
503
+ let isFirst = false;
504
+ let isDefault = false;
505
+ await withCredentialLock(path, async (file) => {
506
+ const replaced = revocableRecord(file, name, path);
507
+ if (replaced !== void 0) {
508
+ step(`Revoking the session that profile "${name}" held\u2026`);
509
+ await revokeProfileSession(args, replaced, name, "replace");
510
+ }
511
+ isFirst = profileNames(file).length === 0;
512
+ file.profiles[name] = record;
513
+ if (isFirst) file.default = name;
514
+ isDefault = isDefaultProfile(file, name);
515
+ writeCredentialFile(path, file);
516
+ });
517
+ const gitignored = ensureGitignoredOrWarn(path);
518
+ if (args.local) warnIfLocalShadowsPin(path, name);
519
+ success(`Stored profile "${name}" \u2014 ${record.instance_base_url}, workspace ${record.workspace_id}.`);
520
+ detail(`Saved to ${path}`);
521
+ const fileFlag = credentialFileFlag(path);
522
+ if (isFirst) detail(`It is ${defaultOf(path)}, since it is the only profile stored.`);
523
+ else if (isDefault) detail(`It is still ${defaultOf(path)}.`);
524
+ else {
525
+ const pin = projectRootFor(process.cwd()) === void 0 ? "" : `, or pin this project with \`xanosdk profile use ${name}${fileFlag}\``;
526
+ detail(`Select it with \`--profile ${name}${fileFlag}\`${pin}.`);
527
+ }
528
+ if (isMachineOutput(args)) {
529
+ writeJson({
530
+ verb: "add",
531
+ profile: name,
532
+ path,
533
+ instance: record.instance_base_url,
534
+ workspaceId: record.workspace_id,
535
+ isDefault,
536
+ replaced: displaced,
537
+ gitignored
538
+ });
539
+ }
540
+ }
541
+ function warnIfLocalShadowsPin(localPath, added) {
542
+ const pin = findProjectPointer(process.cwd());
543
+ if (pin === void 0 || pin.profile === added) return;
544
+ const local = readCredentialFile(localPath);
545
+ if (local === null || profileNames(local).includes(pin.profile)) return;
546
+ const sharedPath = globalAuthFilePath();
547
+ let shared = null;
548
+ try {
549
+ shared = readCredentialFile(sharedPath);
550
+ } catch {
551
+ return;
552
+ }
553
+ if (shared === null || !profileNames(shared).includes(pin.profile)) return;
554
+ warn(
555
+ `This project pins profile "${pin.profile}" (${pin.path}), which is in ${sharedPath} but not in ${localPath}. Commands here now read ${localPath} instead, so "${pin.profile}" no longer resolves.`,
556
+ "profile.local-shadows-pin",
557
+ [
558
+ `Undo with \`xanosdk profile delete ${added} --local\`, or re-pin to the new profile with \`xanosdk profile use ${added} --local\`.`
559
+ ]
560
+ );
561
+ }
562
+ async function readToken(name, args) {
563
+ const stdin = await readStdin();
564
+ if (stdin !== void 0) {
565
+ const piped = stdin.trim();
566
+ if (piped === "") {
567
+ throw new UsageError(
568
+ `\`xanosdk profile add ${name}\` reads the meta API token from stdin when it is not a terminal, and stdin was empty. Pipe the token in (\`printf %s "$TOKEN" | ${retryCommand(args, { command: `profile add ${name}` }).command}\`), or run it in a terminal to be asked for it.`,
569
+ { hintFor: { command: "profile", subcommand: "add" } }
570
+ );
571
+ }
572
+ return piped;
573
+ }
574
+ return promptLine(`Meta API token for profile "${name}":`, {
575
+ mask: true,
576
+ noTtyHint: "A token must not be passed as a flag \u2014 it would land in the process list and the shell history. Pipe it on stdin instead, or for automation set XANO_INSTANCE_URL / XANO_WORKSPACE_ID / XANO_META_TOKEN."
577
+ });
578
+ }
579
+ var VERIFY_TIMEOUT_MS = 3e4;
580
+ async function verifyToken(record, name) {
581
+ const url = new URL("/api:meta/auth/me", record.instance_base_url).href;
582
+ const res = await fetchOrExplain(
583
+ url,
584
+ {
585
+ headers: { Authorization: `Bearer ${record.meta_api_token}` },
586
+ signal: AbortSignal.timeout(VERIFY_TIMEOUT_MS)
587
+ },
588
+ `profile add ${name}`,
589
+ VERIFY_TIMEOUT_MS
590
+ ).catch((err) => {
591
+ if (errorCodeIn(err) !== "ENOTFOUND" || redirectedUnresolvedHost(err, url) !== void 0) {
592
+ return unansweredProfileRead(err, name).then((e) => Promise.reject(e));
593
+ }
594
+ throw new UsageError(
595
+ `profile add ${name}: the host of ${record.instance_base_url} does not resolve (ENOTFOUND), so nothing was stored. Check the \`--instance\` URL \u2014 it is your instance's origin, e.g. https://x8ki-letl-twmt.n7.xano.io.`,
596
+ { hintFor: { command: "profile", subcommand: "add" } }
597
+ );
598
+ });
599
+ const text = await res.text();
600
+ if (res.status === 401 || res.status === 403) {
601
+ throw credentialRejected(
602
+ new Error(
603
+ `${record.instance_base_url} rejected the token for profile "${name}" (HTTP ${res.status}), so nothing was stored. Check it is a meta API token issued by that instance and that it has not expired or been revoked.`
604
+ ),
605
+ {
606
+ profile: name,
607
+ credentialType: "token",
608
+ instance: record.instance_base_url,
609
+ workspaceId: record.workspace_id,
610
+ signIn: null
611
+ }
612
+ );
613
+ }
614
+ if (!res.ok) throw await unansweredVerify(res, text, name);
615
+ }
616
+ async function unansweredVerify(res, text, name) {
617
+ const failed = Object.assign(new Error(httpFailure(`profile add ${name}`, res, text)), { status: res.status });
618
+ return await unansweredProfileRead(failed, name);
619
+ }
620
+ async function unansweredProfileRead(err, name) {
621
+ const { isUnansweredLookup, LookupFailedError, unansweredCause } = await import("./source-resolve-S2XA3XZF.js");
622
+ if (!isUnansweredLookup(err)) {
623
+ if (err instanceof Error && !(err instanceof UsageError) && !/Nothing was stored\.$/.test(err.message)) {
624
+ err.message = `${err.message}
625
+ Nothing was stored.`;
626
+ }
627
+ return err;
628
+ }
629
+ const message = (err instanceof Error ? err.message : String(err)).trim();
630
+ const head = (message.split("\n")[0] ?? message).trim().replace(/[.:]$/, "");
631
+ const failed = new LookupFailedError(
632
+ `Could not verify the token for profile "${name}" \u2014 ${head}. ${unansweredCause(err)} \u2014 nothing was stored`,
633
+ "unreachable",
634
+ "workspace"
635
+ );
636
+ failed.cause = err;
637
+ return failed;
638
+ }
639
+ function errorCodeIn(err) {
640
+ for (let e = err, depth = 0; e !== void 0 && e !== null && depth < 5; depth++) {
641
+ const code = e.code;
642
+ if (typeof code === "string") return code;
643
+ e = e.cause;
644
+ }
645
+ return void 0;
646
+ }
647
+ async function verifyWorkspace(record, name) {
648
+ const url = new URL("/api:meta/workspace", record.instance_base_url).href;
649
+ const res = await fetchOrExplain(
650
+ url,
651
+ {
652
+ headers: { Authorization: `Bearer ${record.meta_api_token}` },
653
+ signal: AbortSignal.timeout(VERIFY_TIMEOUT_MS)
654
+ },
655
+ `profile add ${name}`,
656
+ VERIFY_TIMEOUT_MS
657
+ ).catch(async (err) => Promise.reject(await unansweredProfileRead(err, name)));
658
+ const text = await res.text();
659
+ if (!res.ok) throw await unansweredVerify(res, text, name);
660
+ let parsed;
661
+ try {
662
+ parsed = JSON.parse(text);
663
+ } catch {
664
+ throw new Error(`profile add ${name}: could not parse the workspace list as JSON.
665
+ Nothing was stored.`);
666
+ }
667
+ const all = Array.isArray(parsed) ? parsed : [];
668
+ if (all.some((w) => w.id === record.workspace_id)) return;
669
+ const visible = all.filter((w) => typeof w.id === "number").map((w) => typeof w.name === "string" ? `${String(w.id)} (${w.name})` : String(w.id));
670
+ throw new UsageError(
671
+ `The token for profile "${name}" cannot see workspace ${record.workspace_id} on ${record.instance_base_url}, so nothing was stored. ` + (visible.length === 0 ? "It can see no workspace at all." : `The workspace ids it can see: ${visible.join(", ")}.`) + ` Re-run with one of them as \`--workspace-id\`.`,
672
+ { hintFor: { command: "profile", subcommand: "add" } }
673
+ );
674
+ }
675
+ async function deleteProfile(args) {
676
+ const name = requiredName(args, "delete");
677
+ const path = profileFilePath(args);
678
+ const file = readCredentialFile(path) ?? emptyCredentialFile();
679
+ if (!hasProfile(file, name)) {
680
+ const nearAll = suggestAll(name, profileNames(file));
681
+ if (nearAll.length > 0) {
682
+ const pinned = path === resolve(projectAuthFilePath()) ? findProjectPointer(process.cwd())?.profile : void 0;
683
+ const confirms = (n) => file.default === n && profileNames(file).length > 1 || pinned === n;
684
+ const again = `${args.json === true ? " --json" : ""}${credentialFileFlag(path)}`;
685
+ const meant = nearAll.map(
686
+ (n) => `Did you mean "${safeText(n)}"? \`xanosdk profile delete ${shellQuote(n)}${again}\` deletes it${confirms(n) ? ", after asking to confirm" : ""}.`
687
+ );
688
+ const err = new ProfileNotFoundError(
689
+ [`No credential profile "${name}" in ${path} \u2014 nothing was deleted. ${storedNamesLine(file, path)}`, ...meant].join("\n")
690
+ );
691
+ Object.defineProperty(err, "suggestion", { value: nearAll[0], enumerable: true });
692
+ if (nearAll.length > 1) Object.defineProperty(err, "suggestions", { value: nearAll, enumerable: true });
693
+ throw err;
694
+ }
695
+ warn(`No credential profile "${name}" in ${path} \u2014 nothing to delete. ${storedNamesLine(file, path)}`, "profile.not-found");
696
+ if (isMachineOutput(args)) {
697
+ writeJson({
698
+ verb: "delete",
699
+ profile: name,
700
+ path,
701
+ deleted: false,
702
+ alreadyGone: true,
703
+ remaining: profileNames(file),
704
+ clearedDefault: false,
705
+ pinnedBy: null,
706
+ orphanedEnvironments: [],
707
+ removedFile: false,
708
+ ...revokeFields({ revoked: null })
709
+ });
710
+ }
711
+ return;
712
+ }
713
+ const pointer = findProjectPointer(process.cwd());
714
+ const isProjectFile = path === resolve(projectAuthFilePath());
715
+ const isDefault = file.default === name;
716
+ const isPinned = isProjectFile && pointer?.profile === name;
717
+ const onMachineFile = path === resolve(globalAuthFilePath());
718
+ const orphansDefault = isDefault && profileNames(file).length > 1 ? path : void 0;
719
+ if (!await confirmDanglingRemoval(args, "delete", name, isPinned ? pointer : void 0, orphansDefault)) {
720
+ info("Nothing was deleted.");
721
+ return;
722
+ }
723
+ let removedFile = false;
724
+ let revoke = { revoked: null };
725
+ let wasToken = false;
726
+ let removedRecord;
727
+ let remaining = {};
728
+ const left = await withCredentialLock(path, async (current) => {
729
+ const revocable = revocableRecord(current, name, path);
730
+ removedRecord = current.profiles[name];
731
+ wasToken = current.profiles[name]?.type === "token";
732
+ if (revocable !== void 0) {
733
+ step(`Revoking the session for "${name}"\u2026`);
734
+ revoke = await revokeProfileSession(args, revocable, name);
735
+ }
736
+ removedFile = writeOrRemoveCredentialFile(path, dropProfile(current, name));
737
+ remaining = { ...current.profiles };
738
+ return profileNames(current);
739
+ });
740
+ if (removedFile) removeEmptyProjectCacheDir(path);
741
+ if (isPinned && pointer !== void 0) {
742
+ warn(
743
+ `${pointer.path} still pins this project to "${name}", which no longer exists. Pin another profile with \`xanosdk profile use <name>\`, or store "${name}" again with \`${signInAgain(path, name, removedRecord)}\`.`,
744
+ "profile.pin-deleted"
745
+ );
746
+ }
747
+ const orphaned = isProjectFile ? environmentsFor(name) : [];
748
+ const unreachable = [];
749
+ for (const orphan of orphaned) {
750
+ const reacher = profileReaching(remaining, orphan.host, orphan.workspace);
751
+ if (reacher !== void 0) {
752
+ info(
753
+ `The environment "${orphan.name}" was deployed under "${name}"; "${reacher}" reaches the same workspace, so \`xanosdk ephemeral delete ${orphan.name} --profile ${reacher}${pipedYes()}\` still removes it.`
754
+ );
755
+ continue;
756
+ }
757
+ unreachable.push(orphan.name);
758
+ warn(
759
+ `The environment "${orphan.name}" was deployed under "${name}", and no stored profile reaches it now. It expires on its own; \`xanosdk ephemeral delete ${orphan.name}${pipedYes()}\`, run under a profile for workspace ${orphan.workspace} on ${orphan.host}, removes it and this project's record of it now.`,
760
+ "profile.orphan-ephemeral"
761
+ );
762
+ }
763
+ success(`Deleted profile "${name}".`);
764
+ if (wasToken) detail("The meta API token itself is still valid \u2014 revoke it at its source if you need it dead.");
765
+ const fileFlag = credentialFileFlag(path);
766
+ if (removedFile) detail(`It was the last profile, so ${path} was removed.`);
767
+ if (left.length === 0) {
768
+ const shared = isProjectFile ? readCredentialFile(globalAuthFilePath()) : null;
769
+ const sharedNames = shared === null ? [] : profileNames(shared);
770
+ detail(
771
+ sharedNames.length > 0 ? `No profiles are left in ${path} \u2014 commands here now read ${globalAuthFilePath()} (${quotedNames(sharedNames)}). To store one in this project again, run \`${signInAgain(path, name, removedRecord)}\`.` : `No profiles are left \u2014 run \`${signInAgain(path, name, removedRecord)}\` to sign in again.`
772
+ );
773
+ } else if (isDefault) {
774
+ detail(
775
+ `${onMachineFile ? "This machine has" : `${path} has`} no default now. Signed in as: ${quotedNames(left)} \u2014 set one with \`xanosdk profile set-default ${left.length === 1 ? left[0] : "<name>"}${fileFlag}\`.`
776
+ );
777
+ }
778
+ if (isMachineOutput(args)) {
779
+ writeJson({
780
+ verb: "delete",
781
+ profile: name,
782
+ path,
783
+ deleted: true,
784
+ alreadyGone: false,
785
+ remaining: left,
786
+ clearedDefault: isDefault,
787
+ // The `xano.profile.json` still pinning the deleted name — kept, since it
788
+ // is committed; null when none does. The key `logout` carries.
789
+ pinnedBy: isPinned ? pointer?.path ?? null : null,
790
+ // Only those no remaining profile reaches: the rest are still deletable as they are.
791
+ orphanedEnvironments: unreachable,
792
+ removedFile,
793
+ ...revokeFields(revoke)
794
+ });
795
+ }
796
+ }
797
+ export {
798
+ runProfileCommand
799
+ };
800
+ //# sourceMappingURL=profile-command-AH3PIM4X.js.map