@metabase/cli 0.2.2 → 0.3.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/README.md +4 -1902
- package/dist/add-collection-B3Ty8SzB.mjs +36 -0
- package/dist/alert-DT-ee7yf.mjs +23 -0
- package/dist/{alerts-CRGMX4eB.mjs → alerts-Bf2RH_p_.mjs} +11 -17
- package/dist/{append-lL0IaI6U.mjs → append-DFzQRPMd.mjs} +7 -12
- package/dist/{archive-DihHU042.mjs → archive-4tmm946K.mjs} +8 -17
- package/dist/{archive-C9mJGN6J.mjs → archive-B6eXiyER.mjs} +7 -13
- package/dist/{archive-D3DErepm.mjs → archive-BxNPHxOY.mjs} +7 -13
- package/dist/{archive-DyPsHSFb.mjs → archive-ByvA49Kz.mjs} +8 -13
- package/dist/{archive-ExcEma7q.mjs → archive-C7w49Grr.mjs} +7 -16
- package/dist/{archive-Baz4OVDd.mjs → archive-Cd29QC0c.mjs} +7 -13
- package/dist/{archive-CUGRnyRV.mjs → archive-ChORH5JH.mjs} +7 -13
- package/dist/{archive-hKPQXgXa.mjs → archive-CwAdlv63.mjs} +7 -12
- package/dist/{archive-D8YrImIU.mjs → archive-Dr9Xnx_Z.mjs} +7 -15
- package/dist/{archive-BUFc1me2.mjs → archive-gid9Y09v.mjs} +8 -17
- package/dist/{archive-3rLXY0nS.mjs → archive-lQqs13Uz.mjs} +7 -13
- package/dist/auth-Dltxua89.mjs +19 -0
- package/dist/{body-DXJ2v3GY.mjs → body-Cur4NJt9.mjs} +5 -8
- package/dist/{body-flags-Cbv-Ba6W.mjs → body-flags-AqKpN01Y.mjs} +1 -2
- package/dist/{branches-ByCzTuiv.mjs → branches-DchlyU0i.mjs} +7 -13
- package/dist/{cancel-DvehNbDD.mjs → cancel-BMQa5R1Z.mjs} +5 -12
- package/dist/{cancel-task-BM8ADd3Y.mjs → cancel-task-C5CU1pxU.mjs} +6 -10
- package/dist/card-CHI2bmds.mjs +24 -0
- package/dist/{card-BFRRyTGs.mjs → card-DZxRmver.mjs} +21 -48
- package/dist/card-zyUkr2nS.mjs +44 -0
- package/dist/cards-SccWvRQD.mjs +34 -0
- package/dist/cli.mjs +664 -85
- package/dist/client-BqhzKdLM.mjs +2194 -0
- package/dist/collection-CGoVLvcD.mjs +58 -0
- package/dist/collection-CY0AB99E.mjs +20 -0
- package/dist/{collection-BrrjbPLN.mjs → collection-CfulNRBG.mjs} +16 -61
- package/dist/{collection-namespace-8i_CvWsg.mjs → collection-namespace-GwydWBF3.mjs} +3 -5
- package/dist/{create-D6bXJlBS.mjs → create-BNQ_DytP.mjs} +8 -15
- package/dist/{create-CtIOvInN.mjs → create-BOLwWt8Q.mjs} +9 -17
- package/dist/{create--_4GZUNY.mjs → create-Beh-2uoN.mjs} +8 -16
- package/dist/{create-BnNRvoyz.mjs → create-C79vErX0.mjs} +9 -20
- package/dist/{create-D57tRDrg.mjs → create-CAQV2g6V.mjs} +9 -17
- package/dist/{create-CHK9cJcK.mjs → create-CAWytBE5.mjs} +9 -17
- package/dist/{create-BynNiG1N.mjs → create-CCh_LyW9.mjs} +8 -15
- package/dist/{create-Cy57naL0.mjs → create-CD008jdE.mjs} +13 -28
- package/dist/{create-DOpa2TmH.mjs → create-CHQx7jq4.mjs} +9 -17
- package/dist/{create-COI80Veo.mjs → create-DF4QtgDL.mjs} +8 -16
- package/dist/{create-yK1-fuX5.mjs → create-DJmXXQoq.mjs} +10 -18
- package/dist/{create-1O1UiTVt.mjs → create-DV-Ln5Mo.mjs} +8 -15
- package/dist/create-branch-CYo6jZth.mjs +35 -0
- package/dist/{create-t7z8Eb4T.mjs → create-i14Wv3Tj.mjs} +8 -15
- package/dist/{create-qzjhJFP8.mjs → create-tQbnuz-I.mjs} +8 -15
- package/dist/{create-DAj8pyfQ.mjs → create-zeveFdnd.mjs} +6 -11
- package/dist/{cron-93wjhtrP.mjs → cron-LKRffEC-.mjs} +2 -4
- package/dist/{csv-yoFA1hhv.mjs → csv-B2Jgb1GM.mjs} +7 -19
- package/dist/{current-task-D8Q1uFmk.mjs → current-task-MpBFGttd.mjs} +7 -12
- package/dist/{dashboard-BSCXTX4H.mjs → dashboard-BCpSq_G-.mjs} +9 -60
- package/dist/dashboard-BHJBoaG7.mjs +33 -0
- package/dist/dashboard-CsIFFpzK.mjs +58 -0
- package/dist/database-B19qlLKZ.mjs +38 -0
- package/dist/database-C8G6ZKG0.mjs +26 -0
- package/dist/db-DsfojyeH.mjs +24 -0
- package/dist/{delete-B8dui6O6.mjs → delete-B8e01xAG.mjs} +6 -11
- package/dist/{delete-CA7IjA5J.mjs → delete-BApOjQvl.mjs} +6 -11
- package/dist/{delete-Dcu3iDkg.mjs → delete-Ck0q4Dzp.mjs} +6 -11
- package/dist/{delete-BwPgIWV8.mjs → delete-DFmX7jTp.mjs} +6 -11
- package/dist/{delete-CawUDFud.mjs → delete-Ob06PPie.mjs} +6 -11
- package/dist/{delete-runtime-00-R9iJm.mjs → delete-runtime-D74s6vhu.mjs} +6 -13
- package/dist/{delete-table-DS0b3i0k.mjs → delete-table-DuyhGrvA.mjs} +6 -11
- package/dist/{dependencies-BQVZylqV.mjs → dependencies-Bj3QrGIm.mjs} +10 -13
- package/dist/dirty-DNYoM6Bp.mjs +31 -0
- package/dist/document-BbskZPTT.mjs +19 -0
- package/dist/{document-C7IR6T8c.mjs → document-Cd2mmqCp.mjs} +5 -33
- package/dist/document-D6OybtP2.mjs +29 -0
- package/dist/{eid-DcCAs-RP.mjs → eid-WTZmDdsr.mjs} +12 -54
- package/dist/eid-translation-zEHtr5Oc.mjs +35 -0
- package/dist/{embedding-B0x9CPkU.mjs → embedding-i-KqpefC.mjs} +2 -4
- package/dist/events-Bn7jh5lP.mjs +39 -0
- package/dist/export-BjfoZRDJ.mjs +66 -0
- package/dist/field-BPsNa-TO.mjs +80 -0
- package/dist/{field-RYBTW2KS.mjs → field-Cr2DPUG9.mjs} +2 -81
- package/dist/field-Zau6Hc6X.mjs +18 -0
- package/dist/fields-CBBa-Prp.mjs +34 -0
- package/dist/{get-vGqyjGSW.mjs → get-00lyLv6R.mjs} +7 -11
- package/dist/{get-Cvkt6GcQ.mjs → get-B7sMgsFs.mjs} +7 -11
- package/dist/get-B_xdF1kq.mjs +31 -0
- package/dist/{get-DhS4y0K9.mjs → get-ByBOq30r.mjs} +7 -11
- package/dist/get-Bz99dAxK.mjs +35 -0
- package/dist/get-C2-Q3iQ5.mjs +31 -0
- package/dist/get-CDJFVvhj.mjs +35 -0
- package/dist/get-CDMGbgrh.mjs +31 -0
- package/dist/get-CnbUCzDM.mjs +31 -0
- package/dist/{get-CJYv3CfV.mjs → get-CvI--9S_.mjs} +16 -12
- package/dist/get-DRvsATp-.mjs +31 -0
- package/dist/{get-Db8YNxId.mjs → get-DY03Azx9.mjs} +6 -11
- package/dist/{get-4rA8pbRu.mjs → get-DYO1kywc.mjs} +7 -13
- package/dist/{get-DZRB5S37.mjs → get-D_h-G9bn.mjs} +7 -11
- package/dist/get-DdsoHaKH.mjs +31 -0
- package/dist/{get-DQ0pb4tT.mjs → get-DkWO0EI0.mjs} +7 -11
- package/dist/{get-DXiL39gi.mjs → get-Dmj9Ygz1.mjs} +7 -17
- package/dist/{get-CvXOGyFj.mjs → get-DmpB6J9g.mjs} +7 -12
- package/dist/{get-B2vvnMpl.mjs → get-Dn9ZiSZr.mjs} +8 -16
- package/dist/{get-run-BF5ZBE8o.mjs → get-run-Cnux9ln0.mjs} +7 -11
- package/dist/git-sync-BDnxPrqU.mjs +104 -0
- package/dist/git-sync-DxD_ng48.mjs +136 -0
- package/dist/git-sync-MQQYRYLg.mjs +28 -0
- package/dist/{group-DfTvzGz-.mjs → group-DBM87IgC.mjs} +2 -4
- package/dist/has-remote-changes-C684Redh.mjs +35 -0
- package/dist/import-Rmmttboo.mjs +56 -0
- package/dist/{input-BpXlmJ5J.mjs → input-DH9i67x_.mjs} +6 -11
- package/dist/{is-dirty-4kIyD4oP.mjs → is-dirty-DYeJYhBz.mjs} +4 -8
- package/dist/{items-BXH0f1r6.mjs → items-CQlPXBXE.mjs} +13 -29
- package/dist/key-BEhqIzIQ.mjs +10 -0
- package/dist/{library-BFZYsBcz.mjs → library-Bsm5KsFF.mjs} +6 -9
- package/dist/library-ClLgrAXy.mjs +19 -0
- package/dist/library-DfYAT2Ep.mjs +21 -0
- package/dist/{list-By1yYVGq.mjs → list-B4hJuMhA.mjs} +11 -27
- package/dist/{list-oRyXsJXs.mjs → list-B8nAGwP4.mjs} +10 -12
- package/dist/list-BOET6zhP.mjs +36 -0
- package/dist/list-BP3MPq-M.mjs +36 -0
- package/dist/list-BpFp9Wre.mjs +28 -0
- package/dist/list-BtkWNtvY.mjs +34 -0
- package/dist/list-BtmsNOEn.mjs +28 -0
- package/dist/list-BzVTHOoH.mjs +28 -0
- package/dist/list-C5Zs8nrb.mjs +28 -0
- package/dist/list-CKK-s3Ty.mjs +28 -0
- package/dist/{list-SiSfX4wl.mjs → list-CMpoc2TN.mjs} +10 -13
- package/dist/list-CNUiF8Z7.mjs +28 -0
- package/dist/list-CQDprvW0.mjs +39 -0
- package/dist/{list-w61Uovt2.mjs → list-CQwOgIlj.mjs} +10 -24
- package/dist/list-DE9FM957.mjs +28 -0
- package/dist/{list-CG3ec9BZ.mjs → list-DF2rvoO1.mjs} +22 -14
- package/dist/list-DMKDsBRd.mjs +38 -0
- package/dist/{list-Bar8uQRC.mjs → list-UhpKG6_m.mjs} +15 -15
- package/dist/{login-zUCMDLC8.mjs → login-CGHeSjlP.mjs} +47 -52
- package/dist/{logout-BFh7QHx6.mjs → logout-DAxOlbv4.mjs} +7 -12
- package/dist/measure-4P0bOlZ3.mjs +29 -0
- package/dist/measure-BsYv0p26.mjs +22 -0
- package/dist/{measure-DH3ow2ko.mjs → measure-CtfjqJFP.mjs} +3 -30
- package/dist/network-error-CEb9ymDW.mjs +423 -0
- package/dist/{notification-BR5wehqg.mjs → notification-DaA4bBHW.mjs} +3 -66
- package/dist/notification-Fcq1fIPw.mjs +67 -0
- package/dist/{parameter-hCQ80jnc.mjs → parameter-DUKR8NXo.mjs} +2 -11
- package/dist/{parameter-values-BYDFzxNY.mjs → parameter-values-CJTdqd8c.mjs} +17 -11
- package/dist/{parse-enum-D1zTYr_i.mjs → parse-enum-D0Jfm_Bz.mjs} +2 -4
- package/dist/{parse-id-waEVK-uR.mjs → parse-id-C_jmKFaa.mjs} +2 -4
- package/dist/{parse-ref-C3DUXwci.mjs → parse-ref-ibKVB0J4.mjs} +3 -5
- package/dist/{path-Bvs9IR4k.mjs → path-B5gHvrYL.mjs} +8 -9
- package/dist/{poll-rqLkEJVP.mjs → poll-75SvT7Zv.mjs} +11 -15
- package/dist/predicates-Bkm2IoeX.mjs +170 -0
- package/dist/preflight-YpPQo-sa.mjs +29 -0
- package/dist/{process-BxAUv3Wx.mjs → process-DBOOrmET.mjs} +4 -6
- package/dist/{publish-C1y_vGGw.mjs → publish-DijrxaCW.mjs} +29 -24
- package/dist/{pulse-C8q469KD.mjs → pulse-BmsDenXm.mjs} +3 -56
- package/dist/pulse-DhG6I9mI.mjs +57 -0
- package/dist/{query-B9LlGOZI.mjs → query-BbqECzmF.mjs} +20 -44
- package/dist/{query-DpVWKW-y.mjs → query-Dc__-KJH.mjs} +13 -24
- package/dist/{query-result-Bvh89K4f.mjs → query-result-DBDwk8TS.mjs} +4 -8
- package/dist/remove-collection-BOnxYvhj.mjs +36 -0
- package/dist/{render-rgZBe3rO.mjs → render-CI93iP0I.mjs} +9 -11
- package/dist/{replace-sHtPBNnA.mjs → replace-Cq4CxVa-.mjs} +7 -12
- package/dist/rescan-values-Dr_j416g.mjs +31 -0
- package/dist/revision-message-flag-8TCHYJV6.mjs +8 -0
- package/dist/run-C3DkS6NP.mjs +82 -0
- package/dist/{run-Ce_gPVcg.mjs → run-DdGJ544X.mjs} +8 -18
- package/dist/runs-CUNWiidL.mjs +38 -0
- package/dist/runtime-DiKyBxOw.mjs +1007 -0
- package/dist/{schema-tables-D91DWM5l.mjs → schema-tables-CV386fnC.mjs} +10 -14
- package/dist/{schemas-OVYRgvz9.mjs → schemas-DM-UqZBQ.mjs} +8 -12
- package/dist/search-DFBwUc6d.mjs +44 -0
- package/dist/{search-msFNbxU6.mjs → search-DmGScXs8.mjs} +14 -73
- package/dist/segment-BzUGM2Fr.mjs +22 -0
- package/dist/segment-C_gl5ag6.mjs +29 -0
- package/dist/{segment-cwIOOF0v.mjs → segment-OsrbUDzw.mjs} +3 -30
- package/dist/{selectors-Bsyhe1zP.mjs → selectors-DGDn0Hto.mjs} +4 -6
- package/dist/{send-BeFpVrwD.mjs → send-CVxxEpDB.mjs} +5 -16
- package/dist/{set-jRnCLhvc.mjs → set-DFolTjbd.mjs} +10 -20
- package/dist/{set-active-CFWtIWzX.mjs → set-active-BD8L1lPX.mjs} +7 -18
- package/dist/setting-CwRYgHYN.mjs +35 -0
- package/dist/setting-DTiLCW8g.mjs +22 -0
- package/dist/setting-DyhaeICs.mjs +17 -0
- package/dist/setup-BbDQN8fe.mjs +44 -0
- package/dist/setup-CO7QV-ao.mjs +21 -0
- package/dist/signal-CMd0EFUa.mjs +16 -0
- package/dist/{skills-CxqkjkdQ.mjs → skills--vK6J-e4.mjs} +4 -6
- package/dist/{skills-DlFbbaoS.mjs → skills-DTCrMcix.mjs} +13 -19
- package/dist/{snippet-1xYckIwc.mjs → snippet-CyKAgIZl.mjs} +3 -32
- package/dist/snippet-DRwKb2x7.mjs +19 -0
- package/dist/snippet-oJLaYW9V.mjs +29 -0
- package/dist/stash-D0S4JmAz.mjs +61 -0
- package/dist/{status-DCIOvsc6.mjs → status-BhswxJL1.mjs} +23 -23
- package/dist/{status-BMEdl-_G.mjs → status-hL1am-HV.mjs} +6 -8
- package/dist/{subscription-BOOBR5Ir.mjs → subscription-_d5fB45F.mjs} +7 -10
- package/dist/{subscriptions-C_1AQpZF.mjs → subscriptions-s4TF6Ax3.mjs} +11 -16
- package/dist/{summary-D1fKnwE3.mjs → summary-BytbDz6e.mjs} +1 -2
- package/dist/summary-CsPvcUwW.mjs +31 -0
- package/dist/sync-schema-DaZ_MV-u.mjs +35 -0
- package/dist/sync-task-BACcrs0i.mjs +37 -0
- package/dist/{table-fDvuvqoU.mjs → table-CeeTJgQb.mjs} +4 -38
- package/dist/table-CsIJNPFf.mjs +37 -0
- package/dist/table-DYoC1kPn.mjs +18 -0
- package/dist/{timeline-BNwnJ3g9.mjs → timeline-CCSU2qOS.mjs} +2 -66
- package/dist/timeline-event-CNQdCTDg.mjs +19 -0
- package/dist/timeline-uDCmwGFT.mjs +66 -0
- package/dist/timeline-xlDbEKWg.mjs +21 -0
- package/dist/transform-Bs0EWijQ.mjs +28 -0
- package/dist/{transform-BkSkCvpx.mjs → transform-D3QX0jxA.mjs} +28 -74
- package/dist/transform-DoTyyXAu.mjs +74 -0
- package/dist/transform-job-50GZHhKH.mjs +37 -0
- package/dist/transform-job-BcLChRup.mjs +22 -0
- package/dist/{transform-job-sJmW_En3.mjs → transform-job-DRrK28IH.mjs} +11 -38
- package/dist/{transform-tag-qTjNVfTW.mjs → transform-tag-CcElGp3C.mjs} +2 -21
- package/dist/transform-tag-Dmb4u3-Q.mjs +21 -0
- package/dist/transform-tag-_tgwlsdB.mjs +18 -0
- package/dist/{transforms-Cosz-Vq3.mjs → transforms-oU4zizbO.mjs} +10 -13
- package/dist/{tree-BkXtw0c4.mjs → tree-CH-f3bjP.mjs} +6 -10
- package/dist/{unpublish-BlGj7omM.mjs → unpublish-BUl9RU5C.mjs} +7 -18
- package/dist/{update-DpIzJ8Ts.mjs → update-BCS5FxKr.mjs} +11 -19
- package/dist/{update-hoCyoR-u.mjs → update-BZPllQoR.mjs} +9 -16
- package/dist/{update-CXlhrcy8.mjs → update-BiFDBcEH.mjs} +9 -16
- package/dist/{update-Cbsgvopz.mjs → update-BzMDeZiU.mjs} +9 -15
- package/dist/{update-CTWsiwme.mjs → update-C4YJQFDS.mjs} +9 -16
- package/dist/{update-CzrbMLZq.mjs → update-CHNSUHK4.mjs} +9 -16
- package/dist/{update-CsYFWkVd.mjs → update-CO4m4wH3.mjs} +10 -21
- package/dist/{update-DDVuyquf.mjs → update-CVPAwJaH.mjs} +10 -18
- package/dist/{update-C9K1QnOo.mjs → update-CmDTljK-.mjs} +9 -17
- package/dist/{update-DrvAdi-O.mjs → update-CvOO8TED.mjs} +9 -17
- package/dist/{update-Tw0kARao.mjs → update-D-NE60AV.mjs} +9 -16
- package/dist/{update-ZJ5T-SBW.mjs → update-Nfi44RrE.mjs} +10 -18
- package/dist/{update-C-ChEcI9.mjs → update-bD_Jh5-s.mjs} +10 -16
- package/dist/{update-CuKHukZ6.mjs → update-cYkvbqK8.mjs} +9 -16
- package/dist/update-dashcard-C3TuYO_k.mjs +50 -0
- package/dist/{update-BHhEtxwC.mjs → update-tX9mKBN_.mjs} +10 -21
- package/dist/{upgrade-D0HiyTxw.mjs → upgrade-DXMV4AyP.mjs} +37 -44
- package/dist/upload-CH632qW6.mjs +46 -0
- package/dist/upload-DAtxBBms.mjs +13 -0
- package/dist/upload-Dey_8rLf.mjs +13 -0
- package/dist/{uuid-D7NcSTj8.mjs → uuid-BJkDWj9p.mjs} +5 -7
- package/dist/validate-BWchyW0V.mjs +1469 -0
- package/dist/{validate-query-Di0VKMF-.mjs → validate-query-DaGYSmpQ.mjs} +4 -5
- package/dist/{values-OBiEVCVH.mjs → values-Dxf1JEoA.mjs} +8 -13
- package/dist/verify-K96rItG5.mjs +89 -0
- package/dist/{wait-B9qNlcTe.mjs → wait-DoMDH226.mjs} +10 -18
- package/dist/{wait-flags-D0FEgH6k.mjs → wait-flags-DWEF9tX4.mjs} +14 -11
- package/dist/window-BkvrP0gB.mjs +64 -0
- package/package.json +5 -35
- package/skill-data/core/SKILL.md +25 -22
- package/skill-data/dashboard/SKILL.md +6 -2
- package/skill-data/document/SKILL.md +2 -2
- package/skill-data/transform/SKILL.md +1 -1
- package/.claude-plugin/marketplace.json +0 -19
- package/dist/add-collection-B-Pf12HY.mjs +0 -60
- package/dist/add-collection-B2PdVMRy.mjs +0 -9
- package/dist/alert-DGcECcDb.mjs +0 -26
- package/dist/auth-B8Yb4ZaN.mjs +0 -22
- package/dist/capabilities-1HTHeDa4.mjs +0 -684
- package/dist/card-BT7ce7uO.mjs +0 -27
- package/dist/cards-Bz6anDNX.mjs +0 -38
- package/dist/cli.d.mts +0 -1
- package/dist/collection-ahFSJT-e.mjs +0 -23
- package/dist/command-augment-D9pI9Vbh.mjs +0 -11
- package/dist/create-branch-BwqFHYcZ.mjs +0 -57
- package/dist/dashboard-C__PiWrv.mjs +0 -36
- package/dist/database-B-xwx5LA.mjs +0 -61
- package/dist/db-BiLWl1J9.mjs +0 -27
- package/dist/dirty-BqdcrfUz.mjs +0 -35
- package/dist/document-C9ykHYOG.mjs +0 -22
- package/dist/events-C9PqRUCO.mjs +0 -44
- package/dist/export-CdKR5nPT.mjs +0 -103
- package/dist/field-P7aJaet9.mjs +0 -21
- package/dist/fields-D2czTLKq.mjs +0 -37
- package/dist/get-75Vdyusm.mjs +0 -49
- package/dist/get-B6fSPCfp.mjs +0 -35
- package/dist/get-BbKC0fTx.mjs +0 -35
- package/dist/get-BfFKIfpX.mjs +0 -36
- package/dist/get-Bpw05IUm.mjs +0 -38
- package/dist/get-CaIYg15K.mjs +0 -41
- package/dist/get-DXydDRVU.mjs +0 -35
- package/dist/get-Dy5f54pV.mjs +0 -35
- package/dist/git-sync-BzievbUz.mjs +0 -31
- package/dist/has-remote-changes-CjDHphUH.mjs +0 -67
- package/dist/import-DzA5Ty9_.mjs +0 -94
- package/dist/is-dirty-Cv0bdKkX.mjs +0 -8
- package/dist/key-B9AAqwjq.mjs +0 -17
- package/dist/list-AyGEaws8.mjs +0 -8
- package/dist/list-BiAVv9jX.mjs +0 -31
- package/dist/list-Bm1PlZEV.mjs +0 -31
- package/dist/list-BtgjcC2w.mjs +0 -31
- package/dist/list-CLgkOcmY.mjs +0 -39
- package/dist/list-CSnpbFML.mjs +0 -31
- package/dist/list-Cn-VruXD.mjs +0 -8
- package/dist/list-D7mMcRG5.mjs +0 -49
- package/dist/list-DOhVPh95.mjs +0 -39
- package/dist/list-DSHteJOl.mjs +0 -32
- package/dist/list-Dl81pkVs.mjs +0 -53
- package/dist/list-DwMcwucR.mjs +0 -31
- package/dist/list-IxaPXKXu.mjs +0 -31
- package/dist/list-hKRQUcGB.mjs +0 -39
- package/dist/listing-1G8iFfZe.mjs +0 -10
- package/dist/measure-DNldT89z.mjs +0 -25
- package/dist/paginate-DuDXvUPr.mjs +0 -49
- package/dist/patch-BpjI9BOz.mjs +0 -20
- package/dist/patch-DrMVqf34.mjs +0 -36
- package/dist/poll-task-CiB1o1wG.mjs +0 -194
- package/dist/preflight-DJOBTWVq.mjs +0 -90
- package/dist/prompt-DmxSLNrO.mjs +0 -52
- package/dist/remove-collection-DYQibG6d.mjs +0 -42
- package/dist/requests-Pc0u7PQS.mjs +0 -96
- package/dist/rescan-values-CuPGOzKI.mjs +0 -40
- package/dist/resolve-BiL5scF0.mjs +0 -91
- package/dist/revision-message-flag-B4BxzDXJ.mjs +0 -11
- package/dist/run-D6jyZ0nv.mjs +0 -135
- package/dist/runs-DRxrpAkU.mjs +0 -53
- package/dist/runtime-CPIHg_Zg.mjs +0 -1699
- package/dist/segment-BIKVTq_n.mjs +0 -25
- package/dist/setting-CApPg0Xr.mjs +0 -20
- package/dist/setting-CDEoJYO0.mjs +0 -55
- package/dist/setup-CruHFQJz.mjs +0 -71
- package/dist/snippet-DdoeL-7N.mjs +0 -22
- package/dist/stash-CR-ESWiX.mjs +0 -108
- package/dist/summary-WUjzNITU.mjs +0 -40
- package/dist/sync-schema-Cq5LzHHc.mjs +0 -54
- package/dist/sync-scope-Dh1wBlrg.mjs +0 -55
- package/dist/table-BK56VDw8.mjs +0 -21
- package/dist/timeline-Dl5pm5tN.mjs +0 -24
- package/dist/timeline-event-5JAeGVSI.mjs +0 -22
- package/dist/transform-ATK6rJBl.mjs +0 -31
- package/dist/transform-job-BezBE6Y8.mjs +0 -25
- package/dist/transform-tag-GqbcG_6_.mjs +0 -21
- package/dist/update-dashcard-Dnfa8_aJ.mjs +0 -73
- package/dist/upload-WT6SywFa.mjs +0 -16
- package/dist/validate-BoY75_M3.mjs +0 -1496
- package/dist/verify-VEB7TBQ_.mjs +0 -79
|
@@ -1,1699 +0,0 @@
|
|
|
1
|
-
import { AbortError, BASELINE_CAPABILITIES, ConfigError, DEFAULT_MAX_BYTES, ENV_API_KEY, ENV_DISABLE_KEYRING, ENV_PROFILE, ENV_SKIP_PREFLIGHT, ENV_URL, MetabaseError, NetworkError, ResponseShapeError, TimeoutError, ValidationError, consumeLegacyEnvWarnings, errorMessage, flagConsumesValue, isNotFoundError, isPlainObject, normalizeFlag, package_default, readEnv, reportError, toAliasArray, warn } from "./capabilities-1HTHeDa4.mjs";
|
|
2
|
-
import { setMetabaseAugment } from "./command-augment-D9pI9Vbh.mjs";
|
|
3
|
-
import { defineCommand } from "citty";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
import { promises } from "node:fs";
|
|
6
|
-
import { dirname, join } from "node:path";
|
|
7
|
-
import { Entry } from "@napi-rs/keyring";
|
|
8
|
-
import { homedir } from "node:os";
|
|
9
|
-
import { parse } from "semver";
|
|
10
|
-
import { setTimeout } from "node:timers/promises";
|
|
11
|
-
|
|
12
|
-
//#region src/commands/parse-integer.ts
|
|
13
|
-
const INTEGER_PATTERN = /^-?\d+$/;
|
|
14
|
-
function parseInteger(value, options) {
|
|
15
|
-
const trimmed = value.trim();
|
|
16
|
-
if (!INTEGER_PATTERN.test(trimmed)) throw new ConfigError(`invalid ${options.name}: "${value}" (expected integer)`);
|
|
17
|
-
const parsed = Number.parseInt(trimmed, 10);
|
|
18
|
-
if (parsed < options.min) throw new ConfigError(`invalid ${options.name}: ${parsed} (must be ≥ ${options.min})`);
|
|
19
|
-
return parsed;
|
|
20
|
-
}
|
|
21
|
-
function parseOptionalInteger(value, options) {
|
|
22
|
-
if (value === void 0 || value === "") return null;
|
|
23
|
-
return parseInteger(value, options);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/runtime/json.ts
|
|
28
|
-
const JSON_CONTENT_TYPE = "application/json";
|
|
29
|
-
function parseJson(input, schema, opts = {}) {
|
|
30
|
-
const result = parseJsonResult(input, schema, opts);
|
|
31
|
-
if (!result.ok) throw result.error;
|
|
32
|
-
return result.value;
|
|
33
|
-
}
|
|
34
|
-
function parseJsonResult(input, schema, opts = {}) {
|
|
35
|
-
const sourcePrefix = opts.source ? `${opts.source}: ` : "";
|
|
36
|
-
let raw;
|
|
37
|
-
try {
|
|
38
|
-
raw = JSON.parse(input);
|
|
39
|
-
} catch (error) {
|
|
40
|
-
return {
|
|
41
|
-
ok: false,
|
|
42
|
-
error: new ConfigError(`${sourcePrefix}invalid JSON: ${errorMessage(error)}`)
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
const parsed = schema.safeParse(raw);
|
|
46
|
-
if (!parsed.success) return {
|
|
47
|
-
ok: false,
|
|
48
|
-
error: new ValidationError(`${sourcePrefix}value did not match expected schema`, {
|
|
49
|
-
source: opts.source ?? "<input>",
|
|
50
|
-
zodIssues: parsed.error.issues
|
|
51
|
-
})
|
|
52
|
-
};
|
|
53
|
-
return {
|
|
54
|
-
ok: true,
|
|
55
|
-
value: parsed.data
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function parseJsonOrPlain(text, contentType, schema, opts = {}) {
|
|
59
|
-
if (!isJsonContentType(contentType)) return parseJson(JSON.stringify(text), schema, opts);
|
|
60
|
-
const attempt = parseJsonResult(text, schema, opts);
|
|
61
|
-
if (attempt.ok) return attempt.value;
|
|
62
|
-
if (attempt.error instanceof ValidationError) throw attempt.error;
|
|
63
|
-
return parseJson(JSON.stringify(text), schema, opts);
|
|
64
|
-
}
|
|
65
|
-
function isJsonContentType(contentType) {
|
|
66
|
-
return contentType !== null && contentType.includes(JSON_CONTENT_TYPE);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/core/paths.ts
|
|
71
|
-
const APP_DIR_NAME = "metabase-cli";
|
|
72
|
-
function configDir() {
|
|
73
|
-
if (process.platform === "win32") {
|
|
74
|
-
const appData = process.env["APPDATA"] ?? join(homedir(), "AppData", "Roaming");
|
|
75
|
-
return join(appData, APP_DIR_NAME);
|
|
76
|
-
}
|
|
77
|
-
const xdg = process.env["XDG_CONFIG_HOME"] ?? join(homedir(), ".config");
|
|
78
|
-
return join(xdg, APP_DIR_NAME);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/domain/session-properties.ts
|
|
83
|
-
const ServerVersion = z.object({
|
|
84
|
-
tag: z.string(),
|
|
85
|
-
date: z.string().optional(),
|
|
86
|
-
hash: z.string().optional()
|
|
87
|
-
}).loose();
|
|
88
|
-
const TokenFeatures = z.record(z.string(), z.boolean());
|
|
89
|
-
const SessionProperties = z.object({
|
|
90
|
-
version: ServerVersion,
|
|
91
|
-
"token-features": TokenFeatures.optional()
|
|
92
|
-
}).loose();
|
|
93
|
-
|
|
94
|
-
//#endregion
|
|
95
|
-
//#region src/core/version/tag.ts
|
|
96
|
-
const ParsedVersionSchema = z.object({
|
|
97
|
-
tag: z.string(),
|
|
98
|
-
major: z.number().int().nonnegative(),
|
|
99
|
-
patch: z.number().int().nonnegative()
|
|
100
|
-
});
|
|
101
|
-
function tryParseTag(tag) {
|
|
102
|
-
const parsed = parse(tag);
|
|
103
|
-
if (parsed === null || parsed.major !== 0 && parsed.major !== 1) return null;
|
|
104
|
-
return {
|
|
105
|
-
tag,
|
|
106
|
-
major: parsed.minor,
|
|
107
|
-
patch: parsed.patch
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
//#endregion
|
|
112
|
-
//#region src/core/auth/profile-record.ts
|
|
113
|
-
const ProbedUser = z.object({
|
|
114
|
-
id: z.number().int(),
|
|
115
|
-
name: z.string(),
|
|
116
|
-
isAdmin: z.boolean()
|
|
117
|
-
});
|
|
118
|
-
const ProfileLastProbe = z.object({
|
|
119
|
-
at: z.iso.datetime(),
|
|
120
|
-
version: ParsedVersionSchema.nullable(),
|
|
121
|
-
tokenFeatures: TokenFeatures.nullable(),
|
|
122
|
-
user: ProbedUser
|
|
123
|
-
});
|
|
124
|
-
const ProfileFailureKind = z.enum([
|
|
125
|
-
"auth",
|
|
126
|
-
"network",
|
|
127
|
-
"server"
|
|
128
|
-
]);
|
|
129
|
-
const ProfileLastFailure = z.object({
|
|
130
|
-
at: z.iso.datetime(),
|
|
131
|
-
kind: ProfileFailureKind,
|
|
132
|
-
reason: z.string()
|
|
133
|
-
});
|
|
134
|
-
const ProfileOAuth = z.object({
|
|
135
|
-
accessToken: z.string().nullable(),
|
|
136
|
-
refreshToken: z.string().nullable(),
|
|
137
|
-
expiresAt: z.iso.datetime(),
|
|
138
|
-
clientId: z.string()
|
|
139
|
-
}).loose();
|
|
140
|
-
const ProfileAuthMethod = z.enum(["oauth", "apiKey"]);
|
|
141
|
-
const ProfileRecord = z.object({
|
|
142
|
-
name: z.string(),
|
|
143
|
-
url: z.string(),
|
|
144
|
-
apiKey: z.string().nullable(),
|
|
145
|
-
oauth: ProfileOAuth.nullable().default(null),
|
|
146
|
-
lastProbe: ProfileLastProbe.nullable(),
|
|
147
|
-
lastFailure: ProfileLastFailure.nullable()
|
|
148
|
-
}).loose();
|
|
149
|
-
const ProfilesFile = z.object({ profiles: z.array(ProfileRecord) }).loose();
|
|
150
|
-
function profileAuthMethod(record) {
|
|
151
|
-
return record.oauth !== null ? "oauth" : "apiKey";
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/core/auth/storage.ts
|
|
156
|
-
const KEYRING_SERVICE = "metabase-cli";
|
|
157
|
-
const PROFILES_FILE = "profiles.json";
|
|
158
|
-
const LEGACY_CREDENTIALS_FILE = "credentials.json";
|
|
159
|
-
const LEGACY_REJECTIONS_FILE = "rejections.json";
|
|
160
|
-
const PROFILES_FILE_MODE = 384;
|
|
161
|
-
const PROFILES_DIR_MODE = 448;
|
|
162
|
-
const DEFAULT_PROFILE = "default";
|
|
163
|
-
const LEGACY_STORAGE_NOTICE = "Old profile storage detected and ignored; re-run `mb auth login` for each profile.";
|
|
164
|
-
const KEYCHAIN_RESIDUAL_NOTICE = "warning: could not remove one or more secrets from the OS keychain; a stored token may remain — remove it manually or retry.";
|
|
165
|
-
const account = {
|
|
166
|
-
profileApiKey: (profile) => `profile:${profile}:apiKey`,
|
|
167
|
-
profileOAuthAccess: (profile) => `profile:${profile}:oauthAccess`,
|
|
168
|
-
profileOAuthRefresh: (profile) => `profile:${profile}:oauthRefresh`
|
|
169
|
-
};
|
|
170
|
-
let legacyWarningPending = false;
|
|
171
|
-
let keychainResidualPending = false;
|
|
172
|
-
let keyringDowngradeNotice = null;
|
|
173
|
-
function profilesFilePath() {
|
|
174
|
-
return join(configDir(), PROFILES_FILE);
|
|
175
|
-
}
|
|
176
|
-
function consumeLegacyStorageWarning() {
|
|
177
|
-
if (!legacyWarningPending) return null;
|
|
178
|
-
legacyWarningPending = false;
|
|
179
|
-
return LEGACY_STORAGE_NOTICE;
|
|
180
|
-
}
|
|
181
|
-
function consumeKeychainResidualWarning() {
|
|
182
|
-
if (!keychainResidualPending) return null;
|
|
183
|
-
keychainResidualPending = false;
|
|
184
|
-
return KEYCHAIN_RESIDUAL_NOTICE;
|
|
185
|
-
}
|
|
186
|
-
function consumeKeyringDowngradeWarning() {
|
|
187
|
-
const message = keyringDowngradeNotice;
|
|
188
|
-
keyringDowngradeNotice = null;
|
|
189
|
-
return message;
|
|
190
|
-
}
|
|
191
|
-
function keyringEnabled() {
|
|
192
|
-
return readEnv(ENV_DISABLE_KEYRING) !== "1";
|
|
193
|
-
}
|
|
194
|
-
function trySetKeyring(key, value) {
|
|
195
|
-
if (!keyringEnabled()) return false;
|
|
196
|
-
try {
|
|
197
|
-
new Entry(KEYRING_SERVICE, key).setPassword(value);
|
|
198
|
-
return true;
|
|
199
|
-
} catch {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
function tryReadKeyring(key) {
|
|
204
|
-
if (!keyringEnabled()) return void 0;
|
|
205
|
-
try {
|
|
206
|
-
return new Entry(KEYRING_SERVICE, key).getPassword();
|
|
207
|
-
} catch {
|
|
208
|
-
return void 0;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
function removeKeyringEntry(key) {
|
|
212
|
-
if (!keyringEnabled()) return "skipped";
|
|
213
|
-
try {
|
|
214
|
-
return new Entry(KEYRING_SERVICE, key).deletePassword() ? "removed" : "absent";
|
|
215
|
-
} catch {
|
|
216
|
-
return "failed";
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
async function readProfilesFile() {
|
|
220
|
-
const path = profilesFilePath();
|
|
221
|
-
let raw;
|
|
222
|
-
try {
|
|
223
|
-
raw = await promises.readFile(path, "utf8");
|
|
224
|
-
} catch (error) {
|
|
225
|
-
if (isNotFoundError(error)) {
|
|
226
|
-
await detectLegacyArtifacts();
|
|
227
|
-
return { profiles: [] };
|
|
228
|
-
}
|
|
229
|
-
throw error;
|
|
230
|
-
}
|
|
231
|
-
const parsed = parseJsonResult(raw, ProfilesFile, { source: path });
|
|
232
|
-
if (parsed.ok) return parsed.value;
|
|
233
|
-
if (parsed.error instanceof ValidationError) {
|
|
234
|
-
legacyWarningPending = true;
|
|
235
|
-
return { profiles: [] };
|
|
236
|
-
}
|
|
237
|
-
throw parsed.error;
|
|
238
|
-
}
|
|
239
|
-
async function detectLegacyArtifacts() {
|
|
240
|
-
const legacyCredentials = join(configDir(), LEGACY_CREDENTIALS_FILE);
|
|
241
|
-
const legacyRejections = join(configDir(), LEGACY_REJECTIONS_FILE);
|
|
242
|
-
const [credentialsExists, rejectionsExists] = await Promise.all([fileExists(legacyCredentials), fileExists(legacyRejections)]);
|
|
243
|
-
if (credentialsExists || rejectionsExists) legacyWarningPending = true;
|
|
244
|
-
}
|
|
245
|
-
async function fileExists(path) {
|
|
246
|
-
try {
|
|
247
|
-
await promises.access(path);
|
|
248
|
-
return true;
|
|
249
|
-
} catch {
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
async function writeProfilesFile(file) {
|
|
254
|
-
const path = profilesFilePath();
|
|
255
|
-
if (file.profiles.length === 0) {
|
|
256
|
-
await promises.unlink(path).catch(() => void 0);
|
|
257
|
-
await cleanupLegacyFiles();
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
await promises.mkdir(dirname(path), {
|
|
261
|
-
recursive: true,
|
|
262
|
-
mode: PROFILES_DIR_MODE
|
|
263
|
-
});
|
|
264
|
-
const tmpPath = `${path}.${process.pid}.tmp`;
|
|
265
|
-
await promises.writeFile(tmpPath, JSON.stringify(file, null, 2) + "\n", { mode: PROFILES_FILE_MODE });
|
|
266
|
-
if (process.platform !== "win32") await promises.chmod(tmpPath, PROFILES_FILE_MODE);
|
|
267
|
-
try {
|
|
268
|
-
await promises.rename(tmpPath, path);
|
|
269
|
-
} catch (error) {
|
|
270
|
-
await promises.unlink(tmpPath).catch(() => void 0);
|
|
271
|
-
throw error;
|
|
272
|
-
}
|
|
273
|
-
await cleanupLegacyFiles();
|
|
274
|
-
}
|
|
275
|
-
async function cleanupLegacyFiles() {
|
|
276
|
-
await Promise.all([promises.unlink(join(configDir(), LEGACY_CREDENTIALS_FILE)).catch(() => void 0), promises.unlink(join(configDir(), LEGACY_REJECTIONS_FILE)).catch(() => void 0)]);
|
|
277
|
-
}
|
|
278
|
-
function findRecord(file, name) {
|
|
279
|
-
return file.profiles.find((entry) => entry.name === name) ?? null;
|
|
280
|
-
}
|
|
281
|
-
function sideIsKeyringBacked(record, side) {
|
|
282
|
-
return side === "oauth" ? record.oauth !== null && record.oauth.accessToken === null : record.oauth === null && record.apiKey === null;
|
|
283
|
-
}
|
|
284
|
-
function flagResidualIfUnconfirmed(existing, cleared, removals) {
|
|
285
|
-
if (existing === null || !removals.includes("failed")) return;
|
|
286
|
-
if (sideIsKeyringBacked(existing, cleared)) keychainResidualPending = true;
|
|
287
|
-
}
|
|
288
|
-
function fileLocation(key) {
|
|
289
|
-
return {
|
|
290
|
-
backend: "file",
|
|
291
|
-
path: profilesFilePath(),
|
|
292
|
-
account: key,
|
|
293
|
-
reason: keyringEnabled() ? "unavailable" : "disabled"
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
function keyringFallbackWarning(location) {
|
|
297
|
-
const cause = location.reason === "disabled" ? `OS keychain disabled via ${ENV_DISABLE_KEYRING}` : "OS keychain unavailable";
|
|
298
|
-
return `warning: ${cause}; credentials stored as plaintext at ${location.path}`;
|
|
299
|
-
}
|
|
300
|
-
function persistSecret(key, value) {
|
|
301
|
-
if (trySetKeyring(key, value)) return {
|
|
302
|
-
backend: "keyring",
|
|
303
|
-
service: KEYRING_SERVICE,
|
|
304
|
-
account: key
|
|
305
|
-
};
|
|
306
|
-
removeKeyringEntry(key);
|
|
307
|
-
return fileLocation(key);
|
|
308
|
-
}
|
|
309
|
-
function resolveSecret(key, inline) {
|
|
310
|
-
if (inline !== null) return inline;
|
|
311
|
-
return tryReadKeyring(key) ?? null;
|
|
312
|
-
}
|
|
313
|
-
async function readProfileCredential(name = DEFAULT_PROFILE) {
|
|
314
|
-
const file = await readProfilesFile();
|
|
315
|
-
const record = findRecord(file, name);
|
|
316
|
-
if (record === null) return null;
|
|
317
|
-
return resolveRecordCredential(record);
|
|
318
|
-
}
|
|
319
|
-
function resolveRecordCredential(record) {
|
|
320
|
-
if (record.oauth !== null) {
|
|
321
|
-
const accessToken = resolveSecret(account.profileOAuthAccess(record.name), record.oauth.accessToken);
|
|
322
|
-
const refreshToken = resolveSecret(account.profileOAuthRefresh(record.name), record.oauth.refreshToken);
|
|
323
|
-
if (accessToken === null || refreshToken === null) return null;
|
|
324
|
-
return {
|
|
325
|
-
url: record.url,
|
|
326
|
-
credential: {
|
|
327
|
-
kind: "oauth",
|
|
328
|
-
accessToken,
|
|
329
|
-
refreshToken,
|
|
330
|
-
expiresAt: record.oauth.expiresAt,
|
|
331
|
-
clientId: record.oauth.clientId
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
const apiKey = resolveSecret(account.profileApiKey(record.name), record.apiKey);
|
|
336
|
-
if (apiKey === null) return null;
|
|
337
|
-
return {
|
|
338
|
-
url: record.url,
|
|
339
|
-
credential: {
|
|
340
|
-
kind: "apiKey",
|
|
341
|
-
apiKey
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
async function readProfileRecord(name = DEFAULT_PROFILE) {
|
|
346
|
-
const file = await readProfilesFile();
|
|
347
|
-
return findRecord(file, name);
|
|
348
|
-
}
|
|
349
|
-
async function listProfileRecords() {
|
|
350
|
-
const file = await readProfilesFile();
|
|
351
|
-
return file.profiles;
|
|
352
|
-
}
|
|
353
|
-
async function upsertRecord(file, name, updated) {
|
|
354
|
-
const exists = findRecord(file, name) !== null;
|
|
355
|
-
const profiles = exists ? file.profiles.map((entry) => entry.name === name ? updated : entry) : [...file.profiles, updated];
|
|
356
|
-
await writeProfilesFile({
|
|
357
|
-
...file,
|
|
358
|
-
profiles
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
async function writeProfile(profile, name = DEFAULT_PROFILE) {
|
|
362
|
-
const location = persistSecret(account.profileApiKey(name), profile.apiKey);
|
|
363
|
-
const inlineApiKey = location.backend === "file" ? profile.apiKey : null;
|
|
364
|
-
const file = await readProfilesFile();
|
|
365
|
-
const existing = findRecord(file, name);
|
|
366
|
-
flagResidualIfUnconfirmed(existing, "oauth", [removeKeyringEntry(account.profileOAuthAccess(name)), removeKeyringEntry(account.profileOAuthRefresh(name))]);
|
|
367
|
-
const updated = existing === null ? {
|
|
368
|
-
name,
|
|
369
|
-
url: profile.url,
|
|
370
|
-
apiKey: inlineApiKey,
|
|
371
|
-
oauth: null,
|
|
372
|
-
lastProbe: null,
|
|
373
|
-
lastFailure: null
|
|
374
|
-
} : {
|
|
375
|
-
...existing,
|
|
376
|
-
url: profile.url,
|
|
377
|
-
apiKey: inlineApiKey,
|
|
378
|
-
oauth: null
|
|
379
|
-
};
|
|
380
|
-
await upsertRecord(file, name, updated);
|
|
381
|
-
return location;
|
|
382
|
-
}
|
|
383
|
-
async function writeOAuthProfile(url, credential, name = DEFAULT_PROFILE) {
|
|
384
|
-
const accessKey = account.profileOAuthAccess(name);
|
|
385
|
-
const refreshKey = account.profileOAuthRefresh(name);
|
|
386
|
-
const accessLocation = persistSecret(accessKey, credential.accessToken);
|
|
387
|
-
const refreshLocation = persistSecret(refreshKey, credential.refreshToken);
|
|
388
|
-
const onFile = accessLocation.backend === "file" || refreshLocation.backend === "file";
|
|
389
|
-
const oauth = {
|
|
390
|
-
accessToken: onFile ? credential.accessToken : null,
|
|
391
|
-
refreshToken: onFile ? credential.refreshToken : null,
|
|
392
|
-
expiresAt: credential.expiresAt,
|
|
393
|
-
clientId: credential.clientId
|
|
394
|
-
};
|
|
395
|
-
const file = await readProfilesFile();
|
|
396
|
-
const existing = findRecord(file, name);
|
|
397
|
-
if (onFile && existing !== null && sideIsKeyringBacked(existing, "oauth")) keyringDowngradeNotice = keyringFallbackWarning(fileLocation(accessKey));
|
|
398
|
-
flagResidualIfUnconfirmed(existing, "apiKey", [removeKeyringEntry(account.profileApiKey(name))]);
|
|
399
|
-
const updated = existing === null ? {
|
|
400
|
-
name,
|
|
401
|
-
url,
|
|
402
|
-
apiKey: null,
|
|
403
|
-
oauth,
|
|
404
|
-
lastProbe: null,
|
|
405
|
-
lastFailure: null
|
|
406
|
-
} : {
|
|
407
|
-
...existing,
|
|
408
|
-
url,
|
|
409
|
-
apiKey: null,
|
|
410
|
-
oauth
|
|
411
|
-
};
|
|
412
|
-
await upsertRecord(file, name, updated);
|
|
413
|
-
return onFile ? fileLocation(accessKey) : {
|
|
414
|
-
backend: "keyring",
|
|
415
|
-
service: KEYRING_SERVICE,
|
|
416
|
-
account: accessKey
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
async function writeProbeResult(name, input) {
|
|
420
|
-
const probe = ProfileLastProbe.parse({
|
|
421
|
-
at: new Date().toISOString(),
|
|
422
|
-
version: input.server.version,
|
|
423
|
-
tokenFeatures: input.server.tokenFeatures,
|
|
424
|
-
user: input.user
|
|
425
|
-
});
|
|
426
|
-
const file = await readProfilesFile();
|
|
427
|
-
const existing = findRecord(file, name);
|
|
428
|
-
if (existing === null) return null;
|
|
429
|
-
const profiles = file.profiles.map((entry) => entry.name === name ? {
|
|
430
|
-
...entry,
|
|
431
|
-
lastProbe: probe,
|
|
432
|
-
lastFailure: null
|
|
433
|
-
} : entry);
|
|
434
|
-
await writeProfilesFile({
|
|
435
|
-
...file,
|
|
436
|
-
profiles
|
|
437
|
-
});
|
|
438
|
-
return probe;
|
|
439
|
-
}
|
|
440
|
-
async function writeProbeFailure(name, input) {
|
|
441
|
-
const failure$1 = ProfileLastFailure.parse({
|
|
442
|
-
at: new Date().toISOString(),
|
|
443
|
-
kind: input.kind,
|
|
444
|
-
reason: input.reason
|
|
445
|
-
});
|
|
446
|
-
const file = await readProfilesFile();
|
|
447
|
-
const existing = findRecord(file, name);
|
|
448
|
-
if (existing === null) return null;
|
|
449
|
-
const profiles = file.profiles.map((entry) => entry.name === name ? {
|
|
450
|
-
...entry,
|
|
451
|
-
lastFailure: failure$1
|
|
452
|
-
} : entry);
|
|
453
|
-
await writeProfilesFile({
|
|
454
|
-
...file,
|
|
455
|
-
profiles
|
|
456
|
-
});
|
|
457
|
-
return failure$1;
|
|
458
|
-
}
|
|
459
|
-
async function clearProfile(name = DEFAULT_PROFILE) {
|
|
460
|
-
const file = await readProfilesFile();
|
|
461
|
-
const existing = findRecord(file, name);
|
|
462
|
-
const removals = [
|
|
463
|
-
removeKeyringEntry(account.profileApiKey(name)),
|
|
464
|
-
removeKeyringEntry(account.profileOAuthAccess(name)),
|
|
465
|
-
removeKeyringEntry(account.profileOAuthRefresh(name))
|
|
466
|
-
];
|
|
467
|
-
if (existing !== null) flagResidualIfUnconfirmed(existing, existing.oauth !== null ? "oauth" : "apiKey", removals);
|
|
468
|
-
if (existing === null) return false;
|
|
469
|
-
await writeProfilesFile({
|
|
470
|
-
...file,
|
|
471
|
-
profiles: file.profiles.filter((entry) => entry.name !== name)
|
|
472
|
-
});
|
|
473
|
-
return true;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
//#endregion
|
|
477
|
-
//#region src/core/auth/credential.ts
|
|
478
|
-
const API_KEY_HEADER = "x-api-key";
|
|
479
|
-
const AUTHORIZATION_HEADER = "authorization";
|
|
480
|
-
const BEARER_PREFIX = "Bearer ";
|
|
481
|
-
const EXPIRY_SKEW_MS = 6e4;
|
|
482
|
-
const DEFAULT_EXPIRES_IN_SECONDS = 3600;
|
|
483
|
-
function credentialAuthHeader(credential) {
|
|
484
|
-
if (credential.kind === "apiKey") return {
|
|
485
|
-
name: API_KEY_HEADER,
|
|
486
|
-
value: credential.apiKey
|
|
487
|
-
};
|
|
488
|
-
return {
|
|
489
|
-
name: AUTHORIZATION_HEADER,
|
|
490
|
-
value: BEARER_PREFIX + credential.accessToken
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
function credentialSecrets(credential) {
|
|
494
|
-
if (credential.kind === "apiKey") return [credential.apiKey];
|
|
495
|
-
return [credential.accessToken, credential.refreshToken];
|
|
496
|
-
}
|
|
497
|
-
function isOAuthExpired(credential, nowMs) {
|
|
498
|
-
const expiryMs = Date.parse(credential.expiresAt);
|
|
499
|
-
if (Number.isNaN(expiryMs)) return true;
|
|
500
|
-
return expiryMs - EXPIRY_SKEW_MS <= nowMs;
|
|
501
|
-
}
|
|
502
|
-
function expiresAtFromNow(expiresInSeconds, nowMs) {
|
|
503
|
-
return new Date(nowMs + expiresInSeconds * 1e3).toISOString();
|
|
504
|
-
}
|
|
505
|
-
function oauthCredentialFromTokens(tokens, refreshToken, clientId, nowMs) {
|
|
506
|
-
return {
|
|
507
|
-
kind: "oauth",
|
|
508
|
-
accessToken: tokens.access_token,
|
|
509
|
-
refreshToken,
|
|
510
|
-
expiresAt: expiresAtFromNow(tokens.expires_in ?? DEFAULT_EXPIRES_IN_SECONDS, nowMs),
|
|
511
|
-
clientId
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
//#endregion
|
|
516
|
-
//#region src/core/url.ts
|
|
517
|
-
function normalizeUrl(input) {
|
|
518
|
-
const trimmed = input.trim().replace(/\/+$/, "");
|
|
519
|
-
if (!/^https?:\/\//i.test(trimmed)) throw new ConfigError("URL must start with http:// or https://");
|
|
520
|
-
return trimmed;
|
|
521
|
-
}
|
|
522
|
-
function displayUrl(input) {
|
|
523
|
-
const parsed = new URL(input);
|
|
524
|
-
const path = parsed.pathname.replace(/\/+$/, "");
|
|
525
|
-
return `${parsed.origin}${path}`;
|
|
526
|
-
}
|
|
527
|
-
const LOOPBACK_HOSTS = new Set([
|
|
528
|
-
"localhost",
|
|
529
|
-
"127.0.0.1",
|
|
530
|
-
"::1",
|
|
531
|
-
"[::1]"
|
|
532
|
-
]);
|
|
533
|
-
function isLoopbackHost(hostname) {
|
|
534
|
-
return LOOPBACK_HOSTS.has(hostname.toLowerCase());
|
|
535
|
-
}
|
|
536
|
-
function assertEndpointOrigin(endpoint, baseUrl, label) {
|
|
537
|
-
let parsed;
|
|
538
|
-
try {
|
|
539
|
-
parsed = new URL(endpoint);
|
|
540
|
-
} catch {
|
|
541
|
-
throw new ConfigError(`OAuth ${label} is not a valid URL: ${endpoint}`);
|
|
542
|
-
}
|
|
543
|
-
const base = new URL(baseUrl);
|
|
544
|
-
if (parsed.protocol !== "https:" && !isLoopbackHost(parsed.hostname)) throw new ConfigError(`OAuth ${label} must use https: ${endpoint}`);
|
|
545
|
-
if (parsed.origin !== base.origin) throw new ConfigError(`OAuth ${label} origin (${parsed.origin}) does not match the Metabase URL (${base.origin})`);
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
//#endregion
|
|
549
|
-
//#region src/runtime/signal.ts
|
|
550
|
-
function createProcessAbortHandler() {
|
|
551
|
-
const controller = new AbortController();
|
|
552
|
-
const handler = () => {
|
|
553
|
-
if (!controller.signal.aborted) controller.abort(new AbortError("interrupted"));
|
|
554
|
-
process.off("SIGINT", handler);
|
|
555
|
-
};
|
|
556
|
-
process.on("SIGINT", handler);
|
|
557
|
-
return {
|
|
558
|
-
signal: controller.signal,
|
|
559
|
-
uninstall: () => process.off("SIGINT", handler)
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
|
-
let singleton = null;
|
|
563
|
-
function getProcessAbortSignal() {
|
|
564
|
-
if (singleton === null) singleton = createProcessAbortHandler().signal;
|
|
565
|
-
return singleton;
|
|
566
|
-
}
|
|
567
|
-
function combineAborts(timeoutSignal, callerSignal) {
|
|
568
|
-
const processSignal = getProcessAbortSignal();
|
|
569
|
-
const signals = [timeoutSignal, processSignal];
|
|
570
|
-
if (callerSignal) signals.push(callerSignal);
|
|
571
|
-
return {
|
|
572
|
-
combined: AbortSignal.any(signals),
|
|
573
|
-
processSignal
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
function throwIfAborted(...signals) {
|
|
577
|
-
for (const signal of signals) if (signal?.aborted) throw abortReason(signal);
|
|
578
|
-
}
|
|
579
|
-
function abortReason(signal) {
|
|
580
|
-
const reason = signal.reason;
|
|
581
|
-
if (reason instanceof MetabaseError) return reason;
|
|
582
|
-
if (reason instanceof Error || typeof reason === "string") return new AbortError(errorMessage(reason) || "aborted");
|
|
583
|
-
return new AbortError("aborted");
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
//#endregion
|
|
587
|
-
//#region src/core/http/sanitize.ts
|
|
588
|
-
const SECRET_HEADER_NAMES = new Set([
|
|
589
|
-
"authorization",
|
|
590
|
-
"x-api-key",
|
|
591
|
-
"x-metabase-session",
|
|
592
|
-
"cookie",
|
|
593
|
-
"set-cookie",
|
|
594
|
-
"proxy-authorization"
|
|
595
|
-
]);
|
|
596
|
-
const REDACTED = "[REDACTED]";
|
|
597
|
-
function redactHeaders(headers) {
|
|
598
|
-
const result = {};
|
|
599
|
-
const entries = headers instanceof Headers ? headers.entries() : Object.entries(headers);
|
|
600
|
-
for (const [key, value] of entries) result[key] = SECRET_HEADER_NAMES.has(key.toLowerCase()) ? REDACTED : value;
|
|
601
|
-
return result;
|
|
602
|
-
}
|
|
603
|
-
function redactBody(body, ctx) {
|
|
604
|
-
let result = body;
|
|
605
|
-
for (const secret of ctx.knownSecrets) {
|
|
606
|
-
if (secret.length === 0) continue;
|
|
607
|
-
result = result.replaceAll(secret, REDACTED);
|
|
608
|
-
}
|
|
609
|
-
return result;
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
//#endregion
|
|
613
|
-
//#region src/core/http/errors.ts
|
|
614
|
-
const ROUTE_MISSING_LITERAL = "API endpoint does not exist.";
|
|
615
|
-
const RESOURCE_MISSING_LITERAL = "Not found.";
|
|
616
|
-
const STATUS_CLASSIFICATIONS = {
|
|
617
|
-
401: { retryable: false },
|
|
618
|
-
403: { retryable: false },
|
|
619
|
-
404: { retryable: false },
|
|
620
|
-
408: {
|
|
621
|
-
retryable: true,
|
|
622
|
-
message: "Metabase timed out responding."
|
|
623
|
-
},
|
|
624
|
-
425: { retryable: true },
|
|
625
|
-
429: {
|
|
626
|
-
retryable: true,
|
|
627
|
-
message: "Metabase rate-limited the request."
|
|
628
|
-
},
|
|
629
|
-
500: { retryable: true },
|
|
630
|
-
502: { retryable: true },
|
|
631
|
-
503: { retryable: true },
|
|
632
|
-
504: {
|
|
633
|
-
retryable: true,
|
|
634
|
-
message: "Metabase timed out responding."
|
|
635
|
-
}
|
|
636
|
-
};
|
|
637
|
-
const ErrorEnvelope = z.object({
|
|
638
|
-
message: z.string().optional(),
|
|
639
|
-
error: z.string().optional(),
|
|
640
|
-
"error-message": z.string().optional(),
|
|
641
|
-
via: z.array(z.object({ message: z.string().optional() }).loose()).optional(),
|
|
642
|
-
"specific-errors": z.unknown().optional(),
|
|
643
|
-
errors: z.unknown().optional()
|
|
644
|
-
}).loose();
|
|
645
|
-
const MAX_EXTRACTED_MESSAGE_LEN = 500;
|
|
646
|
-
const ELLIPSIS = "…";
|
|
647
|
-
var HttpError = class extends MetabaseError {
|
|
648
|
-
category = "http";
|
|
649
|
-
exitCode = 1;
|
|
650
|
-
status;
|
|
651
|
-
kind;
|
|
652
|
-
developerDetail;
|
|
653
|
-
constructor(input) {
|
|
654
|
-
const sanitizedBody = sanitizeBody(input.rawBody, input.redactionContext);
|
|
655
|
-
const redactedHeaders = redactHeaders(input.responseHeaders);
|
|
656
|
-
const kind = classifyKind(input.status, sanitizedBody, redactedHeaders);
|
|
657
|
-
super(input.overrideUserMessage ?? buildUserMessage(kind, input, sanitizedBody));
|
|
658
|
-
this.name = "HttpError";
|
|
659
|
-
this.status = input.status;
|
|
660
|
-
this.kind = kind;
|
|
661
|
-
this.developerDetail = {
|
|
662
|
-
status: input.status,
|
|
663
|
-
statusText: input.statusText,
|
|
664
|
-
method: input.method,
|
|
665
|
-
url: input.url,
|
|
666
|
-
responseHeaders: redactedHeaders,
|
|
667
|
-
body: sanitizedBody
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
get isRetryable() {
|
|
671
|
-
return isRetryableStatus(this.status);
|
|
672
|
-
}
|
|
673
|
-
};
|
|
674
|
-
function isRetryableStatus(status) {
|
|
675
|
-
return STATUS_CLASSIFICATIONS[status]?.retryable === true;
|
|
676
|
-
}
|
|
677
|
-
function sanitizeBody(rawBody, ctx) {
|
|
678
|
-
if (rawBody === null) return null;
|
|
679
|
-
if (ctx === void 0) return rawBody;
|
|
680
|
-
return redactBody(rawBody, ctx);
|
|
681
|
-
}
|
|
682
|
-
function classifyKind(status, sanitizedBody, redactedHeaders) {
|
|
683
|
-
if (status === 401 || status === 403) return "auth";
|
|
684
|
-
if (status === 404) return isRouteMissingResponse(sanitizedBody, redactedHeaders) ? "route-missing" : "resource-missing";
|
|
685
|
-
if (status === 429) return "rate-limit";
|
|
686
|
-
if (status >= 500 && status < 600) return "server-error";
|
|
687
|
-
return "generic";
|
|
688
|
-
}
|
|
689
|
-
function isRouteMissingResponse(sanitizedBody, redactedHeaders) {
|
|
690
|
-
if (sanitizedBody?.includes(ROUTE_MISSING_LITERAL)) return true;
|
|
691
|
-
if (sanitizedBody?.includes(RESOURCE_MISSING_LITERAL)) return false;
|
|
692
|
-
if (redactedHeaders["content-type"]?.includes(JSON_CONTENT_TYPE)) return false;
|
|
693
|
-
if (sanitizedBody === null || sanitizedBody.trim() === "") return true;
|
|
694
|
-
return !parseJsonResult(sanitizedBody, ErrorEnvelope).ok;
|
|
695
|
-
}
|
|
696
|
-
function buildUserMessage(kind, input, sanitizedBody) {
|
|
697
|
-
if (kind === "route-missing") return buildRouteMissingMessage(input);
|
|
698
|
-
if (kind === "resource-missing") return `Not found: ${input.method} ${pathFromUrl(input.url)}.`;
|
|
699
|
-
const fromBody = parseEnvelopeMessage(sanitizedBody);
|
|
700
|
-
if (fromBody !== null) return fromBody;
|
|
701
|
-
if (kind === "auth") return `Invalid or unauthorized API key (host: ${hostFromUrl(input.url)}).`;
|
|
702
|
-
return defaultMessageForStatus(input.status);
|
|
703
|
-
}
|
|
704
|
-
function buildRouteMissingMessage(input) {
|
|
705
|
-
const path = pathFromUrl(input.url);
|
|
706
|
-
if (!input.serverTag) return `This endpoint is not available on the connected Metabase: ${input.method} ${path}.`;
|
|
707
|
-
return `This endpoint is not available on Metabase ${input.serverTag}: ${input.method} ${path}. The command may require a newer Metabase major version. Run 'mb auth list' to see this server's version.`;
|
|
708
|
-
}
|
|
709
|
-
function pathFromUrl(url) {
|
|
710
|
-
const parsed = new URL(url);
|
|
711
|
-
return parsed.pathname + parsed.search;
|
|
712
|
-
}
|
|
713
|
-
function hostFromUrl(url) {
|
|
714
|
-
return new URL(url).host;
|
|
715
|
-
}
|
|
716
|
-
function parseEnvelopeMessage(sanitizedBody) {
|
|
717
|
-
if (!sanitizedBody) return null;
|
|
718
|
-
const result = parseJsonResult(sanitizedBody, ErrorEnvelope);
|
|
719
|
-
if (!result.ok) return null;
|
|
720
|
-
const envelope = result.value;
|
|
721
|
-
const topLevel = envelope.message ?? envelope.error ?? envelope["error-message"];
|
|
722
|
-
if (topLevel) return capLength(topLevel);
|
|
723
|
-
const viaMessage = envelope.via?.find((entry) => entry.message)?.message;
|
|
724
|
-
if (viaMessage) return capLength(viaMessage);
|
|
725
|
-
const specific = formatErrorTree(envelope["specific-errors"]);
|
|
726
|
-
if (specific) return capLength(specific);
|
|
727
|
-
const generic = formatErrorTree(envelope.errors);
|
|
728
|
-
if (generic) return capLength(generic);
|
|
729
|
-
return null;
|
|
730
|
-
}
|
|
731
|
-
function formatErrorTree(value) {
|
|
732
|
-
const entries = collectLeafEntries(value, []);
|
|
733
|
-
if (entries.length === 0) return null;
|
|
734
|
-
return entries.map(formatLeafEntry).join("; ");
|
|
735
|
-
}
|
|
736
|
-
function formatLeafEntry(entry) {
|
|
737
|
-
return entry.path === "" ? entry.message : `${entry.path}: ${entry.message}`;
|
|
738
|
-
}
|
|
739
|
-
function collectLeafEntries(value, path) {
|
|
740
|
-
if (typeof value === "string") {
|
|
741
|
-
const trimmed = value.trim();
|
|
742
|
-
return trimmed === "" ? [] : [{
|
|
743
|
-
path: path.join("."),
|
|
744
|
-
message: trimmed
|
|
745
|
-
}];
|
|
746
|
-
}
|
|
747
|
-
if (Array.isArray(value)) {
|
|
748
|
-
const messages = value.filter((entry) => typeof entry === "string" && entry.trim() !== "");
|
|
749
|
-
if (messages.length === 0) return [];
|
|
750
|
-
return [{
|
|
751
|
-
path: path.join("."),
|
|
752
|
-
message: messages.join("; ")
|
|
753
|
-
}];
|
|
754
|
-
}
|
|
755
|
-
if (isPlainObject(value)) return Object.entries(value).flatMap(([key, child]) => collectLeafEntries(child, [...path, key]));
|
|
756
|
-
return [];
|
|
757
|
-
}
|
|
758
|
-
function capLength(message) {
|
|
759
|
-
if (message.length <= MAX_EXTRACTED_MESSAGE_LEN) return message;
|
|
760
|
-
return message.slice(0, MAX_EXTRACTED_MESSAGE_LEN - ELLIPSIS.length) + ELLIPSIS;
|
|
761
|
-
}
|
|
762
|
-
function defaultMessageForStatus(status) {
|
|
763
|
-
return STATUS_CLASSIFICATIONS[status]?.message ?? `Metabase returned ${status}.`;
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
//#endregion
|
|
767
|
-
//#region src/core/http/network-error.ts
|
|
768
|
-
const NETWORK_HINTS = {
|
|
769
|
-
ECONNREFUSED: (t) => `Connection refused by ${t.host} — is Metabase running and is the port correct?`,
|
|
770
|
-
ENOTFOUND: (t) => `Host not found: ${t.hostname} — check the URL.`,
|
|
771
|
-
EAI_AGAIN: (t) => `Could not resolve ${t.hostname} — check your network connection and the URL.`,
|
|
772
|
-
ECONNRESET: (t) => `Connection to ${t.host} was reset — the server may have closed it, or http/https may be mismatched.`,
|
|
773
|
-
ETIMEDOUT: (t) => `Connection to ${t.host} timed out — check the host, port, and your network.`
|
|
774
|
-
};
|
|
775
|
-
const TLS_ERROR_CODES = new Set([
|
|
776
|
-
"EPROTO",
|
|
777
|
-
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
778
|
-
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
779
|
-
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
780
|
-
"CERT_HAS_EXPIRED",
|
|
781
|
-
"ERR_TLS_CERT_ALTNAME_INVALID"
|
|
782
|
-
]);
|
|
783
|
-
function buildNetworkError(error, method, url) {
|
|
784
|
-
const fallback = errorMessage(error);
|
|
785
|
-
const code = causeCode(error);
|
|
786
|
-
const target = networkTarget(url);
|
|
787
|
-
return new NetworkError(networkMessage(code, target, fallback), {
|
|
788
|
-
method,
|
|
789
|
-
url,
|
|
790
|
-
cause: code ?? fallback
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
function networkMessage(code, target, fallback) {
|
|
794
|
-
if (code === null) return `Could not reach Metabase: ${fallback}`;
|
|
795
|
-
if (TLS_ERROR_CODES.has(code)) return `Could not reach Metabase: TLS error contacting ${target.host} (${code}) — the certificate could not be verified, or https:// was used against a plain-HTTP server. For a certificate the OS does not trust either, set NODE_EXTRA_CA_CERTS to its CA bundle.`;
|
|
796
|
-
const hint = NETWORK_HINTS[code];
|
|
797
|
-
if (hint === void 0) return `Could not reach Metabase: ${fallback} (${code})`;
|
|
798
|
-
return `Could not reach Metabase: ${hint(target)}`;
|
|
799
|
-
}
|
|
800
|
-
function causeCode(error) {
|
|
801
|
-
const cause = error instanceof Error ? error.cause : void 0;
|
|
802
|
-
if (cause instanceof Error && "code" in cause && typeof cause.code === "string") return cause.code;
|
|
803
|
-
return null;
|
|
804
|
-
}
|
|
805
|
-
function networkTarget(url) {
|
|
806
|
-
const parsed = new URL(url);
|
|
807
|
-
return {
|
|
808
|
-
host: parsed.host,
|
|
809
|
-
hostname: parsed.hostname
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
//#endregion
|
|
814
|
-
//#region src/core/http/retry.ts
|
|
815
|
-
const DEFAULT_MAX_RETRIES = 3;
|
|
816
|
-
const BASE_DELAY_MS = 250;
|
|
817
|
-
const MAX_DELAY_MS = 8e3;
|
|
818
|
-
const MS_PER_SECOND = 1e3;
|
|
819
|
-
function backoffDelay({ attempt, retryAfterHeader }) {
|
|
820
|
-
const fromHeader = parseRetryAfter(retryAfterHeader);
|
|
821
|
-
if (fromHeader !== null) return fromHeader;
|
|
822
|
-
return Math.min(MAX_DELAY_MS, BASE_DELAY_MS * 2 ** attempt);
|
|
823
|
-
}
|
|
824
|
-
function parseRetryAfter(header) {
|
|
825
|
-
if (!header) return null;
|
|
826
|
-
const numeric = Number(header);
|
|
827
|
-
if (Number.isFinite(numeric) && numeric >= 0) return Math.round(numeric * MS_PER_SECOND);
|
|
828
|
-
const dateMs = Date.parse(header);
|
|
829
|
-
if (Number.isFinite(dateMs)) return Math.max(0, dateMs - Date.now());
|
|
830
|
-
return null;
|
|
831
|
-
}
|
|
832
|
-
function sleep(ms, signal) {
|
|
833
|
-
return setTimeout(ms, void 0, { signal });
|
|
834
|
-
}
|
|
835
|
-
async function runWithRetries(attempt, signal) {
|
|
836
|
-
let attemptIndex = 0;
|
|
837
|
-
while (true) {
|
|
838
|
-
const outcome = await attempt(attemptIndex);
|
|
839
|
-
if (outcome.kind === "success") return outcome.response;
|
|
840
|
-
await sleep(outcome.delayMs, signal);
|
|
841
|
-
attemptIndex += 1;
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
//#endregion
|
|
846
|
-
//#region src/core/http/client.ts
|
|
847
|
-
const UNAUTHORIZED_STATUS = 401;
|
|
848
|
-
const DEFAULT_TIMEOUT_MS = 3e4;
|
|
849
|
-
const OCTET_STREAM_CONTENT_TYPE = "application/octet-stream";
|
|
850
|
-
const TEXT_CONTENT_TYPE_PREFIX = "text/";
|
|
851
|
-
const ERROR_BODY_BYTE_CAP = 64 * 1024;
|
|
852
|
-
const USER_AGENT = `metabase-cli/${package_default.version}`;
|
|
853
|
-
const IDEMPOTENT_METHODS = new Set([
|
|
854
|
-
"GET",
|
|
855
|
-
"HEAD",
|
|
856
|
-
"OPTIONS"
|
|
857
|
-
]);
|
|
858
|
-
const NO_SERVER_TAG = async () => null;
|
|
859
|
-
function createClient(config, overrides = {}) {
|
|
860
|
-
const fetchImpl = overrides.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
861
|
-
const getServerTag = overrides.getServerTag ?? NO_SERVER_TAG;
|
|
862
|
-
const refreshCredential = overrides.refreshCredential;
|
|
863
|
-
let credential = config.credential;
|
|
864
|
-
const knownSecrets = new Set(credentialSecrets(credential));
|
|
865
|
-
const redactionContext = { knownSecrets };
|
|
866
|
-
let refreshInFlight = null;
|
|
867
|
-
function tryRefreshCredential() {
|
|
868
|
-
const refresh = refreshCredential;
|
|
869
|
-
if (credential.kind !== "oauth" || refresh === void 0) return Promise.resolve(false);
|
|
870
|
-
refreshInFlight ??= refreshOnce(refresh).finally(() => {
|
|
871
|
-
refreshInFlight = null;
|
|
872
|
-
});
|
|
873
|
-
return refreshInFlight;
|
|
874
|
-
}
|
|
875
|
-
async function refreshOnce(refresh) {
|
|
876
|
-
const next = await refresh();
|
|
877
|
-
if (next === null) return false;
|
|
878
|
-
credential = next;
|
|
879
|
-
for (const secret of credentialSecrets(next)) knownSecrets.add(secret);
|
|
880
|
-
return true;
|
|
881
|
-
}
|
|
882
|
-
async function attemptOnce(prepared, attempt) {
|
|
883
|
-
const hasRetriesLeft = attempt < prepared.retries;
|
|
884
|
-
const timeoutSignal = AbortSignal.timeout(prepared.timeoutMs);
|
|
885
|
-
const { combined, processSignal } = combineAborts(timeoutSignal, prepared.callerSignal);
|
|
886
|
-
let response;
|
|
887
|
-
try {
|
|
888
|
-
response = await fetchImpl(prepared.url, {
|
|
889
|
-
method: prepared.method,
|
|
890
|
-
headers: prepared.headers,
|
|
891
|
-
body: prepared.body,
|
|
892
|
-
signal: combined
|
|
893
|
-
});
|
|
894
|
-
} catch (error) {
|
|
895
|
-
throwIfAborted(prepared.callerSignal, processSignal);
|
|
896
|
-
if (hasRetriesLeft) return {
|
|
897
|
-
kind: "retry",
|
|
898
|
-
delayMs: backoffDelay({ attempt })
|
|
899
|
-
};
|
|
900
|
-
if (timeoutSignal.aborted) throw new TimeoutError(`Request timed out after ${prepared.timeoutMs}ms`, {
|
|
901
|
-
kind: "http",
|
|
902
|
-
method: prepared.method,
|
|
903
|
-
url: prepared.url,
|
|
904
|
-
timeoutMs: prepared.timeoutMs
|
|
905
|
-
});
|
|
906
|
-
throw buildNetworkError(error, prepared.method, prepared.url);
|
|
907
|
-
}
|
|
908
|
-
const canRetryStatus = hasRetriesLeft && prepared.idempotent;
|
|
909
|
-
if (!response.ok && isRetryableStatus(response.status) && canRetryStatus) {
|
|
910
|
-
const retryAfter = response.headers.get("Retry-After");
|
|
911
|
-
response.body?.cancel().catch(() => void 0);
|
|
912
|
-
return {
|
|
913
|
-
kind: "retry",
|
|
914
|
-
delayMs: backoffDelay({
|
|
915
|
-
attempt,
|
|
916
|
-
retryAfterHeader: retryAfter
|
|
917
|
-
})
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
|
-
if (!response.ok) {
|
|
921
|
-
const rawBody = await readBodyForError(response);
|
|
922
|
-
const serverTag = await getServerTag();
|
|
923
|
-
throw new HttpError({
|
|
924
|
-
status: response.status,
|
|
925
|
-
statusText: response.statusText,
|
|
926
|
-
method: prepared.method,
|
|
927
|
-
url: prepared.url,
|
|
928
|
-
responseHeaders: response.headers,
|
|
929
|
-
rawBody,
|
|
930
|
-
serverTag,
|
|
931
|
-
redactionContext
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
assertContentType(response, prepared);
|
|
935
|
-
return {
|
|
936
|
-
kind: "success",
|
|
937
|
-
response
|
|
938
|
-
};
|
|
939
|
-
}
|
|
940
|
-
async function executeRaw(prepared) {
|
|
941
|
-
return runWithRetries((attempt) => attemptOnce(prepared, attempt), prepared.callerSignal);
|
|
942
|
-
}
|
|
943
|
-
async function executeWithAuthRefresh(path, opts) {
|
|
944
|
-
const prepared = prepare(path, opts);
|
|
945
|
-
try {
|
|
946
|
-
return {
|
|
947
|
-
response: await executeRaw(prepared),
|
|
948
|
-
prepared
|
|
949
|
-
};
|
|
950
|
-
} catch (error) {
|
|
951
|
-
if (error instanceof HttpError && error.status === UNAUTHORIZED_STATUS) {
|
|
952
|
-
if (await tryRefreshCredential()) {
|
|
953
|
-
const retried = prepare(path, opts);
|
|
954
|
-
return {
|
|
955
|
-
response: await executeRaw(retried),
|
|
956
|
-
prepared: retried
|
|
957
|
-
};
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
throw error;
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
function prepare(path, opts = {}) {
|
|
964
|
-
const method = opts.method ?? "GET";
|
|
965
|
-
const expectContentType = opts.expectContentType ?? "json";
|
|
966
|
-
const url = buildUrl(config.url, path, opts.query);
|
|
967
|
-
const headers = new Headers();
|
|
968
|
-
const auth = credentialAuthHeader(credential);
|
|
969
|
-
headers.set(auth.name, auth.value);
|
|
970
|
-
headers.set("accept", acceptHeader(expectContentType));
|
|
971
|
-
headers.set("user-agent", USER_AGENT);
|
|
972
|
-
let body = null;
|
|
973
|
-
if (opts.body !== void 0 && opts.body !== null) if (typeof opts.body === "string" || opts.body instanceof URLSearchParams) body = opts.body;
|
|
974
|
-
else if (opts.body instanceof FormData || opts.body instanceof ReadableStream) body = opts.body;
|
|
975
|
-
else if (opts.body instanceof Uint8Array) {
|
|
976
|
-
body = opts.body;
|
|
977
|
-
headers.set("content-type", OCTET_STREAM_CONTENT_TYPE);
|
|
978
|
-
} else {
|
|
979
|
-
body = JSON.stringify(opts.body);
|
|
980
|
-
headers.set("content-type", JSON_CONTENT_TYPE);
|
|
981
|
-
}
|
|
982
|
-
return {
|
|
983
|
-
url,
|
|
984
|
-
method,
|
|
985
|
-
headers,
|
|
986
|
-
body,
|
|
987
|
-
expectContentType,
|
|
988
|
-
retries: opts.retries ?? DEFAULT_MAX_RETRIES,
|
|
989
|
-
idempotent: opts.idempotent ?? IDEMPOTENT_METHODS.has(method),
|
|
990
|
-
timeoutMs: opts.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
991
|
-
callerSignal: opts.signal
|
|
992
|
-
};
|
|
993
|
-
}
|
|
994
|
-
return {
|
|
995
|
-
async requestRaw(path, opts) {
|
|
996
|
-
return (await executeWithAuthRefresh(path, opts ?? {})).response;
|
|
997
|
-
},
|
|
998
|
-
async requestParsed(schema, path, opts) {
|
|
999
|
-
const { response, prepared } = await executeWithAuthRefresh(path, {
|
|
1000
|
-
...opts,
|
|
1001
|
-
expectContentType: "json"
|
|
1002
|
-
});
|
|
1003
|
-
const text = await response.text();
|
|
1004
|
-
try {
|
|
1005
|
-
return parseJson(text, schema, { source: prepared.url });
|
|
1006
|
-
} catch (error) {
|
|
1007
|
-
if (error instanceof ValidationError) throw new ResponseShapeError({
|
|
1008
|
-
method: prepared.method,
|
|
1009
|
-
url: prepared.url,
|
|
1010
|
-
status: response.status,
|
|
1011
|
-
zodIssues: error.developerDetail.zodIssues,
|
|
1012
|
-
serverTag: await getServerTag()
|
|
1013
|
-
});
|
|
1014
|
-
throw error;
|
|
1015
|
-
}
|
|
1016
|
-
},
|
|
1017
|
-
async requestStream(path, opts) {
|
|
1018
|
-
const { response, prepared } = await executeWithAuthRefresh(path, {
|
|
1019
|
-
...opts,
|
|
1020
|
-
expectContentType: opts?.expectContentType ?? "binary"
|
|
1021
|
-
});
|
|
1022
|
-
if (!response.body) throw new NetworkError("Response had no body to stream", {
|
|
1023
|
-
method: prepared.method,
|
|
1024
|
-
url: prepared.url,
|
|
1025
|
-
cause: "missing body"
|
|
1026
|
-
});
|
|
1027
|
-
return response.body;
|
|
1028
|
-
}
|
|
1029
|
-
};
|
|
1030
|
-
}
|
|
1031
|
-
function buildUrl(baseUrl, path, query) {
|
|
1032
|
-
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
1033
|
-
const target = new URL(baseUrl + normalizedPath);
|
|
1034
|
-
if (query) for (const [key, value] of Object.entries(query)) {
|
|
1035
|
-
if (value === void 0) continue;
|
|
1036
|
-
if (Array.isArray(value)) for (const entry of value) target.searchParams.append(key, String(entry));
|
|
1037
|
-
else target.searchParams.append(key, String(value));
|
|
1038
|
-
}
|
|
1039
|
-
return target.toString();
|
|
1040
|
-
}
|
|
1041
|
-
function acceptHeader(expected) {
|
|
1042
|
-
if (expected === "json") return JSON_CONTENT_TYPE;
|
|
1043
|
-
if (expected === "text") return "text/*";
|
|
1044
|
-
return "*/*";
|
|
1045
|
-
}
|
|
1046
|
-
function assertContentType(response, prepared) {
|
|
1047
|
-
if (prepared.expectContentType === "binary") return;
|
|
1048
|
-
const contentType = response.headers.get("content-type");
|
|
1049
|
-
if (contentType === null) throwContentTypeMismatch(response, prepared, prepared.expectContentType);
|
|
1050
|
-
if (prepared.expectContentType === "json" && !contentType.includes(JSON_CONTENT_TYPE)) throwContentTypeMismatch(response, prepared, "json");
|
|
1051
|
-
if (prepared.expectContentType === "text" && !contentType.startsWith(TEXT_CONTENT_TYPE_PREFIX)) throwContentTypeMismatch(response, prepared, "text");
|
|
1052
|
-
}
|
|
1053
|
-
function throwContentTypeMismatch(response, prepared, expected) {
|
|
1054
|
-
const actual = response.headers.get("content-type") ?? "no content-type";
|
|
1055
|
-
throw new HttpError({
|
|
1056
|
-
status: response.status,
|
|
1057
|
-
statusText: response.statusText,
|
|
1058
|
-
method: prepared.method,
|
|
1059
|
-
url: prepared.url,
|
|
1060
|
-
responseHeaders: response.headers,
|
|
1061
|
-
rawBody: null,
|
|
1062
|
-
overrideUserMessage: `Expected ${expected} response but got ${actual}`
|
|
1063
|
-
});
|
|
1064
|
-
}
|
|
1065
|
-
async function readBodyForError(response) {
|
|
1066
|
-
try {
|
|
1067
|
-
const buffer = Buffer.from(await response.arrayBuffer());
|
|
1068
|
-
return buffer.subarray(0, ERROR_BODY_BYTE_CAP).toString("utf8");
|
|
1069
|
-
} catch (error) {
|
|
1070
|
-
return `[body read failed: ${errorMessage(error)}]`;
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
//#endregion
|
|
1075
|
-
//#region src/core/http/oauth.ts
|
|
1076
|
-
const DISCOVERY_PATH = "/.well-known/oauth-authorization-server";
|
|
1077
|
-
const FORM_CONTENT_TYPE = "application/x-www-form-urlencoded";
|
|
1078
|
-
const OAUTH_TIMEOUT_MS = 3e4;
|
|
1079
|
-
async function oauthFetch(request) {
|
|
1080
|
-
const timeoutSignal = AbortSignal.timeout(OAUTH_TIMEOUT_MS);
|
|
1081
|
-
try {
|
|
1082
|
-
return await fetch(request.url, {
|
|
1083
|
-
method: request.method,
|
|
1084
|
-
headers: {
|
|
1085
|
-
...request.headers,
|
|
1086
|
-
"user-agent": USER_AGENT
|
|
1087
|
-
},
|
|
1088
|
-
...request.body !== void 0 ? { body: request.body } : {},
|
|
1089
|
-
signal: timeoutSignal
|
|
1090
|
-
});
|
|
1091
|
-
} catch (error) {
|
|
1092
|
-
if (timeoutSignal.aborted) throw new TimeoutError(`OAuth request timed out after ${OAUTH_TIMEOUT_MS}ms`, {
|
|
1093
|
-
kind: "http",
|
|
1094
|
-
method: request.method,
|
|
1095
|
-
url: request.url,
|
|
1096
|
-
timeoutMs: OAUTH_TIMEOUT_MS
|
|
1097
|
-
});
|
|
1098
|
-
throw buildNetworkError(error, request.method, request.url);
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
const OAUTH_SCOPE = "mb:full";
|
|
1102
|
-
const OAuthServerMetadata = z.object({
|
|
1103
|
-
issuer: z.string(),
|
|
1104
|
-
authorization_endpoint: z.string(),
|
|
1105
|
-
token_endpoint: z.string(),
|
|
1106
|
-
registration_endpoint: z.string().optional(),
|
|
1107
|
-
revocation_endpoint: z.string().optional(),
|
|
1108
|
-
scopes_supported: z.array(z.string()).optional()
|
|
1109
|
-
}).loose();
|
|
1110
|
-
const RegisteredClient = z.object({ client_id: z.string() }).loose();
|
|
1111
|
-
const OAuthTokens = z.object({
|
|
1112
|
-
access_token: z.string(),
|
|
1113
|
-
token_type: z.string(),
|
|
1114
|
-
expires_in: z.number().int().optional(),
|
|
1115
|
-
refresh_token: z.string().optional()
|
|
1116
|
-
}).loose();
|
|
1117
|
-
const OAuthErrorBody = z.object({
|
|
1118
|
-
error: z.string(),
|
|
1119
|
-
error_description: z.string().optional()
|
|
1120
|
-
}).loose();
|
|
1121
|
-
async function readJson(response, schema, source) {
|
|
1122
|
-
let raw;
|
|
1123
|
-
try {
|
|
1124
|
-
raw = await response.json();
|
|
1125
|
-
} catch (error) {
|
|
1126
|
-
throw new ConfigError(`${source}: invalid JSON response (${errorMessage(error)})`);
|
|
1127
|
-
}
|
|
1128
|
-
const parsed = schema.safeParse(raw);
|
|
1129
|
-
if (!parsed.success) throw new ConfigError(`${source}: unexpected response shape`);
|
|
1130
|
-
return parsed.data;
|
|
1131
|
-
}
|
|
1132
|
-
async function failure(response, source, method, url) {
|
|
1133
|
-
const rawBody = await response.text().catch(() => "");
|
|
1134
|
-
if (isRetryableStatus(response.status)) return new HttpError({
|
|
1135
|
-
status: response.status,
|
|
1136
|
-
statusText: response.statusText,
|
|
1137
|
-
method,
|
|
1138
|
-
url,
|
|
1139
|
-
responseHeaders: response.headers,
|
|
1140
|
-
rawBody
|
|
1141
|
-
});
|
|
1142
|
-
const parsed = parseJsonResult(rawBody, OAuthErrorBody);
|
|
1143
|
-
if (parsed.ok) {
|
|
1144
|
-
const detail = parsed.value.error_description ?? parsed.value.error;
|
|
1145
|
-
return new ConfigError(`${source} failed (${response.status}): ${detail}`);
|
|
1146
|
-
}
|
|
1147
|
-
return new ConfigError(`${source} failed (${response.status})`);
|
|
1148
|
-
}
|
|
1149
|
-
async function postForm(url, params, schema, source) {
|
|
1150
|
-
const response = await oauthFetch({
|
|
1151
|
-
url,
|
|
1152
|
-
method: "POST",
|
|
1153
|
-
headers: {
|
|
1154
|
-
"content-type": FORM_CONTENT_TYPE,
|
|
1155
|
-
accept: JSON_CONTENT_TYPE
|
|
1156
|
-
},
|
|
1157
|
-
body: new URLSearchParams(params)
|
|
1158
|
-
});
|
|
1159
|
-
if (!response.ok) throw await failure(response, source, "POST", url);
|
|
1160
|
-
return readJson(response, schema, source);
|
|
1161
|
-
}
|
|
1162
|
-
const OAUTH_UNSUPPORTED_MESSAGE = "this Metabase does not support OAuth login (requires Metabase v63 or newer)";
|
|
1163
|
-
async function tryDiscoverMetadata(baseUrl) {
|
|
1164
|
-
const url = `${baseUrl}${DISCOVERY_PATH}`;
|
|
1165
|
-
const response = await oauthFetch({
|
|
1166
|
-
url,
|
|
1167
|
-
method: "GET",
|
|
1168
|
-
headers: { accept: JSON_CONTENT_TYPE }
|
|
1169
|
-
});
|
|
1170
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
1171
|
-
if (!response.ok || !contentType.includes("json")) {
|
|
1172
|
-
await response.body?.cancel().catch(() => void 0);
|
|
1173
|
-
return null;
|
|
1174
|
-
}
|
|
1175
|
-
const metadata = await readJson(response, OAuthServerMetadata, "OAuth discovery");
|
|
1176
|
-
const scopes = metadata.scopes_supported;
|
|
1177
|
-
if (scopes !== void 0 && !scopes.includes(OAUTH_SCOPE)) return null;
|
|
1178
|
-
assertEndpointOrigin(metadata.issuer, baseUrl, "issuer");
|
|
1179
|
-
assertEndpointOrigin(metadata.authorization_endpoint, baseUrl, "authorization endpoint");
|
|
1180
|
-
assertEndpointOrigin(metadata.token_endpoint, baseUrl, "token endpoint");
|
|
1181
|
-
if (metadata.registration_endpoint !== void 0) assertEndpointOrigin(metadata.registration_endpoint, baseUrl, "registration endpoint");
|
|
1182
|
-
if (metadata.revocation_endpoint !== void 0) assertEndpointOrigin(metadata.revocation_endpoint, baseUrl, "revocation endpoint");
|
|
1183
|
-
return metadata;
|
|
1184
|
-
}
|
|
1185
|
-
async function discoverMetadata(baseUrl) {
|
|
1186
|
-
const metadata = await tryDiscoverMetadata(baseUrl);
|
|
1187
|
-
if (metadata === null) throw new ConfigError(OAUTH_UNSUPPORTED_MESSAGE);
|
|
1188
|
-
return metadata;
|
|
1189
|
-
}
|
|
1190
|
-
async function registerClient(input) {
|
|
1191
|
-
const response = await oauthFetch({
|
|
1192
|
-
url: input.registrationEndpoint,
|
|
1193
|
-
method: "POST",
|
|
1194
|
-
headers: {
|
|
1195
|
-
"content-type": JSON_CONTENT_TYPE,
|
|
1196
|
-
accept: JSON_CONTENT_TYPE
|
|
1197
|
-
},
|
|
1198
|
-
body: JSON.stringify({
|
|
1199
|
-
application_type: "native",
|
|
1200
|
-
client_name: input.clientName,
|
|
1201
|
-
redirect_uris: [input.redirectUri],
|
|
1202
|
-
grant_types: ["authorization_code", "refresh_token"],
|
|
1203
|
-
response_types: ["code"],
|
|
1204
|
-
token_endpoint_auth_method: "none",
|
|
1205
|
-
scope: OAUTH_SCOPE
|
|
1206
|
-
})
|
|
1207
|
-
});
|
|
1208
|
-
if (!response.ok) throw await failure(response, "OAuth client registration", "POST", input.registrationEndpoint);
|
|
1209
|
-
return readJson(response, RegisteredClient, "OAuth client registration");
|
|
1210
|
-
}
|
|
1211
|
-
function exchangeCode(input) {
|
|
1212
|
-
return postForm(input.tokenEndpoint, {
|
|
1213
|
-
grant_type: "authorization_code",
|
|
1214
|
-
code: input.code,
|
|
1215
|
-
redirect_uri: input.redirectUri,
|
|
1216
|
-
client_id: input.clientId,
|
|
1217
|
-
code_verifier: input.codeVerifier
|
|
1218
|
-
}, OAuthTokens, "OAuth token exchange");
|
|
1219
|
-
}
|
|
1220
|
-
function refreshTokens(input) {
|
|
1221
|
-
return postForm(input.tokenEndpoint, {
|
|
1222
|
-
grant_type: "refresh_token",
|
|
1223
|
-
refresh_token: input.refreshToken,
|
|
1224
|
-
client_id: input.clientId
|
|
1225
|
-
}, OAuthTokens, "OAuth token refresh");
|
|
1226
|
-
}
|
|
1227
|
-
async function revokeToken(input) {
|
|
1228
|
-
const response = await oauthFetch({
|
|
1229
|
-
url: input.revocationEndpoint,
|
|
1230
|
-
method: "POST",
|
|
1231
|
-
headers: { "content-type": FORM_CONTENT_TYPE },
|
|
1232
|
-
body: new URLSearchParams({
|
|
1233
|
-
token: input.token,
|
|
1234
|
-
client_id: input.clientId
|
|
1235
|
-
})
|
|
1236
|
-
});
|
|
1237
|
-
if (!response.ok) throw await failure(response, "OAuth token revocation", "POST", input.revocationEndpoint);
|
|
1238
|
-
await response.body?.cancel().catch(() => void 0);
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
//#endregion
|
|
1242
|
-
//#region src/core/auth/oauth-session.ts
|
|
1243
|
-
async function refreshOAuthCredential(baseUrl, credential, nowMs) {
|
|
1244
|
-
const metadata = await discoverMetadata(baseUrl);
|
|
1245
|
-
const tokens = await refreshTokens({
|
|
1246
|
-
tokenEndpoint: metadata.token_endpoint,
|
|
1247
|
-
refreshToken: credential.refreshToken,
|
|
1248
|
-
clientId: credential.clientId
|
|
1249
|
-
});
|
|
1250
|
-
return oauthCredentialFromTokens(tokens, tokens.refresh_token ?? credential.refreshToken, credential.clientId, nowMs);
|
|
1251
|
-
}
|
|
1252
|
-
async function revokeOAuthCredential(baseUrl, credential) {
|
|
1253
|
-
const metadata = await discoverMetadata(baseUrl);
|
|
1254
|
-
const revocationEndpoint = metadata.revocation_endpoint;
|
|
1255
|
-
if (revocationEndpoint === void 0) return false;
|
|
1256
|
-
await revokeToken({
|
|
1257
|
-
revocationEndpoint,
|
|
1258
|
-
token: credential.refreshToken,
|
|
1259
|
-
clientId: credential.clientId
|
|
1260
|
-
});
|
|
1261
|
-
await revokeToken({
|
|
1262
|
-
revocationEndpoint,
|
|
1263
|
-
token: credential.accessToken,
|
|
1264
|
-
clientId: credential.clientId
|
|
1265
|
-
});
|
|
1266
|
-
return true;
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
//#endregion
|
|
1270
|
-
//#region src/core/config.ts
|
|
1271
|
-
function isPreflightSkipped() {
|
|
1272
|
-
return readEnv(ENV_SKIP_PREFLIGHT) === "1";
|
|
1273
|
-
}
|
|
1274
|
-
function resolveProfileName(profileFlag) {
|
|
1275
|
-
return explicitProfileName(profileFlag) ?? DEFAULT_PROFILE;
|
|
1276
|
-
}
|
|
1277
|
-
function explicitProfileName(profileFlag) {
|
|
1278
|
-
return profileFlag || readEnv(ENV_PROFILE) || null;
|
|
1279
|
-
}
|
|
1280
|
-
function readEnvCredentials() {
|
|
1281
|
-
return {
|
|
1282
|
-
url: readEnv(ENV_URL) ?? null,
|
|
1283
|
-
apiKey: readEnv(ENV_API_KEY) ?? null
|
|
1284
|
-
};
|
|
1285
|
-
}
|
|
1286
|
-
async function resolveConfig(flags) {
|
|
1287
|
-
const profile = resolveProfileName(flags.profile);
|
|
1288
|
-
const env = readEnvCredentials();
|
|
1289
|
-
const hasUrl = Boolean(flags.url ?? env.url);
|
|
1290
|
-
const hasKey = Boolean(flags.apiKey ?? env.apiKey);
|
|
1291
|
-
const stored = hasUrl && hasKey ? null : await readProfileCredential(profile);
|
|
1292
|
-
const url = resolveUrl(flags.url, env.url, stored?.url);
|
|
1293
|
-
const credential = resolveCredential(flags.apiKey, env.apiKey, stored?.credential);
|
|
1294
|
-
if (url === null || credential === null) {
|
|
1295
|
-
const hint = await failureHintForProfile(profile);
|
|
1296
|
-
throw new ConfigError(`Not authenticated for profile "${profile}". Run \`mb auth login\`, set ${ENV_URL}/${ENV_API_KEY}, or pass --url/--api-key.${hint}`);
|
|
1297
|
-
}
|
|
1298
|
-
const normalizedUrl = normalizeUrl(url.value);
|
|
1299
|
-
assertOAuthUrlMatchesIssuer(credential.credential, stored?.url, normalizedUrl, profile);
|
|
1300
|
-
const fresh = await ensureFreshCredential(profile, credential.credential, stored?.url);
|
|
1301
|
-
return {
|
|
1302
|
-
url: normalizedUrl,
|
|
1303
|
-
credential: fresh,
|
|
1304
|
-
profile,
|
|
1305
|
-
source: url.source === credential.source ? url.source : "mixed"
|
|
1306
|
-
};
|
|
1307
|
-
}
|
|
1308
|
-
function assertOAuthUrlMatchesIssuer(credential, issuerUrl, requestUrl, profile) {
|
|
1309
|
-
if (credential.kind !== "oauth" || issuerUrl === void 0) return;
|
|
1310
|
-
const issuer = normalizeUrl(issuerUrl);
|
|
1311
|
-
if (issuer === requestUrl) return;
|
|
1312
|
-
throw new ConfigError(`profile "${profile}" is a browser-login (OAuth) profile bound to ${issuer}, but the request URL is ${requestUrl}. Drop --url/${ENV_URL} to use the profile's own URL, or run \`mb auth login --url ${requestUrl}\` to authenticate there.`);
|
|
1313
|
-
}
|
|
1314
|
-
async function ensureFreshCredential(profile, credential, issuerUrl) {
|
|
1315
|
-
if (credential.kind !== "oauth" || issuerUrl === void 0) return credential;
|
|
1316
|
-
if (!isOAuthExpired(credential, Date.now())) return credential;
|
|
1317
|
-
let refreshed;
|
|
1318
|
-
try {
|
|
1319
|
-
refreshed = await refreshOAuthCredential(issuerUrl, credential, Date.now());
|
|
1320
|
-
} catch {
|
|
1321
|
-
return credential;
|
|
1322
|
-
}
|
|
1323
|
-
await persistRefreshed(profile, issuerUrl, refreshed);
|
|
1324
|
-
return refreshed;
|
|
1325
|
-
}
|
|
1326
|
-
async function refreshAndPersist(profile, issuerUrl, credential) {
|
|
1327
|
-
const refreshed = await refreshOAuthCredential(issuerUrl, credential, Date.now());
|
|
1328
|
-
await persistRefreshed(profile, issuerUrl, refreshed);
|
|
1329
|
-
return refreshed;
|
|
1330
|
-
}
|
|
1331
|
-
async function persistRefreshed(profile, issuerUrl, refreshed) {
|
|
1332
|
-
await writeOAuthProfile(issuerUrl, refreshed, profile);
|
|
1333
|
-
}
|
|
1334
|
-
function createCredentialRefresher(profile) {
|
|
1335
|
-
return async () => {
|
|
1336
|
-
const stored = await readProfileCredential(profile);
|
|
1337
|
-
if (stored === null || stored.credential.kind !== "oauth") return null;
|
|
1338
|
-
try {
|
|
1339
|
-
return await refreshAndPersist(profile, stored.url, stored.credential);
|
|
1340
|
-
} catch (error) {
|
|
1341
|
-
if (error instanceof ConfigError) throw new ConfigError(`${error.message} — run \`mb auth login --profile ${profile}\` to log in again`);
|
|
1342
|
-
throw error;
|
|
1343
|
-
}
|
|
1344
|
-
};
|
|
1345
|
-
}
|
|
1346
|
-
async function failureHintForProfile(profile) {
|
|
1347
|
-
const record = await readProfileRecord(profile);
|
|
1348
|
-
if (record === null || record.lastFailure === null) return "";
|
|
1349
|
-
if (record.lastProbe !== null && record.lastProbe.at >= record.lastFailure.at) return "";
|
|
1350
|
-
return ` profile "${profile}" last verify failed: ${record.lastFailure.reason}. Run \`mb auth login --profile ${profile}\` to update the token.`;
|
|
1351
|
-
}
|
|
1352
|
-
function resolveUrl(flag, env, stored) {
|
|
1353
|
-
if (flag) return {
|
|
1354
|
-
value: flag,
|
|
1355
|
-
source: "flag"
|
|
1356
|
-
};
|
|
1357
|
-
if (env) return {
|
|
1358
|
-
value: env,
|
|
1359
|
-
source: "env"
|
|
1360
|
-
};
|
|
1361
|
-
if (stored) return {
|
|
1362
|
-
value: stored,
|
|
1363
|
-
source: "stored"
|
|
1364
|
-
};
|
|
1365
|
-
return null;
|
|
1366
|
-
}
|
|
1367
|
-
function resolveCredential(flagKey, envKey, stored) {
|
|
1368
|
-
if (flagKey) return {
|
|
1369
|
-
credential: {
|
|
1370
|
-
kind: "apiKey",
|
|
1371
|
-
apiKey: flagKey
|
|
1372
|
-
},
|
|
1373
|
-
source: "flag"
|
|
1374
|
-
};
|
|
1375
|
-
if (envKey) return {
|
|
1376
|
-
credential: {
|
|
1377
|
-
kind: "apiKey",
|
|
1378
|
-
apiKey: envKey
|
|
1379
|
-
},
|
|
1380
|
-
source: "env"
|
|
1381
|
-
};
|
|
1382
|
-
if (stored) return {
|
|
1383
|
-
credential: stored,
|
|
1384
|
-
source: "stored"
|
|
1385
|
-
};
|
|
1386
|
-
return null;
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
|
-
//#endregion
|
|
1390
|
-
//#region src/core/version/capabilities.ts
|
|
1391
|
-
function mergeCapabilities(overrides) {
|
|
1392
|
-
if (overrides === void 0) return BASELINE_CAPABILITIES;
|
|
1393
|
-
return {
|
|
1394
|
-
minVersion: overrides.minVersion ?? BASELINE_CAPABILITIES.minVersion,
|
|
1395
|
-
...overrides.tokenFeature === void 0 ? {} : { tokenFeature: overrides.tokenFeature }
|
|
1396
|
-
};
|
|
1397
|
-
}
|
|
1398
|
-
function checkCapabilities(info, required) {
|
|
1399
|
-
if (info.version === null) return {
|
|
1400
|
-
reason: "unknown-version",
|
|
1401
|
-
detail: "Could not detect Metabase server version. Proceeding without preflight check; failures may produce confusing errors."
|
|
1402
|
-
};
|
|
1403
|
-
if (info.version.major < required.minVersion) return {
|
|
1404
|
-
reason: "version-too-old",
|
|
1405
|
-
detail: `This command requires Metabase v${required.minVersion}+ (this server is ${info.version.tag}). Upgrade Metabase or pin mb-cli to an older release.`
|
|
1406
|
-
};
|
|
1407
|
-
if (required.tokenFeature !== void 0) {
|
|
1408
|
-
const enabled = info.tokenFeatures?.[required.tokenFeature] === true;
|
|
1409
|
-
if (!enabled) return {
|
|
1410
|
-
reason: "missing-token-feature",
|
|
1411
|
-
detail: `This command requires the '${required.tokenFeature}' premium feature (not enabled on this server).`
|
|
1412
|
-
};
|
|
1413
|
-
}
|
|
1414
|
-
return null;
|
|
1415
|
-
}
|
|
1416
|
-
|
|
1417
|
-
//#endregion
|
|
1418
|
-
//#region src/core/version/preflight-error.ts
|
|
1419
|
-
var CapabilityError = class extends MetabaseError {
|
|
1420
|
-
category = "capability";
|
|
1421
|
-
isRetryable = false;
|
|
1422
|
-
exitCode = 2;
|
|
1423
|
-
developerDetail;
|
|
1424
|
-
constructor(failure$1) {
|
|
1425
|
-
super(failure$1.detail);
|
|
1426
|
-
this.name = "CapabilityError";
|
|
1427
|
-
this.developerDetail = failure$1;
|
|
1428
|
-
}
|
|
1429
|
-
};
|
|
1430
|
-
|
|
1431
|
-
//#endregion
|
|
1432
|
-
//#region src/core/version/probe.ts
|
|
1433
|
-
const PROBE_PATH = "/api/session/properties";
|
|
1434
|
-
const PROBE_TIMEOUT_MS = 1e4;
|
|
1435
|
-
async function probeServer(client, opts = {}) {
|
|
1436
|
-
const properties = await client.requestParsed(SessionProperties, PROBE_PATH, {
|
|
1437
|
-
timeoutMs: PROBE_TIMEOUT_MS,
|
|
1438
|
-
retries: opts.retries ?? 0
|
|
1439
|
-
});
|
|
1440
|
-
const version = tryParseTag(properties.version.tag);
|
|
1441
|
-
return {
|
|
1442
|
-
version,
|
|
1443
|
-
tokenFeatures: properties["token-features"] ?? null
|
|
1444
|
-
};
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
//#endregion
|
|
1448
|
-
//#region src/output/format.ts
|
|
1449
|
-
function resolveFormat({ json, format, isTty }) {
|
|
1450
|
-
const explicit = format !== void 0 && format !== "auto" ? format : null;
|
|
1451
|
-
if (explicit !== null && explicit !== "json" && explicit !== "text") throw new ConfigError(`invalid --format value: "${explicit}" (expected: auto, json, text)`);
|
|
1452
|
-
if (json && explicit !== null && explicit !== "json") throw new ConfigError(`--json conflicts with --format ${explicit}`);
|
|
1453
|
-
if (json) return "json";
|
|
1454
|
-
if (explicit !== null) return explicit;
|
|
1455
|
-
return isTty ? "text" : "json";
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1458
|
-
//#endregion
|
|
1459
|
-
//#region src/runtime/csv.ts
|
|
1460
|
-
function parseCsv(raw) {
|
|
1461
|
-
return raw.split(",").map((part) => part.trim()).filter((part) => part.length > 0);
|
|
1462
|
-
}
|
|
1463
|
-
function parseEnumCsv(raw, schema, flagName) {
|
|
1464
|
-
if (raw === void 0 || raw === "") return void 0;
|
|
1465
|
-
const parts = parseCsv(raw);
|
|
1466
|
-
if (parts.length === 0) return void 0;
|
|
1467
|
-
const accepted = [];
|
|
1468
|
-
const rejected = [];
|
|
1469
|
-
for (const part of parts) {
|
|
1470
|
-
const result = schema.safeParse(part);
|
|
1471
|
-
if (result.success) accepted.push(result.data);
|
|
1472
|
-
else rejected.push(part);
|
|
1473
|
-
}
|
|
1474
|
-
if (rejected.length > 0) {
|
|
1475
|
-
const allowed = Object.values(schema.enum).join(", ");
|
|
1476
|
-
throw new ConfigError(`invalid ${flagName} value: ${rejected.join(", ")} (expected one of: ${allowed})`);
|
|
1477
|
-
}
|
|
1478
|
-
return accepted;
|
|
1479
|
-
}
|
|
1480
|
-
function parseEnum(raw, schema, flagName) {
|
|
1481
|
-
if (raw === void 0 || raw === "") return void 0;
|
|
1482
|
-
const result = schema.safeParse(raw);
|
|
1483
|
-
if (!result.success) {
|
|
1484
|
-
const allowed = Object.values(schema.enum).join(", ");
|
|
1485
|
-
throw new ConfigError(`invalid ${flagName} value: "${raw}" (expected one of: ${allowed})`);
|
|
1486
|
-
}
|
|
1487
|
-
return result.data;
|
|
1488
|
-
}
|
|
1489
|
-
|
|
1490
|
-
//#endregion
|
|
1491
|
-
//#region src/commands/context.ts
|
|
1492
|
-
function resolveCommonFlags(args, options = {}) {
|
|
1493
|
-
const isTty = options.isTty ?? Boolean(process.stdout.isTTY);
|
|
1494
|
-
const fields = parseFields(args.fields);
|
|
1495
|
-
const full = args.full === true;
|
|
1496
|
-
if (full && fields !== void 0) throw new ConfigError("--full conflicts with --fields (use one or neither)");
|
|
1497
|
-
return {
|
|
1498
|
-
format: resolveFormat({
|
|
1499
|
-
json: args.json,
|
|
1500
|
-
format: args.format,
|
|
1501
|
-
isTty
|
|
1502
|
-
}),
|
|
1503
|
-
full,
|
|
1504
|
-
fields,
|
|
1505
|
-
maxBytes: parseMaxBytes(args.maxBytes),
|
|
1506
|
-
url: args.url,
|
|
1507
|
-
apiKey: args.apiKey,
|
|
1508
|
-
profile: args.profile,
|
|
1509
|
-
skipPreflight: args.skipPreflight === true
|
|
1510
|
-
};
|
|
1511
|
-
}
|
|
1512
|
-
function parseFields(value) {
|
|
1513
|
-
if (value === void 0 || value === "") return void 0;
|
|
1514
|
-
const parts = parseCsv(value);
|
|
1515
|
-
return parts.length > 0 ? parts : void 0;
|
|
1516
|
-
}
|
|
1517
|
-
function parseMaxBytes(value) {
|
|
1518
|
-
return parseInteger(value ?? String(DEFAULT_MAX_BYTES), {
|
|
1519
|
-
name: "--max-bytes",
|
|
1520
|
-
min: 0
|
|
1521
|
-
});
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
|
-
//#endregion
|
|
1525
|
-
//#region src/commands/known-flags.ts
|
|
1526
|
-
const ARGUMENT_SEPARATOR = "--";
|
|
1527
|
-
const NEGATION_PREFIX = "no-";
|
|
1528
|
-
const BUILTIN_FLAGS = [
|
|
1529
|
-
"help",
|
|
1530
|
-
"h",
|
|
1531
|
-
"version",
|
|
1532
|
-
"v"
|
|
1533
|
-
];
|
|
1534
|
-
function assertKnownFlags(rawArgs, argsDef) {
|
|
1535
|
-
const allowed = allowedFlagKeys(argsDef);
|
|
1536
|
-
let index = 0;
|
|
1537
|
-
while (index < rawArgs.length) {
|
|
1538
|
-
const token = rawArgs[index];
|
|
1539
|
-
if (token === void 0 || token === ARGUMENT_SEPARATOR) return;
|
|
1540
|
-
if (!isFlagToken(token)) {
|
|
1541
|
-
index += 1;
|
|
1542
|
-
continue;
|
|
1543
|
-
}
|
|
1544
|
-
const matched = flagCandidates(token).some((candidate) => allowed.has(candidate));
|
|
1545
|
-
if (!matched) throw new ConfigError(`unknown flag: ${displayFlag(token)}`);
|
|
1546
|
-
index += flagConsumesValue(token, argsDef) ? 2 : 1;
|
|
1547
|
-
}
|
|
1548
|
-
}
|
|
1549
|
-
function allowedFlagKeys(argsDef) {
|
|
1550
|
-
const keys = new Set(BUILTIN_FLAGS.map(normalizeFlag));
|
|
1551
|
-
for (const [name, def] of Object.entries(argsDef)) {
|
|
1552
|
-
keys.add(normalizeFlag(name));
|
|
1553
|
-
if ("alias" in def) for (const alias of toAliasArray(def.alias)) keys.add(normalizeFlag(alias));
|
|
1554
|
-
}
|
|
1555
|
-
return keys;
|
|
1556
|
-
}
|
|
1557
|
-
function isFlagToken(token) {
|
|
1558
|
-
return token.startsWith("-") && token !== "-";
|
|
1559
|
-
}
|
|
1560
|
-
function displayFlag(token) {
|
|
1561
|
-
const equals = token.indexOf("=");
|
|
1562
|
-
return equals === -1 ? token : token.slice(0, equals);
|
|
1563
|
-
}
|
|
1564
|
-
function flagCandidates(token) {
|
|
1565
|
-
const name = displayFlag(token).replace(/^-+/, "");
|
|
1566
|
-
const candidates = [normalizeFlag(name)];
|
|
1567
|
-
if (name.startsWith(NEGATION_PREFIX)) candidates.push(normalizeFlag(name.slice(NEGATION_PREFIX.length)));
|
|
1568
|
-
return candidates;
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
//#endregion
|
|
1572
|
-
//#region src/commands/runtime.ts
|
|
1573
|
-
function defineMetabaseCommand(def) {
|
|
1574
|
-
const required = def.capabilities === null ? null : mergeCapabilities(def.capabilities);
|
|
1575
|
-
const cmd = defineCommand({
|
|
1576
|
-
meta: def.meta,
|
|
1577
|
-
args: def.args,
|
|
1578
|
-
async run({ args, rawArgs }) {
|
|
1579
|
-
let reportFormat;
|
|
1580
|
-
try {
|
|
1581
|
-
const ctx = resolveCommonFlags(pickCommonArgs(args));
|
|
1582
|
-
reportFormat = ctx.format;
|
|
1583
|
-
assertKnownFlags(rawArgs, def.args);
|
|
1584
|
-
let cachedConfig = null;
|
|
1585
|
-
let cachedClient = null;
|
|
1586
|
-
let cachedServerInfo = null;
|
|
1587
|
-
const getResolvedConfig = async () => {
|
|
1588
|
-
if (cachedConfig === null) cachedConfig = await resolveConfig(buildConfigFlags(ctx));
|
|
1589
|
-
return cachedConfig;
|
|
1590
|
-
};
|
|
1591
|
-
const getServerInfo = () => {
|
|
1592
|
-
if (cachedServerInfo === null) cachedServerInfo = loadServerInfo(getResolvedConfig);
|
|
1593
|
-
return cachedServerInfo;
|
|
1594
|
-
};
|
|
1595
|
-
const rawGetClient = async () => {
|
|
1596
|
-
if (cachedClient === null) {
|
|
1597
|
-
const resolved = await getResolvedConfig();
|
|
1598
|
-
cachedClient = createClient({
|
|
1599
|
-
url: resolved.url,
|
|
1600
|
-
credential: resolved.credential
|
|
1601
|
-
}, {
|
|
1602
|
-
getServerTag: async () => (await getServerInfo())?.version?.tag ?? null,
|
|
1603
|
-
refreshCredential: createCredentialRefresher(resolved.profile)
|
|
1604
|
-
});
|
|
1605
|
-
}
|
|
1606
|
-
return cachedClient;
|
|
1607
|
-
};
|
|
1608
|
-
const enforcePreflight = createPreflightEnforcer(required, getServerInfo, ctx.skipPreflight);
|
|
1609
|
-
const getClient = async () => {
|
|
1610
|
-
const client = await rawGetClient();
|
|
1611
|
-
await enforcePreflight();
|
|
1612
|
-
return client;
|
|
1613
|
-
};
|
|
1614
|
-
try {
|
|
1615
|
-
await def.run({
|
|
1616
|
-
args,
|
|
1617
|
-
ctx,
|
|
1618
|
-
getClient,
|
|
1619
|
-
getResolvedConfig,
|
|
1620
|
-
getServerInfo
|
|
1621
|
-
});
|
|
1622
|
-
} finally {
|
|
1623
|
-
emitPendingWarnings();
|
|
1624
|
-
}
|
|
1625
|
-
} catch (error) {
|
|
1626
|
-
reportError(error, reportFormat);
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
|
-
});
|
|
1630
|
-
setMetabaseAugment(cmd, {
|
|
1631
|
-
examples: def.examples ?? [],
|
|
1632
|
-
details: def.details ? def.details : null,
|
|
1633
|
-
skills: def.skills ?? [],
|
|
1634
|
-
inputSchema: def.inputSchema ?? null,
|
|
1635
|
-
outputSchema: def.outputSchema ?? null,
|
|
1636
|
-
capabilities: required
|
|
1637
|
-
});
|
|
1638
|
-
return cmd;
|
|
1639
|
-
}
|
|
1640
|
-
function emitPendingWarnings() {
|
|
1641
|
-
for (const message of consumeLegacyEnvWarnings()) warn(message);
|
|
1642
|
-
const legacy = consumeLegacyStorageWarning();
|
|
1643
|
-
if (legacy !== null) warn(legacy);
|
|
1644
|
-
const downgrade = consumeKeyringDowngradeWarning();
|
|
1645
|
-
if (downgrade !== null) warn(downgrade);
|
|
1646
|
-
}
|
|
1647
|
-
async function loadServerInfo(getResolvedConfig) {
|
|
1648
|
-
const resolved = await getResolvedConfig();
|
|
1649
|
-
const record = await readProfileRecord(resolved.profile);
|
|
1650
|
-
if (record === null || record.lastProbe === null) return null;
|
|
1651
|
-
return {
|
|
1652
|
-
version: record.lastProbe.version,
|
|
1653
|
-
tokenFeatures: record.lastProbe.tokenFeatures
|
|
1654
|
-
};
|
|
1655
|
-
}
|
|
1656
|
-
const NO_OP_ENFORCER = async () => {};
|
|
1657
|
-
const NO_PROBE_DATA_WARNING = "Could not detect Metabase server version. Proceeding without preflight check; failures may produce confusing errors. Run `mb auth list` (or `mb auth login`) to populate the version cache.";
|
|
1658
|
-
function createPreflightEnforcer(required, getServerInfo, skip) {
|
|
1659
|
-
if (required === null || skip || isPreflightSkipped() || isBaseline(required)) return NO_OP_ENFORCER;
|
|
1660
|
-
let done = false;
|
|
1661
|
-
return async () => {
|
|
1662
|
-
if (done) return;
|
|
1663
|
-
done = true;
|
|
1664
|
-
const info = await getServerInfo();
|
|
1665
|
-
if (info === null) {
|
|
1666
|
-
warn(NO_PROBE_DATA_WARNING);
|
|
1667
|
-
return;
|
|
1668
|
-
}
|
|
1669
|
-
const failure$1 = checkCapabilities(info, required);
|
|
1670
|
-
if (failure$1 === null || failure$1.reason === "unknown-version") return;
|
|
1671
|
-
throw new CapabilityError(failure$1);
|
|
1672
|
-
};
|
|
1673
|
-
}
|
|
1674
|
-
function isBaseline(caps) {
|
|
1675
|
-
return caps.minVersion === BASELINE_CAPABILITIES.minVersion && caps.tokenFeature === void 0;
|
|
1676
|
-
}
|
|
1677
|
-
function pickCommonArgs(args) {
|
|
1678
|
-
const out = {};
|
|
1679
|
-
if (typeof args["format"] === "string") out.format = args["format"];
|
|
1680
|
-
if (typeof args["json"] === "boolean") out.json = args["json"];
|
|
1681
|
-
if (typeof args["full"] === "boolean") out.full = args["full"];
|
|
1682
|
-
if (typeof args["fields"] === "string") out.fields = args["fields"];
|
|
1683
|
-
if (typeof args["maxBytes"] === "string") out.maxBytes = args["maxBytes"];
|
|
1684
|
-
if (typeof args["profile"] === "string") out.profile = args["profile"];
|
|
1685
|
-
if (typeof args["url"] === "string") out.url = args["url"];
|
|
1686
|
-
if (typeof args["apiKey"] === "string") out.apiKey = args["apiKey"];
|
|
1687
|
-
if (typeof args["skipPreflight"] === "boolean") out.skipPreflight = args["skipPreflight"];
|
|
1688
|
-
return out;
|
|
1689
|
-
}
|
|
1690
|
-
function buildConfigFlags(ctx) {
|
|
1691
|
-
const flags = {};
|
|
1692
|
-
if (ctx.profile !== void 0) flags.profile = ctx.profile;
|
|
1693
|
-
if (ctx.url !== void 0) flags.url = ctx.url;
|
|
1694
|
-
if (ctx.apiKey !== void 0) flags.apiKey = ctx.apiKey;
|
|
1695
|
-
return flags;
|
|
1696
|
-
}
|
|
1697
|
-
|
|
1698
|
-
//#endregion
|
|
1699
|
-
export { DEFAULT_PROFILE, HttpError, OAUTH_SCOPE, ParsedVersionSchema, ProbedUser, ProfileAuthMethod, ProfileLastFailure, TokenFeatures, USER_AGENT, clearProfile, combineAborts, consumeKeychainResidualWarning, consumeKeyringDowngradeWarning, createClient, createCredentialRefresher, defineMetabaseCommand, discoverMetadata, displayUrl, exchangeCode, explicitProfileName, keyringFallbackWarning, listProfileRecords, normalizeUrl, oauthCredentialFromTokens, parseCsv, parseEnum, parseEnumCsv, parseInteger, parseJson, parseJsonOrPlain, parseOptionalInteger, probeServer, profileAuthMethod, readEnvCredentials, readProfileCredential, readProfileRecord, registerClient, resolveProfileName, resolveRecordCredential, revokeOAuthCredential, throwIfAborted, tryDiscoverMetadata, writeOAuthProfile, writeProbeFailure, writeProbeResult, writeProfile };
|