@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.
- package/CHANGELOG.md +788 -0
- package/LICENSE +21 -0
- package/README.md +541 -0
- package/dist/.build-fingerprint +1 -0
- package/dist/agent-file-refresh-ZEMK33AX.js +38 -0
- package/dist/answer-shape-K67TAAPY.js +33 -0
- package/dist/backend-dir-2U53CIAL.js +39 -0
- package/dist/backend-slot-7QXW2QYC.js +28 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +255 -0
- package/dist/branch-NCRNWQBQ.js +61 -0
- package/dist/branch-commands-ACIRCEQJ.js +79 -0
- package/dist/bundle.d.ts +223 -0
- package/dist/bundle.js +153 -0
- package/dist/capture-WAXPD7DR.js +41 -0
- package/dist/chunk-27GWNP2I.js +23 -0
- package/dist/chunk-2CMJZDCL.js +177 -0
- package/dist/chunk-2EZ3ZJZZ.js +302 -0
- package/dist/chunk-2GNFDZA2.js +390 -0
- package/dist/chunk-2MNLRIOX.js +11 -0
- package/dist/chunk-2TFRR6JV.js +104 -0
- package/dist/chunk-2ZUEE4EK.js +408 -0
- package/dist/chunk-36JUQZVQ.js +22 -0
- package/dist/chunk-3DRXWLJ5.js +83 -0
- package/dist/chunk-3JDU4VRL.js +137 -0
- package/dist/chunk-3KZCLN4Z.js +241 -0
- package/dist/chunk-3LDULPRE.js +168 -0
- package/dist/chunk-3M4LFYNQ.js +111 -0
- package/dist/chunk-3XI5CTUE.js +22 -0
- package/dist/chunk-3YW23UFH.js +50 -0
- package/dist/chunk-45UIT5T2.js +862 -0
- package/dist/chunk-4BW2SG2N.js +46 -0
- package/dist/chunk-4KHEMC32.js +79 -0
- package/dist/chunk-4POWHT2K.js +321 -0
- package/dist/chunk-4Q2GN7NW.js +192 -0
- package/dist/chunk-5A2PLKZB.js +70 -0
- package/dist/chunk-5FBYXK5P.js +159 -0
- package/dist/chunk-5HVXPTU4.js +323 -0
- package/dist/chunk-5QU2P5CA.js +304 -0
- package/dist/chunk-5V5XU32D.js +191 -0
- package/dist/chunk-5ZSO4T2G.js +10 -0
- package/dist/chunk-622HUCZT.js +10 -0
- package/dist/chunk-65HWOMGV.js +177 -0
- package/dist/chunk-6ELFRN3P.js +365 -0
- package/dist/chunk-6HO3NCSJ.js +1055 -0
- package/dist/chunk-6IUMKYWI.js +457 -0
- package/dist/chunk-6KEB3C3U.js +65 -0
- package/dist/chunk-6MR5TI5V.js +987 -0
- package/dist/chunk-6NNTNXN7.js +157 -0
- package/dist/chunk-6PBR37LN.js +97 -0
- package/dist/chunk-6QXLMMT3.js +155 -0
- package/dist/chunk-6ZGJCBZS.js +224 -0
- package/dist/chunk-73IVBKMA.js +250 -0
- package/dist/chunk-7G3CTU7I.js +286 -0
- package/dist/chunk-A3UDOZB6.js +222 -0
- package/dist/chunk-A6E77GDW.js +85 -0
- package/dist/chunk-AHJWCYQO.js +660 -0
- package/dist/chunk-AKNCFVKZ.js +36 -0
- package/dist/chunk-AM4FKL4J.js +237 -0
- package/dist/chunk-AN6BL47T.js +26 -0
- package/dist/chunk-AOSYVMUS.js +147 -0
- package/dist/chunk-APWXY5SL.js +182 -0
- package/dist/chunk-AWEIIR2U.js +218 -0
- package/dist/chunk-AWQ7BQTQ.js +73 -0
- package/dist/chunk-BAUZOWGX.js +393 -0
- package/dist/chunk-BHACRS6R.js +940 -0
- package/dist/chunk-BWPNT55T.js +680 -0
- package/dist/chunk-C6RIMRU4.js +187 -0
- package/dist/chunk-CGVQZXYG.js +263 -0
- package/dist/chunk-CIMQZRRE.js +162 -0
- package/dist/chunk-CJHQKJU4.js +113 -0
- package/dist/chunk-CTMO46PK.js +1897 -0
- package/dist/chunk-D53J55C5.js +106 -0
- package/dist/chunk-D7VGG3WS.js +90 -0
- package/dist/chunk-DAD3ONIS.js +245 -0
- package/dist/chunk-DGWHAVRG.js +162 -0
- package/dist/chunk-DX4QR4B2.js +483 -0
- package/dist/chunk-EHP3WPEG.js +21 -0
- package/dist/chunk-ELP2HMXC.js +432 -0
- package/dist/chunk-ERVIASGL.js +21 -0
- package/dist/chunk-ET4Y4XCB.js +865 -0
- package/dist/chunk-ETO6LGLD.js +4750 -0
- package/dist/chunk-EUUUMY7J.js +24 -0
- package/dist/chunk-FQJ2TTHP.js +218 -0
- package/dist/chunk-FQOF7E2E.js +133 -0
- package/dist/chunk-FWD7AL6N.js +21 -0
- package/dist/chunk-FXFV3KU6.js +138 -0
- package/dist/chunk-FXRQOWTE.js +171 -0
- package/dist/chunk-G554NZNI.js +210 -0
- package/dist/chunk-GSGDWJB5.js +13 -0
- package/dist/chunk-H2V3N23D.js +66 -0
- package/dist/chunk-H5C7MBCR.js +159 -0
- package/dist/chunk-HHN734BU.js +371 -0
- package/dist/chunk-HRVBLCVJ.js +243 -0
- package/dist/chunk-HVRUQXGD.js +1264 -0
- package/dist/chunk-I4F5TCJH.js +130 -0
- package/dist/chunk-IDOTCMDV.js +57 -0
- package/dist/chunk-IGOLHKWF.js +427 -0
- package/dist/chunk-JGE7CAWB.js +148 -0
- package/dist/chunk-JTUKLCXS.js +92 -0
- package/dist/chunk-JZGVVJSI.js +66 -0
- package/dist/chunk-K4WX6UUU.js +923 -0
- package/dist/chunk-K5BBGTYZ.js +217 -0
- package/dist/chunk-K6RXBGUB.js +427 -0
- package/dist/chunk-KTSDSD36.js +165 -0
- package/dist/chunk-L5JYN3NM.js +1038 -0
- package/dist/chunk-LIEOKXKD.js +354 -0
- package/dist/chunk-LLNZGEFK.js +51 -0
- package/dist/chunk-LPECSJ2J.js +55 -0
- package/dist/chunk-LQCMKAJ7.js +413 -0
- package/dist/chunk-LRN4ZJCQ.js +1145 -0
- package/dist/chunk-MJ4ZVHKN.js +17 -0
- package/dist/chunk-MXHSQOC4.js +3061 -0
- package/dist/chunk-N5GKCWE5.js +367 -0
- package/dist/chunk-NA3PXMEF.js +10 -0
- package/dist/chunk-NAQDMEHV.js +76 -0
- package/dist/chunk-NWKXM5RD.js +109 -0
- package/dist/chunk-NZOWWHU5.js +196 -0
- package/dist/chunk-OHX6MIUZ.js +184 -0
- package/dist/chunk-OOXWYAA4.js +15 -0
- package/dist/chunk-OPHB5ORL.js +1990 -0
- package/dist/chunk-OXA6PSZT.js +1725 -0
- package/dist/chunk-P2HAGF6H.js +73 -0
- package/dist/chunk-PTHVMXZI.js +3036 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-Q325JKYB.js +189 -0
- package/dist/chunk-Q7DGTQ5G.js +255 -0
- package/dist/chunk-QCNYHBL7.js +601 -0
- package/dist/chunk-QO6BVGS5.js +145 -0
- package/dist/chunk-QXTKSOFI.js +76 -0
- package/dist/chunk-ROY4YAEQ.js +66 -0
- package/dist/chunk-RTJRZFFY.js +447 -0
- package/dist/chunk-SAVJUS2X.js +128 -0
- package/dist/chunk-SFLHVCKX.js +173 -0
- package/dist/chunk-STSFNCY4.js +127 -0
- package/dist/chunk-SWBF2LTK.js +170 -0
- package/dist/chunk-T5KELPAR.js +109 -0
- package/dist/chunk-TFFGOFVZ.js +1481 -0
- package/dist/chunk-TLHIFK4M.js +256 -0
- package/dist/chunk-TLQE7ZN3.js +156 -0
- package/dist/chunk-TPHWJ7UG.js +1981 -0
- package/dist/chunk-TRJCALW3.js +291 -0
- package/dist/chunk-TTEIYD5P.js +133 -0
- package/dist/chunk-U64O2MXY.js +407 -0
- package/dist/chunk-UCQ2VUTG.js +630 -0
- package/dist/chunk-UTI5G6OJ.js +44 -0
- package/dist/chunk-UVHDMMIP.js +188 -0
- package/dist/chunk-UZ6QQWJT.js +120 -0
- package/dist/chunk-VAX3UZOY.js +686 -0
- package/dist/chunk-W3HBUKFO.js +57 -0
- package/dist/chunk-WKQLGKCL.js +2823 -0
- package/dist/chunk-WQFNASK4.js +560 -0
- package/dist/chunk-WRBKLYSJ.js +224 -0
- package/dist/chunk-WTPZRR4I.js +17 -0
- package/dist/chunk-WZDJ2LLX.js +2385 -0
- package/dist/chunk-X2NL4KUO.js +14 -0
- package/dist/chunk-X4DVXBFY.js +38 -0
- package/dist/chunk-X677DMZM.js +7050 -0
- package/dist/chunk-XBKMWY7F.js +612 -0
- package/dist/chunk-XNCP4KYO.js +78 -0
- package/dist/chunk-XVBGLISP.js +35 -0
- package/dist/chunk-XW6KISBB.js +1192 -0
- package/dist/chunk-YGZHHAAB.js +8156 -0
- package/dist/chunk-YHEFQUQB.js +186 -0
- package/dist/chunk-YLDALTWZ.js +653 -0
- package/dist/chunk-YU4HSQW7.js +229 -0
- package/dist/chunk-ZDPP6RKB.js +27 -0
- package/dist/chunk-ZFDZKNGG.js +194 -0
- package/dist/chunk-ZIY7RNUT.js +49 -0
- package/dist/chunk-ZYJP6BOO.js +30 -0
- package/dist/cli.d.ts +1111 -0
- package/dist/cli.js +165 -0
- package/dist/codegen-command-VR2GWR6C.js +173 -0
- package/dist/codegen.d.ts +115 -0
- package/dist/codegen.js +19 -0
- package/dist/commands-GJMJ4XYZ.js +76 -0
- package/dist/completion-ZQLO6PB6.js +738 -0
- package/dist/config-MBYGCAFK.js +136 -0
- package/dist/deploy-command-JVZPWHMK.js +180 -0
- package/dist/deploy-source-3W45CXMP.js +81 -0
- package/dist/dev-env-sync-HN44K4D5.js +188 -0
- package/dist/diagnostics-UEAAHWVF.js +30 -0
- package/dist/display-name-hint-ABBPVQIR.js +46 -0
- package/dist/emit-CyhBDxli.d.ts +7007 -0
- package/dist/env-example-refresh-ET5HMMDW.js +126 -0
- package/dist/env-pull-command-TNMNB3CV.js +323 -0
- package/dist/env-target-O4HRKTGZ.js +40 -0
- package/dist/env-var-command-ZIRDCAZA.js +427 -0
- package/dist/ephemeral-P7F3PMAD.js +54 -0
- package/dist/ephemeral-command-CLJJKOFT.js +592 -0
- package/dist/ephemeral-state-PYCBSOGX.js +61 -0
- package/dist/file-lock-PT74GWYW.js +10 -0
- package/dist/generate-command-AYEOLA26.js +510 -0
- package/dist/gitignore-3SJ3WNRG.js +51 -0
- package/dist/guards-4EBNCZDC.js +162 -0
- package/dist/hosted-file-PSHJB3HX.js +28 -0
- package/dist/impersonate-command-5JAS3WSV.js +152 -0
- package/dist/import-EQSFU6JC.js +19 -0
- package/dist/index.d.ts +5470 -0
- package/dist/index.js +371 -0
- package/dist/init-command-X2FR4UAK.js +125 -0
- package/dist/init-modules-RY7UHAOL.js +50 -0
- package/dist/init-web-M4YZSZK6.js +42 -0
- package/dist/internal.d.ts +179 -0
- package/dist/internal.js +2634 -0
- package/dist/io-RC56QSN5.js +26 -0
- package/dist/keep-data-merge-7MPLVAVI.js +1119 -0
- package/dist/lambda-config-reconcile-OUZ4OYAB.js +116 -0
- package/dist/landed-753YLJ5H.js +40 -0
- package/dist/landing-record-SU52SKXU.js +61 -0
- package/dist/live-diff-YONW2VI3.js +65 -0
- package/dist/local-engine-choice-CH5X3W7E.js +79 -0
- package/dist/local-engine-command-Z3OL7VOD.js +766 -0
- package/dist/local-engine-config-5U3SC434.js +39 -0
- package/dist/local-engine-deploy-PCQ4SNPB.js +39 -0
- package/dist/local-engine-process-EHTE5LLU.js +63 -0
- package/dist/local-engine-state-A4FTRFAF.js +32 -0
- package/dist/local-engine-update-check-6L645VBL.js +162 -0
- package/dist/lock-MRRHW5GS.js +87 -0
- package/dist/lock-commands-2QG25HL7.js +963 -0
- package/dist/login-command-QPYRWOXZ.js +538 -0
- package/dist/logout-command-WOIQLDP6.js +56 -0
- package/dist/loop-ALIZLOSX.js +191 -0
- package/dist/marketplace-command-K5YL42NO.js +977 -0
- package/dist/marketplace-resolve-LY32JES5.js +40 -0
- package/dist/meta-client-YXGPW53C.js +244 -0
- package/dist/module-manifest-JFGHU2TC.js +38 -0
- package/dist/near-key.d.ts +13 -0
- package/dist/near-key.js +8 -0
- package/dist/node.d.ts +95 -0
- package/dist/node.js +969 -0
- package/dist/operation-outcome-TZSESNC7.js +51 -0
- package/dist/output-target-AL3I44GG.js +47 -0
- package/dist/package-manager-PRAHUSCN.js +34 -0
- package/dist/plan-disclosure-6G4MLZKD.js +114 -0
- package/dist/plugin-contributions-WRNY5ABG.js +28 -0
- package/dist/plugin-prompt-4VA3B4FF.js +20 -0
- package/dist/plugin-questions-JTSYA74Q.js +24 -0
- package/dist/plugin.d.ts +396 -0
- package/dist/plugin.js +1 -0
- package/dist/preflight-command-2T5Z36MI.js +321 -0
- package/dist/profile-command-AH3PIM4X.js +800 -0
- package/dist/profile-pointer-GRWJU3YD.js +31 -0
- package/dist/profile-select-74TRDEPD.js +23 -0
- package/dist/project-dependency-KSH63ODT.js +35 -0
- package/dist/project-sdk-REPPOIBD.js +24 -0
- package/dist/promote-command-PCWT5N6S.js +140 -0
- package/dist/prompt-II3F3LND.js +27 -0
- package/dist/publish-command-TTDUUJI5.js +414 -0
- package/dist/pull-command-VBO7C4S3.js +161 -0
- package/dist/pull-superseded-GJWLG7XO.js +20 -0
- package/dist/release-command-N4ZPKMHR.js +146 -0
- package/dist/release-ns-command-3KFDMZ6G.js +1745 -0
- package/dist/response-HlXahv4K.d.ts +925 -0
- package/dist/retry-command-AS5EVREX.js +34 -0
- package/dist/routes-manifest-SNWUVBT6.js +43 -0
- package/dist/runtime-XETHVF33.js +14 -0
- package/dist/scaffold.d.ts +1911 -0
- package/dist/scaffold.js +107 -0
- package/dist/secrets-file-LVZD6IIM.js +56 -0
- package/dist/secrets-fill-command-TTCPSVXN.js +218 -0
- package/dist/seed-VU7C3QYS.js +46 -0
- package/dist/sent-writes-N7X4OVXT.js +22 -0
- package/dist/source-resolve-S2XA3XZF.js +83 -0
- package/dist/static-host-B2Y6AG3W.js +352 -0
- package/dist/status-command-RUDXTF7I.js +554 -0
- package/dist/store-6VNCD4D7.js +20 -0
- package/dist/store-ARM6VMO5.js +98 -0
- package/dist/store-DuYfzKlW.d.ts +3144 -0
- package/dist/suggest-6FOOYKHG.js +12 -0
- package/dist/sveltekit.d.ts +154 -0
- package/dist/sveltekit.js +109 -0
- package/dist/sync-contributions-UCEROO26.js +415 -0
- package/dist/table-ENAVMITR.js +42 -0
- package/dist/tables-command-GUPXXSB5.js +156 -0
- package/dist/tenant-IIHPOHGP.js +42 -0
- package/dist/tenant-command-D5HGI2X4.js +965 -0
- package/dist/test-command-TIKZMDPZ.js +476 -0
- package/dist/tests-BGGIOK3L.js +26 -0
- package/dist/token-NICJUTMT.js +72 -0
- package/dist/toolchain-hooks-GHKLUJOH.js +96 -0
- package/dist/toolchain-modules-5EAZUONB.js +24 -0
- package/dist/tracked-backend-EIBUMDZA.js +80 -0
- package/dist/update-check-2W2NLDTC.js +136 -0
- package/dist/upgrade-command-QHNFWM7O.js +531 -0
- package/dist/verify-rollout-DRCK5TDD.js +61 -0
- package/dist/whoami-command-STGINTXH.js +51 -0
- package/dist/workspace-2CLHU2LK.js +93 -0
- package/dist/workspace-binding-56PIIPCP.js +54 -0
- package/dist/workspace-command-JEXQETJD.js +535 -0
- package/dist/workspace-env-F2RFMSC5.js +70 -0
- package/dist/workspace-export-OJSH2HIW.js +21 -0
- package/dist/writable-VA7OISSK.js +25 -0
- package/dist/xano-ICFUSPFR.js +42 -0
- package/dist/xanosdk-import-GN42TO2B.js +56 -0
- package/dist/xanosdk-project-S6DXJONQ.js +41 -0
- package/dist/xdo-CxDr2Q1C.d.ts +1371 -0
- package/guides/README.md +33 -0
- package/guides/authoring.md +921 -0
- package/guides/cli.md +401 -0
- package/guides/codegen.md +177 -0
- package/guides/codes.md +404 -0
- package/guides/coverage.md +74 -0
- package/guides/deploying.md +1525 -0
- package/guides/environment.md +400 -0
- package/guides/marketplace.md +415 -0
- package/guides/module-contract.md +558 -0
- package/guides/object-kinds.md +433 -0
- package/guides/project-structure.md +43 -0
- package/guides/scaffold.md +351 -0
- package/guides/typed-frontend.md +242 -0
- package/llms/client.md +63 -0
- package/llms/errors.md +56 -0
- package/llms/fields.md +176 -0
- package/llms/filters.md +183 -0
- package/llms/kinds-agent-mcp.md +30 -0
- package/llms/kinds-core.md +100 -0
- package/llms/kinds-knowledge.md +20 -0
- package/llms/kinds-realtime.md +76 -0
- package/llms/lambda.md +94 -0
- package/llms/legacy.md +44 -0
- package/llms/lock.md +40 -0
- package/llms/object-kinds.md +34 -0
- package/llms/statements-calls.md +62 -0
- package/llms/statements-catalog.md +320 -0
- package/llms/statements-data.md +66 -0
- package/llms/statements-runtime.md +68 -0
- package/llms/tests.md +59 -0
- package/llms/toolchain.md +16 -0
- package/llms/triggers.md +36 -0
- package/llms/values.md +29 -0
- package/llms-full.txt +2085 -0
- package/llms.txt +493 -0
- package/manifest.json +11224 -0
- package/package.json +162 -0
- package/types/lambda-globals.d.ts +129 -0
|
@@ -0,0 +1,865 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readEphemeralState
|
|
3
|
+
} from "./chunk-5QU2P5CA.js";
|
|
4
|
+
import {
|
|
5
|
+
OpenIdProvider,
|
|
6
|
+
addProfileHint,
|
|
7
|
+
assertHttpsOrigin,
|
|
8
|
+
assertNoUserinfo,
|
|
9
|
+
assertSignInOrigin,
|
|
10
|
+
buildTokenCredential,
|
|
11
|
+
credentialFileFlag,
|
|
12
|
+
decodeAudience,
|
|
13
|
+
dropProfile,
|
|
14
|
+
envOrigin,
|
|
15
|
+
globalAuthFilePath,
|
|
16
|
+
isSafeIdText,
|
|
17
|
+
localAuthFilePath,
|
|
18
|
+
loginCommand,
|
|
19
|
+
loginHint,
|
|
20
|
+
oauthErrorCode,
|
|
21
|
+
oauthErrorResponse,
|
|
22
|
+
profileNames,
|
|
23
|
+
readCredential,
|
|
24
|
+
readCredentialFile,
|
|
25
|
+
readProfile,
|
|
26
|
+
resolveAuthFilePath,
|
|
27
|
+
resolveAuthHost,
|
|
28
|
+
resolveOAuthErrorCode,
|
|
29
|
+
resolveScope,
|
|
30
|
+
withCredentialLock,
|
|
31
|
+
writeCredentialFile,
|
|
32
|
+
writeOrRemoveCredentialFile
|
|
33
|
+
} from "./chunk-XW6KISBB.js";
|
|
34
|
+
import {
|
|
35
|
+
registerSecret,
|
|
36
|
+
tokenTextProblem
|
|
37
|
+
} from "./chunk-AWQ7BQTQ.js";
|
|
38
|
+
import {
|
|
39
|
+
expandHome,
|
|
40
|
+
readPathEnvVar
|
|
41
|
+
} from "./chunk-EUUUMY7J.js";
|
|
42
|
+
import {
|
|
43
|
+
RATE_LIMIT_MAX_WAIT_S,
|
|
44
|
+
noteResolvedAuth,
|
|
45
|
+
retryAfterSeconds,
|
|
46
|
+
serverMessage
|
|
47
|
+
} from "./chunk-YLDALTWZ.js";
|
|
48
|
+
import {
|
|
49
|
+
POINTER_FILE,
|
|
50
|
+
findProjectPointer
|
|
51
|
+
} from "./chunk-5FBYXK5P.js";
|
|
52
|
+
import {
|
|
53
|
+
DEFAULT_PROFILE,
|
|
54
|
+
ENV_PROFILE,
|
|
55
|
+
assertValidProfileName,
|
|
56
|
+
describeProfileSelection,
|
|
57
|
+
profileSourceLabel,
|
|
58
|
+
resolveActiveProfile
|
|
59
|
+
} from "./chunk-QXTKSOFI.js";
|
|
60
|
+
import {
|
|
61
|
+
readEnvVar
|
|
62
|
+
} from "./chunk-X2NL4KUO.js";
|
|
63
|
+
import {
|
|
64
|
+
EXIT_SOURCE_UNRESOLVABLE,
|
|
65
|
+
UsageError,
|
|
66
|
+
detail,
|
|
67
|
+
hostLabel,
|
|
68
|
+
info,
|
|
69
|
+
noteRunWarning,
|
|
70
|
+
quotedNames,
|
|
71
|
+
safeText,
|
|
72
|
+
warn
|
|
73
|
+
} from "./chunk-PTHVMXZI.js";
|
|
74
|
+
import {
|
|
75
|
+
suggest
|
|
76
|
+
} from "./chunk-UTI5G6OJ.js";
|
|
77
|
+
import {
|
|
78
|
+
shellQuote
|
|
79
|
+
} from "./chunk-5ZSO4T2G.js";
|
|
80
|
+
|
|
81
|
+
// src/auth/token.ts
|
|
82
|
+
import { existsSync, statSync } from "fs";
|
|
83
|
+
import { dirname, resolve as resolvePath } from "path";
|
|
84
|
+
var EXPIRY_SKEW_MS = 3e4;
|
|
85
|
+
function stampExpiry(raw) {
|
|
86
|
+
return {
|
|
87
|
+
access_token: raw.access_token,
|
|
88
|
+
refresh_token: raw.refresh_token,
|
|
89
|
+
scope: raw.scope,
|
|
90
|
+
expires_at: Date.now() + (raw.expires_in ?? 0) * 1e3
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function refreshAccessToken(authHost, clientId, refreshToken, scope) {
|
|
94
|
+
const provider = new OpenIdProvider({ authHost, scope: scope ?? "", clientId });
|
|
95
|
+
return provider.refresh(refreshToken, { scope });
|
|
96
|
+
}
|
|
97
|
+
function isTransientRefreshError(err) {
|
|
98
|
+
if (oauthErrorCode(err) !== void 0) return false;
|
|
99
|
+
const res = oauthErrorResponse(err);
|
|
100
|
+
if (res === void 0) return true;
|
|
101
|
+
return res.status >= 500 || res.status === 429;
|
|
102
|
+
}
|
|
103
|
+
function unansweredRefresh(failure, err) {
|
|
104
|
+
const status = oauthErrorResponse(err)?.status;
|
|
105
|
+
return Object.assign(failure, { exitCode: 8 }, status === void 0 ? {} : { status });
|
|
106
|
+
}
|
|
107
|
+
async function refusedRefreshCredential(err) {
|
|
108
|
+
const code = await resolveOAuthErrorCode(err);
|
|
109
|
+
if (code === "invalid_grant") return "token";
|
|
110
|
+
if (code === "invalid_client" || code === "unauthorized_client") return "client";
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
async function describeRefreshFailure(err) {
|
|
114
|
+
const rfc = oauthErrorCode(err);
|
|
115
|
+
if (rfc !== void 0) {
|
|
116
|
+
const { status, error_description: description } = err ?? {};
|
|
117
|
+
const said = typeof description === "string" && description.trim() !== "" ? `: ${description.trim()}` : "";
|
|
118
|
+
return `the authorization server answered ${typeof status === "number" ? `HTTP ${status} \u2014 ` : ""}${rfc}${said}`;
|
|
119
|
+
}
|
|
120
|
+
const answer = await describeRefreshAnswer(err);
|
|
121
|
+
if (answer !== void 0) return `the authorization server answered ${answer}`;
|
|
122
|
+
return err instanceof Error ? err.message : String(err);
|
|
123
|
+
}
|
|
124
|
+
async function describeRefreshAnswer(err) {
|
|
125
|
+
const res = oauthErrorResponse(err);
|
|
126
|
+
if (res === void 0) return void 0;
|
|
127
|
+
const parts = [`HTTP ${res.status}`];
|
|
128
|
+
const code = await resolveOAuthErrorCode(err);
|
|
129
|
+
if (code !== void 0) parts.push(code);
|
|
130
|
+
else if (!res.bodyUsed) {
|
|
131
|
+
try {
|
|
132
|
+
const said = serverMessage(await res.clone().text());
|
|
133
|
+
if (said !== void 0) parts.push(said);
|
|
134
|
+
} catch {
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return parts.join(" \u2014 ");
|
|
138
|
+
}
|
|
139
|
+
async function refreshWithRetry(authHost, clientId, refreshToken, scope) {
|
|
140
|
+
try {
|
|
141
|
+
return await refreshAccessToken(authHost, clientId, refreshToken, scope);
|
|
142
|
+
} catch (err) {
|
|
143
|
+
if (!isTransientRefreshError(err)) throw err;
|
|
144
|
+
const status = oauthErrorResponse(err)?.status;
|
|
145
|
+
if (status === 429) {
|
|
146
|
+
const wait = refreshRetryAfter(err) ?? 1;
|
|
147
|
+
if (wait > RATE_LIMIT_MAX_WAIT_S) throw err;
|
|
148
|
+
detail(`The authorization server is rate limiting (HTTP 429); retrying once in ${wait}s\u2026`);
|
|
149
|
+
await new Promise((r) => setTimeout(r, wait * 1e3));
|
|
150
|
+
return await refreshAccessToken(authHost, clientId, refreshToken, scope);
|
|
151
|
+
}
|
|
152
|
+
detail(
|
|
153
|
+
status === void 0 ? `Token refresh hit a network error; retrying once\u2026` : `The authorization server answered HTTP ${status}; retrying once\u2026`
|
|
154
|
+
);
|
|
155
|
+
return await refreshAccessToken(authHost, clientId, refreshToken, scope);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function retriedNote(err) {
|
|
159
|
+
return oauthErrorResponse(err)?.status === 429 && (refreshRetryAfter(err) ?? 1) > RATE_LIMIT_MAX_WAIT_S ? "" : ", even after one retry";
|
|
160
|
+
}
|
|
161
|
+
function refreshRetryAfter(err) {
|
|
162
|
+
return retryAfterSeconds(oauthErrorResponse(err)?.headers?.get?.("retry-after") ?? null);
|
|
163
|
+
}
|
|
164
|
+
function unansweredRefreshCause(err, authHost, fix) {
|
|
165
|
+
if (oauthErrorResponse(err)?.status === 429) {
|
|
166
|
+
const wait = refreshRetryAfter(err);
|
|
167
|
+
return `This is rate limiting, not an auth problem \u2014 ${wait === void 0 ? "wait a moment, then re-run the command" : `wait ${wait}s (its Retry-After), then re-run the command`}. ${fix} would not help.`;
|
|
168
|
+
}
|
|
169
|
+
return `This is a server-side error, not an auth problem \u2014 re-run the command. If it persists, ${authHost} is having trouble; ${fix.charAt(0).toLowerCase()}${fix.slice(1)} would not help.`;
|
|
170
|
+
}
|
|
171
|
+
var ENV_INSTANCE = "XANO_INSTANCE_URL";
|
|
172
|
+
var ENV_WORKSPACE = "XANO_WORKSPACE_ID";
|
|
173
|
+
var ENV_META_TOKEN = "XANO_META_TOKEN";
|
|
174
|
+
function readEnvMetaCredential() {
|
|
175
|
+
const instance = readEnvVar(ENV_INSTANCE);
|
|
176
|
+
const workspace = readEnvVar(ENV_WORKSPACE);
|
|
177
|
+
const token = readEnvVar(ENV_META_TOKEN);
|
|
178
|
+
if (instance === void 0 && workspace === void 0 && token === void 0) return void 0;
|
|
179
|
+
const missing = [
|
|
180
|
+
instance === void 0 ? ENV_INSTANCE : void 0,
|
|
181
|
+
workspace === void 0 ? ENV_WORKSPACE : void 0,
|
|
182
|
+
token === void 0 ? ENV_META_TOKEN : void 0
|
|
183
|
+
].filter((n) => n !== void 0);
|
|
184
|
+
if (missing.length > 0) {
|
|
185
|
+
const set = [ENV_INSTANCE, ENV_WORKSPACE, ENV_META_TOKEN].filter((n) => !missing.includes(n));
|
|
186
|
+
throw new UsageError(
|
|
187
|
+
`Incomplete meta credential in the environment: ${set.join(", ")} ${set.length === 1 ? "is" : "are"} set but ${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} not. All three are required \u2014 check for a misspelled secret name, or unset the rest to use a different credential.`
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
return buildTokenCredential(
|
|
192
|
+
{
|
|
193
|
+
instance,
|
|
194
|
+
// Parsed here, not in the validator: pass the ORIGINAL string through on a
|
|
195
|
+
// bad parse so the rejection quotes what was actually set, not `NaN`.
|
|
196
|
+
workspaceId: isSafeIdText(workspace) ? Number(workspace.trim()) : workspace,
|
|
197
|
+
token
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
at: "in the environment",
|
|
201
|
+
labels: { instance: ENV_INSTANCE, workspace: ENV_WORKSPACE, token: ENV_META_TOKEN }
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
} catch (err) {
|
|
205
|
+
throw err instanceof UsageError ? err : new UsageError(err instanceof Error ? err.message : String(err));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function envMetaCredentialVarsSet() {
|
|
209
|
+
return [ENV_INSTANCE, ENV_WORKSPACE, ENV_META_TOKEN].filter(
|
|
210
|
+
(name) => readEnvVar(name) !== void 0
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
function environmentCredentialVars() {
|
|
214
|
+
const meta = envMetaCredentialVarsSet();
|
|
215
|
+
const refresh = readEnvVar("XANO_REFRESH_TOKEN") !== void 0;
|
|
216
|
+
const clientId = readEnvVar("XANO_CLIENT_ID") !== void 0;
|
|
217
|
+
const vars = refresh ? [...meta, "XANO_REFRESH_TOKEN"] : [...meta];
|
|
218
|
+
const complete = meta.length === 3 || meta.length === 0 && refresh && clientId;
|
|
219
|
+
return { vars, complete };
|
|
220
|
+
}
|
|
221
|
+
function noteDisplacedCredentials(args, variable) {
|
|
222
|
+
const configPath = expandHome(args.authFile) ?? readPathEnvVar("XANO_CONFIG");
|
|
223
|
+
if (configPath !== void 0 && existsSync(configPath)) {
|
|
224
|
+
info(
|
|
225
|
+
args.toProfile !== void 0 ? `Using the ${variable} credential from the environment for this run's sign-in \u2014 \`--to-profile\` still reads ${configPath}.` : `Using the ${variable} credential from the environment \u2014 ignoring ${configPath}.`
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
if (variable !== "XANO_REFRESH_TOKEN" && readEnvVar("XANO_REFRESH_TOKEN") !== void 0) {
|
|
229
|
+
info(`Using the ${variable} credential from the environment \u2014 ignoring XANO_REFRESH_TOKEN.`);
|
|
230
|
+
}
|
|
231
|
+
const profile = readEnvVar(ENV_PROFILE);
|
|
232
|
+
if (profile !== void 0) {
|
|
233
|
+
info(`Using the ${variable} credential from the environment \u2014 ignoring ${ENV_PROFILE}=${profile.trim()}.`);
|
|
234
|
+
}
|
|
235
|
+
const pin = pinnedProfile();
|
|
236
|
+
if (pin !== void 0) {
|
|
237
|
+
const message = `Using the ${variable} credential from the environment \u2014 ignoring ${pin.path}, which pins this project to profile "${pin.profile}".`;
|
|
238
|
+
info(message);
|
|
239
|
+
noteRunWarning("credential.env-overrides-pin", message);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function pinnedProfile() {
|
|
243
|
+
try {
|
|
244
|
+
return findProjectPointer(process.cwd());
|
|
245
|
+
} catch {
|
|
246
|
+
return void 0;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function storedProfile(args) {
|
|
250
|
+
try {
|
|
251
|
+
const path = resolveAuthFilePath(args);
|
|
252
|
+
const file = readCredentialFile(path);
|
|
253
|
+
const selection = resolveActiveProfile({
|
|
254
|
+
flag: args.profile,
|
|
255
|
+
fileDefault: file?.default,
|
|
256
|
+
readPointer: () => findProjectPointer(process.cwd())?.profile
|
|
257
|
+
});
|
|
258
|
+
const raw = file?.profiles[selection.name];
|
|
259
|
+
const kind = raw === void 0 ? "none" : raw.type === "token" || raw.type === "oauth" ? raw.type : "unknown";
|
|
260
|
+
return { name: selection.name, path, kind };
|
|
261
|
+
} catch {
|
|
262
|
+
return void 0;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function refuseUnusedOrigin(args, envMeta) {
|
|
266
|
+
const typed = args.authHost;
|
|
267
|
+
try {
|
|
268
|
+
assertNoUserinfo(typed, "`--origin`");
|
|
269
|
+
} catch (err) {
|
|
270
|
+
throw new UsageError(err instanceof Error ? err.message : String(err));
|
|
271
|
+
}
|
|
272
|
+
const lead = "`--origin` selects the OAuth host a sign-in (`login`) goes to and the one XANO_REFRESH_TOKEN is exchanged at, and this run does neither: ";
|
|
273
|
+
if (envMeta !== void 0) {
|
|
274
|
+
throw new UsageError(`${lead}it uses XANO_META_TOKEN, which never refreshes. Drop \`--origin\`.`);
|
|
275
|
+
}
|
|
276
|
+
const stored = storedProfile(args);
|
|
277
|
+
if (stored?.kind === "token") {
|
|
278
|
+
throw new UsageError(
|
|
279
|
+
`${lead}it uses a stored meta API token profile, which has no sign-in server and never refreshes. Drop \`--origin\`.`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
const name = stored?.name ?? DEFAULT_PROFILE;
|
|
283
|
+
const target = { path: stored?.path, origin: typed };
|
|
284
|
+
let unusable;
|
|
285
|
+
try {
|
|
286
|
+
assertSignInOrigin(typed, "`--origin`");
|
|
287
|
+
} catch (err) {
|
|
288
|
+
unusable = err instanceof Error ? err.message : String(err);
|
|
289
|
+
}
|
|
290
|
+
if (stored?.kind === "none") {
|
|
291
|
+
throw new UsageError(
|
|
292
|
+
`${lead}no XANO_REFRESH_TOKEN is set, and no profile "${name}" is stored in ${stored.path}. ` + (unusable === void 0 ? `Drop \`--origin\`, or sign in through that server with \`${loginCommand(name, target)}\`.` : `Drop \`--origin\` \u2014 it could not be a sign-in server either: ${unusable}`)
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
throw new UsageError(
|
|
296
|
+
`${lead}it uses a stored profile, which refreshes at the sign-in server recorded with it. ` + (unusable === void 0 ? `Drop \`--origin\`; to change that profile's sign-in server, run \`${loginCommand(name, target, ["--force"])}\`.` : `Drop \`--origin\` \u2014 it could not be that profile's sign-in server either: ${unusable}`)
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
async function getAccessToken(args) {
|
|
300
|
+
const auth = await resolveAccessToken(args);
|
|
301
|
+
registerSecret(auth.access_token);
|
|
302
|
+
noteResolvedAuth(auth, args);
|
|
303
|
+
return auth;
|
|
304
|
+
}
|
|
305
|
+
async function resolveAccessToken(args) {
|
|
306
|
+
const envMeta = readEnvMetaCredential();
|
|
307
|
+
if (args.authHost !== void 0 && (envMeta !== void 0 || readEnvVar("XANO_REFRESH_TOKEN") === void 0)) {
|
|
308
|
+
refuseUnusedOrigin(args, envMeta);
|
|
309
|
+
}
|
|
310
|
+
if (envMeta) {
|
|
311
|
+
assertHttpsOrigin(envMeta.instance_base_url, ENV_INSTANCE);
|
|
312
|
+
refuseProfileDisplacedByEnv(args, ENV_META_TOKEN);
|
|
313
|
+
noteDisplacedCredentials(args, ENV_META_TOKEN);
|
|
314
|
+
return {
|
|
315
|
+
access_token: envMeta.meta_api_token,
|
|
316
|
+
instance: envMeta.instance_base_url,
|
|
317
|
+
workspaceId: envMeta.workspace_id,
|
|
318
|
+
credentialType: "token"
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
const envRefresh = readEnvVar("XANO_REFRESH_TOKEN");
|
|
322
|
+
if (envRefresh) {
|
|
323
|
+
registerSecret(envRefresh);
|
|
324
|
+
const malformed = tokenTextProblem(envRefresh.trim());
|
|
325
|
+
if (malformed !== void 0) {
|
|
326
|
+
throw new UsageError(
|
|
327
|
+
`XANO_REFRESH_TOKEN ${malformed}, which no request can carry. Set it to the refresh token alone \u2014 one line, nothing else.`
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
refuseProfileDisplacedByEnv(args, "XANO_REFRESH_TOKEN");
|
|
331
|
+
noteDisplacedCredentials(args, "XANO_REFRESH_TOKEN");
|
|
332
|
+
const authHost = resolveAuthHost(args);
|
|
333
|
+
try {
|
|
334
|
+
assertSignInOrigin(authHost, args.authHost === void 0 ? "XANO_ORIGIN" : "--origin");
|
|
335
|
+
} catch (err) {
|
|
336
|
+
throw new UsageError(err instanceof Error ? err.message : String(err));
|
|
337
|
+
}
|
|
338
|
+
const clientId = readEnvVar("XANO_CLIENT_ID");
|
|
339
|
+
if (!clientId) {
|
|
340
|
+
const searched = oauthSearchPaths(args);
|
|
341
|
+
const stored = storedOAuthProfiles(searched);
|
|
342
|
+
throw new UsageError(
|
|
343
|
+
`XANO_REFRESH_TOKEN is set but XANO_CLIENT_ID is not. A refresh token can only be exchanged by the client that minted it` + (stored.length > 0 ? ` \u2014 copy both values from the OAuth profile it came from (${stored.join("; ")}): its "refresh_token" and "client_id" fields.` : `, and no OAuth profile is stored here to copy one from (${searched.join(", ")}). Set XANO_CLIENT_ID to the "client_id" stored beside that refresh token where \`xanosdk login\` wrote it \u2014 or run \`xanosdk login\` to sign in and store a pair.`)
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
let set;
|
|
347
|
+
try {
|
|
348
|
+
set = await refreshWithRetry(authHost, clientId, envRefresh, resolveScope(args));
|
|
349
|
+
} catch (err) {
|
|
350
|
+
if (isTransientRefreshError(err)) {
|
|
351
|
+
const answer = await describeRefreshAnswer(err);
|
|
352
|
+
const message2 = await describeRefreshFailure(err);
|
|
353
|
+
throw unansweredRefresh(new Error(
|
|
354
|
+
answer === void 0 ? `XANO_REFRESH_TOKEN exchange could not reach the authorization server (${message2}), even after one retry. This is a transient network error, not an auth problem \u2014 re-run the command. If it persists, check connectivity to ${authHost}.` : `XANO_REFRESH_TOKEN exchange failed: the authorization server answered ${answer}${retriedNote(err)}. ` + unansweredRefreshCause(err, authHost, "Minting a new refresh token")
|
|
355
|
+
), err);
|
|
356
|
+
}
|
|
357
|
+
const failure = `XANO_REFRESH_TOKEN exchange failed: ${await describeRefreshFailure(err)}`;
|
|
358
|
+
const mint = loginCommand(DEFAULT_PROFILE, { origin: authHost }, ["--force"]);
|
|
359
|
+
const refused = await refusedRefreshCredential(err);
|
|
360
|
+
const rejected = (message2) => credentialRejected(new Error(message2), {
|
|
361
|
+
profile: null,
|
|
362
|
+
credentialType: "oauth-refresh",
|
|
363
|
+
instance: null,
|
|
364
|
+
workspaceId: null,
|
|
365
|
+
signIn: null
|
|
366
|
+
});
|
|
367
|
+
if (refused === "client") {
|
|
368
|
+
throw rejected(
|
|
369
|
+
`${failure}
|
|
370
|
+
XANO_CLIENT_ID is not a client the authorization server accepts for XANO_REFRESH_TOKEN \u2014 set both from the same OAuth profile (its "client_id" and "refresh_token" fields), or unset both to use a stored profile.`
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
const message = `${failure}
|
|
374
|
+
The refresh token may be expired or already spent \u2014 refresh tokens rotate on use, so a single stored value is consumed on first exchange. Replace XANO_REFRESH_TOKEN (with the XANO_CLIENT_ID stored beside it), or unset both to use a stored profile. Mint a fresh one via \`${mint}\`.`;
|
|
375
|
+
throw refused === "token" ? rejected(message) : new Error(message);
|
|
376
|
+
}
|
|
377
|
+
const instance = decodeAudience(set.access_token);
|
|
378
|
+
if (!instance) {
|
|
379
|
+
throw new Error(
|
|
380
|
+
`Could not determine the target instance from the token minted by XANO_REFRESH_TOKEN (no readable \`aud\` claim). Mint a fresh refresh token via \`${loginCommand(DEFAULT_PROFILE, { origin: authHost }, ["--force"])}\`.`
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
assertHttpsOrigin(instance, "instance");
|
|
384
|
+
const { resolveScopedWorkspaceId } = await import("./workspace-2CLHU2LK.js");
|
|
385
|
+
const workspaceId = await resolveScopedWorkspaceId({ access_token: set.access_token, instance });
|
|
386
|
+
return { access_token: set.access_token, instance, workspaceId, credentialType: "oauth-refresh" };
|
|
387
|
+
}
|
|
388
|
+
const authFilePath = resolveAuthFilePath(args);
|
|
389
|
+
const file = readCredentialFile(authFilePath);
|
|
390
|
+
const { selection, pin } = resolveProfile(args, file, authFilePath);
|
|
391
|
+
const saved = file === null ? null : readProfile(file, selection.name, authFilePath);
|
|
392
|
+
if (!saved) {
|
|
393
|
+
throw notSignedIn(authFilePath, file, selection, args.authHost ?? envOrigin(), pin);
|
|
394
|
+
}
|
|
395
|
+
warnIfReadableByOthers(authFilePath);
|
|
396
|
+
warnIfLocalShadowsGlobal(args, authFilePath, saved, selection);
|
|
397
|
+
await warnIfUnpinnedMachineDefault(file, selection, pin, saved, authFilePath);
|
|
398
|
+
return fromStoredProfile(authFilePath, selection, saved);
|
|
399
|
+
}
|
|
400
|
+
async function resolveNamedProfile(name, args, flag = "--to-profile") {
|
|
401
|
+
try {
|
|
402
|
+
assertValidProfileName(name, flag);
|
|
403
|
+
} catch (err) {
|
|
404
|
+
throw new UsageError(err instanceof Error ? err.message : String(err));
|
|
405
|
+
}
|
|
406
|
+
const selection = { name, source: "flag", flag };
|
|
407
|
+
const authFilePath = resolveAuthFilePath(args);
|
|
408
|
+
const file = readCredentialFile(authFilePath);
|
|
409
|
+
const saved = file === null ? null : readProfile(file, name, authFilePath);
|
|
410
|
+
if (!saved) {
|
|
411
|
+
const available = file === null ? [] : profileNames(file);
|
|
412
|
+
const have = available.length === 0 ? `Nothing is signed in there.` : `Stored profiles there: ${quotedNames(available)}.`;
|
|
413
|
+
throw new ProfileNotFoundError(
|
|
414
|
+
`\`${flag} ${name}\` names no stored credential profile in ${authFilePath}. ${have} Run ${addProfileHint(name, { path: authFilePath })} to add it.`
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
warnIfReadableByOthers(authFilePath);
|
|
418
|
+
warnIfLocalShadowsGlobal(args, authFilePath, saved, selection);
|
|
419
|
+
return fromStoredProfile(authFilePath, selection, saved);
|
|
420
|
+
}
|
|
421
|
+
async function fromStoredProfile(authFilePath, selection, saved) {
|
|
422
|
+
if (saved.type === "token") {
|
|
423
|
+
assertHttpsOrigin(saved.instance_base_url, "instance_base_url");
|
|
424
|
+
return {
|
|
425
|
+
access_token: saved.meta_api_token,
|
|
426
|
+
instance: saved.instance_base_url,
|
|
427
|
+
workspaceId: saved.workspace_id,
|
|
428
|
+
credentialType: "token",
|
|
429
|
+
profile: selection
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
const instance = saved.instance;
|
|
433
|
+
assertStoredInstance(instance, authFilePath, selection);
|
|
434
|
+
if (Date.now() < saved.expires_at - EXPIRY_SKEW_MS) {
|
|
435
|
+
return {
|
|
436
|
+
access_token: saved.access_token,
|
|
437
|
+
instance,
|
|
438
|
+
workspaceId: saved.workspace_id,
|
|
439
|
+
credentialType: "oauth",
|
|
440
|
+
profile: selection
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
return refreshUnderLock(authFilePath, selection, saved);
|
|
444
|
+
}
|
|
445
|
+
function assertStoredInstance(instance, authFilePath, selection) {
|
|
446
|
+
try {
|
|
447
|
+
assertHttpsOrigin(instance, `The instance stored for profile "${selection.name}" in ${authFilePath}`);
|
|
448
|
+
} catch (err) {
|
|
449
|
+
const fix = loginCommand(selection.name, { path: authFilePath }, ["--force"]);
|
|
450
|
+
throw new StoredCredentialError(
|
|
451
|
+
`${err instanceof Error ? err.message : String(err)} Nothing was sent. Run \`${fix}\` to sign in again and replace the record.`,
|
|
452
|
+
selection,
|
|
453
|
+
instance,
|
|
454
|
+
fix,
|
|
455
|
+
{ cause: err }
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function resolveProfile(args, file, path) {
|
|
460
|
+
let pin;
|
|
461
|
+
let walked = false;
|
|
462
|
+
const readPin = () => {
|
|
463
|
+
if (!walked) {
|
|
464
|
+
walked = true;
|
|
465
|
+
pin = findProjectPointer(process.cwd());
|
|
466
|
+
}
|
|
467
|
+
return pin;
|
|
468
|
+
};
|
|
469
|
+
const selection = resolveActiveProfile({
|
|
470
|
+
flag: args.profile,
|
|
471
|
+
fileDefault: file?.default,
|
|
472
|
+
defaultIn: path === globalAuthFilePath() ? void 0 : path,
|
|
473
|
+
readPointer: () => readPin()?.profile
|
|
474
|
+
});
|
|
475
|
+
if (selection.source === "flag") {
|
|
476
|
+
let overridden;
|
|
477
|
+
try {
|
|
478
|
+
overridden = readPin();
|
|
479
|
+
} catch {
|
|
480
|
+
overridden = void 0;
|
|
481
|
+
}
|
|
482
|
+
if (overridden !== void 0 && overridden.profile !== selection.name) {
|
|
483
|
+
info(
|
|
484
|
+
`\`--profile ${selection.name}\` overrides ${overridden.path}, which pins this project to profile "${overridden.profile}".`
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
} else if (selection.source === "pointer") {
|
|
488
|
+
const env = readEnvVar(ENV_PROFILE)?.trim();
|
|
489
|
+
if (env !== void 0 && env !== selection.name && pin !== void 0) {
|
|
490
|
+
info(
|
|
491
|
+
`${pin.path} pins this project to profile "${selection.name}" \u2014 ignoring ${ENV_PROFILE}=${env}.`
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return { selection, pin };
|
|
496
|
+
}
|
|
497
|
+
async function warnIfUnpinnedMachineDefault(file, selection, pin, saved, path) {
|
|
498
|
+
if (pin !== void 0) return;
|
|
499
|
+
if (selection.source !== "file-default" && selection.source !== "implicit") return;
|
|
500
|
+
const stored = file === null ? [] : profileNames(file);
|
|
501
|
+
if (stored.length < 2) return;
|
|
502
|
+
const { projectDirFrom } = await import("./xanosdk-project-S6DXJONQ.js");
|
|
503
|
+
if (projectDirFrom(process.cwd()) === void 0) return;
|
|
504
|
+
const target = targetOf(saved);
|
|
505
|
+
credentialWarning(
|
|
506
|
+
"credential.unpinned-profile",
|
|
507
|
+
`This project has no ${POINTER_FILE}, so this run acts as ${describeProfileSelection(selection)} \u2014 ${hostLabel(target.instance)}, workspace ${target.workspaceId}. ${stored.length} profiles are stored on this machine.`,
|
|
508
|
+
`Run \`xanosdk profile use ${selection.name}${credentialFileFlag(path)}\` to pin this project to that profile, or name another with \`--profile\`.`
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
var warnedReadable = /* @__PURE__ */ new Set();
|
|
512
|
+
function warnIfReadableByOthers(path) {
|
|
513
|
+
if (process.platform === "win32" || warnedReadable.has(path)) return;
|
|
514
|
+
let mode;
|
|
515
|
+
try {
|
|
516
|
+
mode = statSync(path).mode;
|
|
517
|
+
} catch {
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
if ((mode & 63) === 0) return;
|
|
521
|
+
warnedReadable.add(path);
|
|
522
|
+
credentialWarning(
|
|
523
|
+
"credential.readable-file",
|
|
524
|
+
`${path} can be read by other users of this machine, and it holds your Xano credentials.`,
|
|
525
|
+
`Run \`chmod 600 ${shellQuote(path)}\` to make it readable by you alone.`
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
function credentialWarning(code, message, remedy) {
|
|
529
|
+
warn(message, code, remedy === void 0 ? [] : [remedy]);
|
|
530
|
+
}
|
|
531
|
+
function refuseProfileDisplacedByEnv(args, variable) {
|
|
532
|
+
if (args.profile !== void 0) {
|
|
533
|
+
const { vars } = environmentCredentialVars();
|
|
534
|
+
const authFilePath = resolveAuthFilePath(args, "read");
|
|
535
|
+
let file = null;
|
|
536
|
+
try {
|
|
537
|
+
file = readCredentialFile(authFilePath);
|
|
538
|
+
} catch {
|
|
539
|
+
}
|
|
540
|
+
const stored = file === null ? [] : profileNames(file);
|
|
541
|
+
if (!stored.includes(args.profile)) {
|
|
542
|
+
const have = stored.length === 0 ? `Nothing is signed in there.` : `Stored profiles there: ${quotedNames(stored)}.`;
|
|
543
|
+
throw new ProfileNotFoundError(
|
|
544
|
+
`\`--profile ${args.profile}\` names no stored credential profile in ${authFilePath}. ${have} Run ${addProfileHint(args.profile, { path: authFilePath })} to add it \u2014 and \`unset ${vars.join(" ")}\` to act as it, since ${variable} in this environment outranks the credential file.`
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
throw new UsageError(
|
|
548
|
+
`\`--profile ${args.profile}\` selects a stored credential, but ${variable} is set in this environment and outranks the credential file \u2014 there is no profile for it to select. Run \`unset ${vars.join(" ")}\` to act as profile "${args.profile}", or drop \`--profile\` to use the environment credential.`
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
function storedOAuthProfiles(paths) {
|
|
553
|
+
const found = [];
|
|
554
|
+
for (const path of [...new Set(paths)]) {
|
|
555
|
+
try {
|
|
556
|
+
const file = readCredentialFile(path);
|
|
557
|
+
if (file === null) continue;
|
|
558
|
+
for (const name of profileNames(file)) {
|
|
559
|
+
if (file.profiles[name]?.type === "oauth") found.push(`profile "${name}" in ${path}`);
|
|
560
|
+
}
|
|
561
|
+
} catch {
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return found;
|
|
565
|
+
}
|
|
566
|
+
function oauthSearchPaths(args) {
|
|
567
|
+
let resolved;
|
|
568
|
+
try {
|
|
569
|
+
resolved = resolveAuthFilePath(args);
|
|
570
|
+
} catch {
|
|
571
|
+
}
|
|
572
|
+
return [.../* @__PURE__ */ new Set([...resolved !== void 0 ? [resolved] : [], globalAuthFilePath(), localAuthFilePath()])];
|
|
573
|
+
}
|
|
574
|
+
var NotSignedInError = class extends Error {
|
|
575
|
+
name = "NotSignedInError";
|
|
576
|
+
/**
|
|
577
|
+
* The profile that was asked for by NAME and is not stored — set when other
|
|
578
|
+
* profiles are, or when a flag, `$XANO_PROFILE` or a pin named it, so the
|
|
579
|
+
* absence is a wrong name rather than a machine nobody has signed in on
|
|
580
|
+
* without choosing anything. `status` reads it to refuse rather than answer
|
|
581
|
+
* "not signed in" about a profile someone (or a pointer) chose.
|
|
582
|
+
*/
|
|
583
|
+
missingProfile;
|
|
584
|
+
/**
|
|
585
|
+
* The profiles the file DOES hold — empty on a machine nobody signed in on.
|
|
586
|
+
* `status` reads it to name `profile set-default` rather than `login` when
|
|
587
|
+
* only the default is missing.
|
|
588
|
+
*/
|
|
589
|
+
storedProfiles;
|
|
590
|
+
constructor(message, missingProfile, storedProfiles = []) {
|
|
591
|
+
super(message);
|
|
592
|
+
if (missingProfile !== void 0) this.missingProfile = missingProfile;
|
|
593
|
+
this.storedProfiles = storedProfiles;
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
var ProfileNotFoundError = class extends NotSignedInError {
|
|
597
|
+
name = "ProfileNotFoundError";
|
|
598
|
+
exitCode = EXIT_SOURCE_UNRESOLVABLE;
|
|
599
|
+
};
|
|
600
|
+
var StoredCredentialError = class extends Error {
|
|
601
|
+
constructor(message, profile, instance, fix, options) {
|
|
602
|
+
super(message, options);
|
|
603
|
+
this.profile = profile;
|
|
604
|
+
this.instance = instance;
|
|
605
|
+
this.fix = fix;
|
|
606
|
+
}
|
|
607
|
+
profile;
|
|
608
|
+
instance;
|
|
609
|
+
fix;
|
|
610
|
+
name = "StoredCredentialError";
|
|
611
|
+
};
|
|
612
|
+
function credentialRejected(err, details) {
|
|
613
|
+
return Object.assign(err, { code: "SDK_CREDENTIAL_REJECTED", details });
|
|
614
|
+
}
|
|
615
|
+
function recordedTargetFor(pin, name) {
|
|
616
|
+
if (pin === void 0) return {};
|
|
617
|
+
const keyed = Object.entries(readEphemeralState(dirname(pin.path)).environments).filter(
|
|
618
|
+
([key]) => key.startsWith(`${name}/`) && key.split("/").length >= 3
|
|
619
|
+
);
|
|
620
|
+
const targets = new Map(
|
|
621
|
+
keyed.map(([key, record]) => {
|
|
622
|
+
const instance = record.instance ?? `https://${key.split("/").slice(1, -1).join("/")}`;
|
|
623
|
+
const workspaceId = key.slice(key.lastIndexOf("/") + 1);
|
|
624
|
+
return [`${instance} ${workspaceId}`, { instance, workspaceId }];
|
|
625
|
+
})
|
|
626
|
+
);
|
|
627
|
+
return targets.size === 1 ? [...targets.values()][0] : {};
|
|
628
|
+
}
|
|
629
|
+
function notSignedIn(path, file, selection, origin, pin) {
|
|
630
|
+
const available = file === null ? [] : profileNames(file);
|
|
631
|
+
const target = {
|
|
632
|
+
path,
|
|
633
|
+
...origin !== void 0 ? { origin } : {},
|
|
634
|
+
...selection.source === "pointer" ? recordedTargetFor(pin, selection.name) : {}
|
|
635
|
+
};
|
|
636
|
+
const named = selection.source === "flag" || selection.source === "env" || selection.source === "pointer";
|
|
637
|
+
if (available.length === 0 && named) {
|
|
638
|
+
return new ProfileNotFoundError(
|
|
639
|
+
`No credential profile "${selection.name}" (${profileSourceLabel(selection.source)}) \u2014 no profile is stored at ${path}.
|
|
640
|
+
Run ${addProfileHint(selection.name, target)} to add it.`,
|
|
641
|
+
selection,
|
|
642
|
+
available
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
if (available.length === 0) {
|
|
646
|
+
return new NotSignedInError(
|
|
647
|
+
`Not signed in (no credential at ${path}). Run \`${loginCommand(DEFAULT_PROFILE, target)}\` to sign in, or store a meta API token with \`xanosdk profile add <name>${credentialFileFlag(path)} --instance <url> --workspace-id <id>\`. For CI, set XANO_INSTANCE_URL, XANO_WORKSPACE_ID and XANO_META_TOKEN together.`
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
const have = `Stored profiles: ${quotedNames(available)}.`;
|
|
651
|
+
const shared = shadowedInShared(path, selection.name);
|
|
652
|
+
if (shared !== void 0) {
|
|
653
|
+
return new ProfileNotFoundError(
|
|
654
|
+
`Profile "${selection.name}" (${profileSourceLabel(selection.source)}) is stored in this machine's shared credential file (${shared}), but this project's ${path} is read instead and does not hold it. ${have}
|
|
655
|
+
Use the shared one with \`--config ${shellQuote(shared)}\`, remove ${path} so commands here fall back to it, or add the profile here: ${addProfileHint(selection.name, target)}.`,
|
|
656
|
+
selection,
|
|
657
|
+
available
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
if (selection.source === "pointer") {
|
|
661
|
+
const near2 = suggest(selection.name, available);
|
|
662
|
+
const err2 = new ProfileNotFoundError(
|
|
663
|
+
`This project's xano.profile.json names profile "${selection.name}", which is not signed in on this machine (${path}). ${have}` + (near2 === void 0 ? "" : ` Did you mean "${safeText(near2)}"? Run \`xanosdk profile use ${shellQuote(near2)}${credentialFileFlag(path)}\` to pin it.`) + `
|
|
664
|
+
Run ${addProfileHint(selection.name, target)} to sign in as it, or \`xanosdk profile use <name>${credentialFileFlag(path)}\` to point this project at one you have.`,
|
|
665
|
+
selection,
|
|
666
|
+
available
|
|
667
|
+
);
|
|
668
|
+
if (near2 !== void 0) Object.defineProperty(err2, "suggestion", { value: near2, enumerable: true });
|
|
669
|
+
return err2;
|
|
670
|
+
}
|
|
671
|
+
const unchosen = selection.source === "file-default" || selection.source === "implicit";
|
|
672
|
+
if (unchosen) {
|
|
673
|
+
const one = available.length === 1;
|
|
674
|
+
return new ProfileNotFoundError(
|
|
675
|
+
`No default profile to use: ${path} holds no profile "${selection.name}". ${have} Run \`xanosdk profile set-default ${one ? shellQuote(available[0]) : "<name>"}${credentialFileFlag(path)}\` to make ${one ? "it" : "one of them"} the default, or ${addProfileHint(selection.name, target)} to add "${selection.name}".`,
|
|
676
|
+
selection,
|
|
677
|
+
available
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
const near = suggest(selection.name, available);
|
|
681
|
+
const retype = near === void 0 ? "" : ` Did you mean "${safeText(near)}"? ${selection.source === "env" ? `Set XANO_PROFILE=${shellQuote(near)}` : `Pass \`--profile ${shellQuote(near)}\``} instead.`;
|
|
682
|
+
const err = new ProfileNotFoundError(
|
|
683
|
+
`No credential profile "${selection.name}" in ${path} (${profileSourceLabel(selection.source)}). ${have}${retype} Run ${addProfileHint(selection.name, target)} to add it.`,
|
|
684
|
+
selection,
|
|
685
|
+
available
|
|
686
|
+
);
|
|
687
|
+
if (near !== void 0) Object.defineProperty(err, "suggestion", { value: near, enumerable: true });
|
|
688
|
+
return err;
|
|
689
|
+
}
|
|
690
|
+
function shadowedInShared(path, name) {
|
|
691
|
+
if (resolvePath(path) !== localAuthFilePath()) return void 0;
|
|
692
|
+
const shared = globalAuthFilePath();
|
|
693
|
+
try {
|
|
694
|
+
const file = readCredentialFile(shared);
|
|
695
|
+
return file !== null && Object.prototype.hasOwnProperty.call(file.profiles, name) ? shared : void 0;
|
|
696
|
+
} catch {
|
|
697
|
+
return void 0;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
function targetOf(credential) {
|
|
701
|
+
return credential.type === "token" ? { instance: credential.instance_base_url, workspaceId: credential.workspace_id } : { instance: credential.instance, workspaceId: credential.workspace_id };
|
|
702
|
+
}
|
|
703
|
+
function warnIfLocalShadowsGlobal(args, resolved, saved, selection) {
|
|
704
|
+
const isDefaultResolution = args.authFile === void 0 && readPathEnvVar("XANO_CONFIG") === void 0 && !args.local;
|
|
705
|
+
if (!isDefaultResolution || resolved !== localAuthFilePath()) return;
|
|
706
|
+
const globalPath = globalAuthFilePath();
|
|
707
|
+
if (globalPath === resolved) return;
|
|
708
|
+
let globalSaved = null;
|
|
709
|
+
try {
|
|
710
|
+
globalSaved = readCredential(globalPath, selection.name);
|
|
711
|
+
} catch {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
if (!globalSaved) return;
|
|
715
|
+
const here = targetOf(saved);
|
|
716
|
+
const there = targetOf(globalSaved);
|
|
717
|
+
if (here.instance === there.instance && here.workspaceId === there.workspaceId) return;
|
|
718
|
+
credentialWarning(
|
|
719
|
+
"credential.shadowed-global",
|
|
720
|
+
`Using project-local ${resolved}, ${describeProfileSelection(selection)} (${hostLabel(here.instance)}, workspace ${here.workspaceId}), but a global credential for ${hostLabel(there.instance)}, workspace ${there.workspaceId} also exists under the same profile name \u2014 the local one wins. Remove ./.xano/auth.json (or pass --config) to use the global credential instead.`
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
async function refreshUnderLock(authFilePath, selection, saved) {
|
|
724
|
+
const profile = selection.name;
|
|
725
|
+
return withCredentialLock(authFilePath, async (file) => {
|
|
726
|
+
const current = rereadOAuthProfile(file, profile, authFilePath, saved);
|
|
727
|
+
const instance = current.instance;
|
|
728
|
+
const workspaceId = current.workspace_id;
|
|
729
|
+
if (Date.now() < current.expires_at - EXPIRY_SKEW_MS) {
|
|
730
|
+
return {
|
|
731
|
+
access_token: current.access_token,
|
|
732
|
+
instance,
|
|
733
|
+
workspaceId,
|
|
734
|
+
credentialType: "oauth",
|
|
735
|
+
profile: selection
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
const target = { path: authFilePath, origin: current.auth_host };
|
|
739
|
+
const login = (force = false) => loginCommand(profile, target, force ? ["--force"] : []);
|
|
740
|
+
const unusable = (message, fix, cause) => new StoredCredentialError(message, selection, instance, fix, { cause });
|
|
741
|
+
if (!current.refresh_token) {
|
|
742
|
+
throw unusable(
|
|
743
|
+
`No usable access token for ${instance} and no refresh token is cached. Run \`${login()}\` again.`,
|
|
744
|
+
login()
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
try {
|
|
748
|
+
assertStoredAuthHost(current.auth_host, profile, authFilePath);
|
|
749
|
+
} catch (err) {
|
|
750
|
+
const fix = loginCommand(profile, { path: authFilePath }, ["--force"]);
|
|
751
|
+
throw unusable(err instanceof Error ? err.message : String(err), fix, err);
|
|
752
|
+
}
|
|
753
|
+
detail(`Refreshing access token for ${hostLabel(instance)}\u2026`);
|
|
754
|
+
let set;
|
|
755
|
+
try {
|
|
756
|
+
set = await refreshWithRetry(current.auth_host, current.client_id, current.refresh_token, current.scope);
|
|
757
|
+
} catch (err) {
|
|
758
|
+
const message = await describeRefreshFailure(err);
|
|
759
|
+
const refused = await refusedRefreshCredential(err);
|
|
760
|
+
if (refused === "token") {
|
|
761
|
+
const removedFile = writeOrRemoveCredentialFile(authFilePath, dropProfile(file, profile));
|
|
762
|
+
const relogin = login();
|
|
763
|
+
throw credentialRejected(
|
|
764
|
+
unusable(
|
|
765
|
+
`Session for profile "${profile}" (${instance}) has expired or was revoked (the refresh token was rejected), so the profile was removed from ${authFilePath}${removedFile ? " \u2014 it was the last one, so the file went with it" : ""}. Run \`${relogin}\` to sign in again.`,
|
|
766
|
+
relogin
|
|
767
|
+
),
|
|
768
|
+
{ profile, credentialType: "oauth", instance, workspaceId, signIn: relogin }
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
if (isTransientRefreshError(err)) {
|
|
772
|
+
const answer = await describeRefreshAnswer(err);
|
|
773
|
+
throw unansweredRefresh(unusable(
|
|
774
|
+
answer === void 0 ? `Token refresh for ${instance} could not reach the authorization server (${message}), even after one retry. This is a transient network error, not an auth problem \u2014 re-run the command. If it persists, check connectivity to ${current.auth_host}.` : `Token refresh for ${instance} failed: the authorization server answered ${answer}${retriedNote(err)}. ` + unansweredRefreshCause(err, current.auth_host, "Signing in again"),
|
|
775
|
+
null,
|
|
776
|
+
err
|
|
777
|
+
), err);
|
|
778
|
+
}
|
|
779
|
+
const failed = unusable(
|
|
780
|
+
`Token refresh failed for ${instance}: ${message}
|
|
781
|
+
Run \`${login()}\` to sign in again.`,
|
|
782
|
+
login(),
|
|
783
|
+
err
|
|
784
|
+
);
|
|
785
|
+
throw refused === "client" ? credentialRejected(failed, { profile, credentialType: "oauth", instance, workspaceId, signIn: login() }) : failed;
|
|
786
|
+
}
|
|
787
|
+
const stamped = stampExpiry(set);
|
|
788
|
+
file.profiles[profile] = {
|
|
789
|
+
...current,
|
|
790
|
+
access_token: stamped.access_token,
|
|
791
|
+
refresh_token: stamped.refresh_token ?? current.refresh_token,
|
|
792
|
+
expires_at: stamped.expires_at,
|
|
793
|
+
scope: stamped.scope ?? current.scope
|
|
794
|
+
};
|
|
795
|
+
writeCredentialFile(authFilePath, file);
|
|
796
|
+
return {
|
|
797
|
+
access_token: stamped.access_token,
|
|
798
|
+
instance,
|
|
799
|
+
workspaceId,
|
|
800
|
+
credentialType: "oauth",
|
|
801
|
+
profile: selection
|
|
802
|
+
};
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
function assertStoredAuthHost(authHost, profile, authFilePath) {
|
|
806
|
+
try {
|
|
807
|
+
assertHttpsOrigin(
|
|
808
|
+
authHost,
|
|
809
|
+
`The sign-in server (\`auth_host\`) stored for profile "${profile}"${authFilePath === void 0 ? "" : ` in ${authFilePath}`}`
|
|
810
|
+
);
|
|
811
|
+
} catch (err) {
|
|
812
|
+
throw new Error(
|
|
813
|
+
`${err instanceof Error ? err.message : String(err)} The refresh token was not sent. Run \`${loginCommand(profile, { path: authFilePath }, ["--force"])}\` to sign in again and replace the record.`,
|
|
814
|
+
{ cause: err }
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
function rereadOAuthProfile(file, profile, path, saved) {
|
|
819
|
+
let current;
|
|
820
|
+
try {
|
|
821
|
+
current = readProfile(file, profile, path);
|
|
822
|
+
} catch {
|
|
823
|
+
current = null;
|
|
824
|
+
}
|
|
825
|
+
if (current === null) {
|
|
826
|
+
throw new Error(
|
|
827
|
+
`Profile "${profile}" was removed from ${path} while its token was being refreshed. Nothing was written. Run ${loginHint(profile, { path, origin: saved.auth_host })} to sign in again.`
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
if (current.type !== "oauth") {
|
|
831
|
+
throw new Error(
|
|
832
|
+
`Profile "${profile}" in ${path} was replaced with a hand-authored meta API token while its OAuth token was being refreshed. Nothing was written \u2014 re-run the command to use it.`
|
|
833
|
+
);
|
|
834
|
+
}
|
|
835
|
+
if (current.instance !== saved.instance || current.workspace_id !== saved.workspace_id) {
|
|
836
|
+
throw new Error(
|
|
837
|
+
`Profile "${profile}" in ${path} was repointed from ${hostLabel(saved.instance)} workspace ${saved.workspace_id} to ${hostLabel(current.instance)} workspace ${current.workspace_id} while its token was being refreshed. Nothing was written \u2014 re-run the command.`
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
return current;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
export {
|
|
844
|
+
isTransientRefreshError,
|
|
845
|
+
refusedRefreshCredential,
|
|
846
|
+
describeRefreshFailure,
|
|
847
|
+
describeRefreshAnswer,
|
|
848
|
+
ENV_INSTANCE,
|
|
849
|
+
ENV_WORKSPACE,
|
|
850
|
+
ENV_META_TOKEN,
|
|
851
|
+
readEnvMetaCredential,
|
|
852
|
+
envMetaCredentialVarsSet,
|
|
853
|
+
environmentCredentialVars,
|
|
854
|
+
getAccessToken,
|
|
855
|
+
resolveNamedProfile,
|
|
856
|
+
warnIfReadableByOthers,
|
|
857
|
+
credentialWarning,
|
|
858
|
+
NotSignedInError,
|
|
859
|
+
ProfileNotFoundError,
|
|
860
|
+
StoredCredentialError,
|
|
861
|
+
credentialRejected,
|
|
862
|
+
notSignedIn,
|
|
863
|
+
assertStoredAuthHost
|
|
864
|
+
};
|
|
865
|
+
//# sourceMappingURL=chunk-ET4Y4XCB.js.map
|