tenjin-cli 0.1.0-alpha.15 → 0.1.0-alpha.17
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/NOTICE.md +54 -7
- package/README.md +43 -310
- package/dist/{_esm-N4KAVXQR.js → _esm-CE7KNONL.js} +9 -10
- package/dist/{ccip-ZGGWQN4X.js → ccip-7RMRLAGV.js} +4 -4
- package/dist/{ccip-RPPPKTJR.js → ccip-NLCSCHKI.js} +5 -5
- package/dist/chunk-2BKS2FVE.js +93 -0
- package/dist/chunk-2BKS2FVE.js.map +1 -0
- package/dist/chunk-2G2WLVHB.js +102 -0
- package/dist/chunk-2G2WLVHB.js.map +1 -0
- package/dist/chunk-2I4QTOLB.js +11 -0
- package/dist/chunk-2I4QTOLB.js.map +1 -0
- package/dist/chunk-2JGT3KDW.js +172 -0
- package/dist/chunk-2JGT3KDW.js.map +1 -0
- package/dist/chunk-2QYORQBF.js +55 -0
- package/dist/chunk-2QYORQBF.js.map +1 -0
- package/dist/chunk-35M3VITA.js +102 -0
- package/dist/chunk-35M3VITA.js.map +1 -0
- package/dist/{chunk-KINZ23CV.js → chunk-3AUDA53C.js} +4740 -23
- package/dist/chunk-3AUDA53C.js.map +1 -0
- package/dist/{chunk-MJZZTKCC.js → chunk-56MOAIP5.js} +5 -10
- package/dist/chunk-56MOAIP5.js.map +1 -0
- package/dist/{chunk-U5S527PP.js → chunk-5IEP5EGE.js} +3 -3
- package/dist/chunk-5QHHRMRA.js +227 -0
- package/dist/chunk-5QHHRMRA.js.map +1 -0
- package/dist/{chunk-JBIKAAT3.js → chunk-5UDD5VSY.js} +8 -8
- package/dist/chunk-5UDD5VSY.js.map +1 -0
- package/dist/chunk-7QKHZQKW.js +1680 -0
- package/dist/chunk-7QKHZQKW.js.map +1 -0
- package/dist/{chunk-ZFJJ3EXC.js → chunk-AR7U7BRG.js} +550 -182
- package/dist/chunk-AR7U7BRG.js.map +1 -0
- package/dist/chunk-AUKDYPPX.js +130 -0
- package/dist/chunk-AUKDYPPX.js.map +1 -0
- package/dist/{chunk-7FK2UN2T.js → chunk-AWQPGIR6.js} +65 -67
- package/dist/{chunk-7FK2UN2T.js.map → chunk-AWQPGIR6.js.map} +1 -1
- package/dist/{chunk-KYQVEKP5.js → chunk-BPMWXTFX.js} +8 -8
- package/dist/{chunk-47PP7TAG.js → chunk-EGELTSPU.js} +1356 -1356
- package/dist/chunk-EGELTSPU.js.map +1 -0
- package/dist/{chunk-S5RYMCV6.js → chunk-HPWO4O6S.js} +3 -3
- package/dist/chunk-J5INH7WB.js +299 -0
- package/dist/chunk-J5INH7WB.js.map +1 -0
- package/dist/chunk-JLEF5WHM.js +132 -0
- package/dist/chunk-JLEF5WHM.js.map +1 -0
- package/dist/{chunk-W6R3HAAG.js → chunk-JRGFKVAZ.js} +2 -2
- package/dist/{chunk-XJN5WUKL.js → chunk-KG3D7FIF.js} +2 -2
- package/dist/chunk-KK4YGYTV.js +808 -0
- package/dist/chunk-KK4YGYTV.js.map +1 -0
- package/dist/{chunk-CPCX67TI.js → chunk-KUBEYXSO.js} +1076 -1038
- package/dist/chunk-KUBEYXSO.js.map +1 -0
- package/dist/{chunk-QW2Q2KAH.js → chunk-LHHMV4GU.js} +2 -2
- package/dist/{chunk-NIKXHWOL.js → chunk-LJ4DMVFI.js} +16 -16
- package/dist/chunk-LJ4DMVFI.js.map +1 -0
- package/dist/{chunk-ZOBNS7CX.js → chunk-MEFB5KHA.js} +4 -18
- package/dist/chunk-MEFB5KHA.js.map +1 -0
- package/dist/{chunk-HPJGOLTN.js → chunk-MRGADYDD.js} +13 -8
- package/dist/chunk-MRGADYDD.js.map +1 -0
- package/dist/{chunk-M2O56UK7.js → chunk-N35E6CM2.js} +293 -163
- package/dist/chunk-N35E6CM2.js.map +1 -0
- package/dist/chunk-O4ZNKFRU.js +366 -0
- package/dist/chunk-O4ZNKFRU.js.map +1 -0
- package/dist/chunk-PDA2BVFY.js +244 -0
- package/dist/chunk-PDA2BVFY.js.map +1 -0
- package/dist/{chunk-POJRB2AE.js → chunk-POUWHWID.js} +2 -2
- package/dist/chunk-QDD2RN7G.js +10238 -0
- package/dist/chunk-QDD2RN7G.js.map +1 -0
- package/dist/chunk-S2NRVRPF.js +171 -0
- package/dist/chunk-S2NRVRPF.js.map +1 -0
- package/dist/chunk-TGLKKLQG.js +11 -0
- package/dist/chunk-TGLKKLQG.js.map +1 -0
- package/dist/chunk-TP4D47BY.js +127 -0
- package/dist/chunk-TP4D47BY.js.map +1 -0
- package/dist/{chunk-KZAAWQNP.js → chunk-TTNESUPQ.js} +3 -3
- package/dist/{chunk-UO22YNY4.js → chunk-U2DZISAH.js} +43 -1
- package/dist/chunk-U2DZISAH.js.map +1 -0
- package/dist/chunk-WGQVJM56.js +165 -0
- package/dist/chunk-WGQVJM56.js.map +1 -0
- package/dist/{chunk-OLWTRUTS.js → chunk-WLMJE3GJ.js} +35 -16
- package/dist/chunk-WLMJE3GJ.js.map +1 -0
- package/dist/chunk-WS4JA6TC.js +137 -0
- package/dist/chunk-WS4JA6TC.js.map +1 -0
- package/dist/chunk-WXC57XGG.js +29 -0
- package/dist/chunk-WXC57XGG.js.map +1 -0
- package/dist/{chunk-YLYINX2H.js → chunk-XZKD7DIF.js} +3 -3
- package/dist/chunk-XZOEUYMX.js +1784 -0
- package/dist/chunk-XZOEUYMX.js.map +1 -0
- package/dist/{cli-KKRKBU5T.js → cli-VHYYYYXM.js} +303 -374
- package/dist/cli-VHYYYYXM.js.map +1 -0
- package/dist/config-5ADBAAXU.js +42 -0
- package/dist/{dist-U4M6QCKE.js → dist-3LOO6M4U.js} +10 -10
- package/dist/doctor-Q35VQW3S.js +436 -0
- package/dist/doctor-Q35VQW3S.js.map +1 -0
- package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js → ethersCompat-Df4a6QIZ-THAVUGIJ.js} +5 -5
- package/dist/{chunk-KAJZHIQ4.js → fund-GDDPL2BB.js} +81 -24
- package/dist/fund-GDDPL2BB.js.map +1 -0
- package/dist/hook-command-PBERPRE3.js +763 -0
- package/dist/hook-command-PBERPRE3.js.map +1 -0
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/install-OKDKGUXM.js +60 -0
- package/dist/install-wallet-SI4LZ73K.js +106 -0
- package/dist/install-wallet-SI4LZ73K.js.map +1 -0
- package/dist/{run-XYTQ5TWQ.js → mcp-XX3WRQEZ.js} +3766 -10677
- package/dist/mcp-XX3WRQEZ.js.map +1 -0
- package/dist/paths-P2N4JTDZ.js +49 -0
- package/dist/pay-3SYKHKWJ.js +39 -0
- package/dist/redact-6W23GGJC.js +15 -0
- package/dist/{secp256k1-XRPVBC6V.js → secp256k1-ZZZT2CAX.js} +3 -3
- package/dist/{send-G746D7PQ.js → send-LQRKTEJT.js} +29 -29
- package/dist/send-LQRKTEJT.js.map +1 -0
- package/dist/{chunk-QZ6ROAJU.js → skill-placement-JMDPSKE6.js} +155 -10
- package/dist/skill-placement-JMDPSKE6.js.map +1 -0
- package/dist/status-FFC6FO72.js +64 -0
- package/dist/status-FFC6FO72.js.map +1 -0
- package/dist/status-line-SAXSU6CR.js +87 -0
- package/dist/status-line-SAXSU6CR.js.map +1 -0
- package/dist/status-line-wiring-L2WYIYBM.js +29 -0
- package/dist/tenjin-daemon.mjs +20421 -0
- package/dist/tenjin-shim.mjs +251 -0
- package/dist/tenjin-vitest-reporter.mjs +49 -0
- package/dist/uninstall-OACH27UV.js +147 -0
- package/dist/uninstall-OACH27UV.js.map +1 -0
- package/dist/{update-R76LHOZW.js → update-4W6EKLGZ.js} +132 -16
- package/dist/update-4W6EKLGZ.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-TUQJBMHM.js → viemAdapter-By13KInL-X2VY6CY3.js} +5 -5
- package/dist/wallet-BMEXRR3P.js +32 -0
- package/dist/wallet-kdf-worker.mjs +980 -0
- package/docs/agent-permissions.md +71 -352
- package/docs/safety-model.md +16 -6
- package/package.json +8 -7
- package/LICENSE +0 -21
- package/dist/buy-VIRNSYGN.js +0 -47
- package/dist/chunk-2MYQN7HM.js +0 -247
- package/dist/chunk-2MYQN7HM.js.map +0 -1
- package/dist/chunk-2RF2GIJQ.js +0 -1188
- package/dist/chunk-2RF2GIJQ.js.map +0 -1
- package/dist/chunk-3GL2Z5QK.js +0 -57
- package/dist/chunk-3GL2Z5QK.js.map +0 -1
- package/dist/chunk-47PP7TAG.js.map +0 -1
- package/dist/chunk-4CQIDQOT.js +0 -167
- package/dist/chunk-4CQIDQOT.js.map +0 -1
- package/dist/chunk-4KG27W2S.js +0 -614
- package/dist/chunk-4KG27W2S.js.map +0 -1
- package/dist/chunk-5QQTYWEU.js +0 -199
- package/dist/chunk-5QQTYWEU.js.map +0 -1
- package/dist/chunk-65DTCCJ7.js +0 -21
- package/dist/chunk-65DTCCJ7.js.map +0 -1
- package/dist/chunk-A5DKHMUN.js +0 -173
- package/dist/chunk-A5DKHMUN.js.map +0 -1
- package/dist/chunk-B63XPWQ4.js +0 -246
- package/dist/chunk-B63XPWQ4.js.map +0 -1
- package/dist/chunk-CAR6FHK6.js +0 -105
- package/dist/chunk-CAR6FHK6.js.map +0 -1
- package/dist/chunk-CPCX67TI.js.map +0 -1
- package/dist/chunk-CQBVCYI2.js +0 -162
- package/dist/chunk-CQBVCYI2.js.map +0 -1
- package/dist/chunk-DBU5CXBV.js +0 -4731
- package/dist/chunk-DBU5CXBV.js.map +0 -1
- package/dist/chunk-DHJD77OW.js +0 -81
- package/dist/chunk-DHJD77OW.js.map +0 -1
- package/dist/chunk-EDZSNPE5.js +0 -35
- package/dist/chunk-EDZSNPE5.js.map +0 -1
- package/dist/chunk-EFWZPUTC.js +0 -65
- package/dist/chunk-EFWZPUTC.js.map +0 -1
- package/dist/chunk-EPFL6CTE.js +0 -448
- package/dist/chunk-EPFL6CTE.js.map +0 -1
- package/dist/chunk-GHLVXVZD.js +0 -142
- package/dist/chunk-GHLVXVZD.js.map +0 -1
- package/dist/chunk-H3SOOJ2I.js +0 -580
- package/dist/chunk-H3SOOJ2I.js.map +0 -1
- package/dist/chunk-HPJGOLTN.js.map +0 -1
- package/dist/chunk-HRGBS2PA.js +0 -203
- package/dist/chunk-HRGBS2PA.js.map +0 -1
- package/dist/chunk-ITUXPJIS.js +0 -314
- package/dist/chunk-ITUXPJIS.js.map +0 -1
- package/dist/chunk-JBIKAAT3.js.map +0 -1
- package/dist/chunk-KAJZHIQ4.js.map +0 -1
- package/dist/chunk-KINZ23CV.js.map +0 -1
- package/dist/chunk-LRYV3SK7.js +0 -235
- package/dist/chunk-LRYV3SK7.js.map +0 -1
- package/dist/chunk-M2O56UK7.js.map +0 -1
- package/dist/chunk-MJZZTKCC.js.map +0 -1
- package/dist/chunk-NIKXHWOL.js.map +0 -1
- package/dist/chunk-OKDRDT74.js +0 -209
- package/dist/chunk-OKDRDT74.js.map +0 -1
- package/dist/chunk-OKYSNAS3.js +0 -2144
- package/dist/chunk-OKYSNAS3.js.map +0 -1
- package/dist/chunk-OLWTRUTS.js.map +0 -1
- package/dist/chunk-QQ6ELLSA.js +0 -143
- package/dist/chunk-QQ6ELLSA.js.map +0 -1
- package/dist/chunk-QZ6ROAJU.js.map +0 -1
- package/dist/chunk-R7RSCBI7.js +0 -794
- package/dist/chunk-R7RSCBI7.js.map +0 -1
- package/dist/chunk-SGK2B724.js +0 -67
- package/dist/chunk-SGK2B724.js.map +0 -1
- package/dist/chunk-U6VPKMGC.js +0 -390
- package/dist/chunk-U6VPKMGC.js.map +0 -1
- package/dist/chunk-UHTVXQ2O.js +0 -140
- package/dist/chunk-UHTVXQ2O.js.map +0 -1
- package/dist/chunk-UO22YNY4.js.map +0 -1
- package/dist/chunk-US456VUI.js +0 -149
- package/dist/chunk-US456VUI.js.map +0 -1
- package/dist/chunk-V44J2MXV.js +0 -400
- package/dist/chunk-V44J2MXV.js.map +0 -1
- package/dist/chunk-VJQKL3YH.js +0 -216
- package/dist/chunk-VJQKL3YH.js.map +0 -1
- package/dist/chunk-VJSQSLBM.js +0 -1442
- package/dist/chunk-VJSQSLBM.js.map +0 -1
- package/dist/chunk-VYOJOX4Z.js +0 -165
- package/dist/chunk-VYOJOX4Z.js.map +0 -1
- package/dist/chunk-WY2K35OL.js +0 -269
- package/dist/chunk-WY2K35OL.js.map +0 -1
- package/dist/chunk-ZFJJ3EXC.js.map +0 -1
- package/dist/chunk-ZOBNS7CX.js.map +0 -1
- package/dist/cli-KKRKBU5T.js.map +0 -1
- package/dist/config-JMRUNYE6.js +0 -37
- package/dist/discover-B5HF6SHM.js +0 -102
- package/dist/discover-B5HF6SHM.js.map +0 -1
- package/dist/doctor-ZBG7X66D.js +0 -32
- package/dist/edit-PZJIILQE.js +0 -40
- package/dist/fund-EUDH5KPA.js +0 -40
- package/dist/inspect-QC6WEQPN.js +0 -37
- package/dist/install-GNK2W3PI.js +0 -972
- package/dist/install-GNK2W3PI.js.map +0 -1
- package/dist/outcome-KSGWZHUS.js +0 -24
- package/dist/pay-BC4UICPA.js +0 -361
- package/dist/pay-BC4UICPA.js.map +0 -1
- package/dist/publish-LXWFDIKF.js +0 -42
- package/dist/read-JMNUQ56P.js +0 -160
- package/dist/read-JMNUQ56P.js.map +0 -1
- package/dist/run-XYTQ5TWQ.js.map +0 -1
- package/dist/search-TSQAB45E.js +0 -25
- package/dist/secp256k1-XRPVBC6V.js.map +0 -1
- package/dist/send-G746D7PQ.js.map +0 -1
- package/dist/session-JBKWMJ24.js +0 -89
- package/dist/session-JBKWMJ24.js.map +0 -1
- package/dist/skill-heal-WKD67SLJ.js +0 -92
- package/dist/skill-heal-WKD67SLJ.js.map +0 -1
- package/dist/skill-placement-RIU4AMC2.js +0 -20
- package/dist/skill-placement-RIU4AMC2.js.map +0 -1
- package/dist/uninstall-5E263VTS.js +0 -73
- package/dist/uninstall-5E263VTS.js.map +0 -1
- package/dist/update-R76LHOZW.js.map +0 -1
- package/dist/usdc-4VCDHFWX.js +0 -38
- package/dist/usdc-4VCDHFWX.js.map +0 -1
- package/dist/viemAdapter-By13KInL-TUQJBMHM.js.map +0 -1
- package/dist/wallet-TQ7D5EQ7.js +0 -41
- package/dist/wallet-TQ7D5EQ7.js.map +0 -1
- package/dist/wallet-ZAVXWLWP.js +0 -32
- package/dist/wallet-ZAVXWLWP.js.map +0 -1
- package/docs/command-reference.md +0 -303
- package/skills/tenjin/SKILL.md +0 -373
- package/skills/tenjin-pay/SKILL.md +0 -76
- package/skills/tenjin-publish/SKILL.md +0 -227
- package/skills/tenjin-publish/references/maintain.md +0 -39
- package/skills/tenjin-search/SKILL.md +0 -154
- package/skills/tenjin-search/references/permissions.md +0 -112
- /package/dist/{_esm-N4KAVXQR.js.map → _esm-CE7KNONL.js.map} +0 -0
- /package/dist/{buy-VIRNSYGN.js.map → ccip-7RMRLAGV.js.map} +0 -0
- /package/dist/{ccip-RPPPKTJR.js.map → ccip-NLCSCHKI.js.map} +0 -0
- /package/dist/{chunk-U5S527PP.js.map → chunk-5IEP5EGE.js.map} +0 -0
- /package/dist/{chunk-KYQVEKP5.js.map → chunk-BPMWXTFX.js.map} +0 -0
- /package/dist/{chunk-S5RYMCV6.js.map → chunk-HPWO4O6S.js.map} +0 -0
- /package/dist/{chunk-W6R3HAAG.js.map → chunk-JRGFKVAZ.js.map} +0 -0
- /package/dist/{chunk-XJN5WUKL.js.map → chunk-KG3D7FIF.js.map} +0 -0
- /package/dist/{chunk-QW2Q2KAH.js.map → chunk-LHHMV4GU.js.map} +0 -0
- /package/dist/{chunk-POJRB2AE.js.map → chunk-POUWHWID.js.map} +0 -0
- /package/dist/{chunk-KZAAWQNP.js.map → chunk-TTNESUPQ.js.map} +0 -0
- /package/dist/{chunk-YLYINX2H.js.map → chunk-XZKD7DIF.js.map} +0 -0
- /package/dist/{ccip-ZGGWQN4X.js.map → config-5ADBAAXU.js.map} +0 -0
- /package/dist/{dist-U4M6QCKE.js.map → dist-3LOO6M4U.js.map} +0 -0
- /package/dist/{config-JMRUNYE6.js.map → ethersCompat-Df4a6QIZ-THAVUGIJ.js.map} +0 -0
- /package/dist/{doctor-ZBG7X66D.js.map → install-OKDKGUXM.js.map} +0 -0
- /package/dist/{edit-PZJIILQE.js.map → paths-P2N4JTDZ.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js.map → pay-3SYKHKWJ.js.map} +0 -0
- /package/dist/{fund-EUDH5KPA.js.map → redact-6W23GGJC.js.map} +0 -0
- /package/dist/{inspect-QC6WEQPN.js.map → secp256k1-ZZZT2CAX.js.map} +0 -0
- /package/dist/{outcome-KSGWZHUS.js.map → status-line-wiring-L2WYIYBM.js.map} +0 -0
- /package/dist/{publish-LXWFDIKF.js.map → viemAdapter-By13KInL-X2VY6CY3.js.map} +0 -0
- /package/dist/{search-TSQAB45E.js.map → wallet-BMEXRR3P.js.map} +0 -0
package/dist/pay-BC4UICPA.js
DELETED
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
verifyAgainstRegistries
|
|
4
|
-
} from "./chunk-EPFL6CTE.js";
|
|
5
|
-
import {
|
|
6
|
-
buildExactPayment,
|
|
7
|
-
gateSpend
|
|
8
|
-
} from "./chunk-2RF2GIJQ.js";
|
|
9
|
-
import "./chunk-QW2Q2KAH.js";
|
|
10
|
-
import {
|
|
11
|
-
SIGN_IN_WITH_X,
|
|
12
|
-
SIWX_HEADER,
|
|
13
|
-
buildSiwxHeader
|
|
14
|
-
} from "./chunk-KINZ23CV.js";
|
|
15
|
-
import {
|
|
16
|
-
decodePaymentRequiredHeader,
|
|
17
|
-
decodePaymentResponseHeader
|
|
18
|
-
} from "./chunk-DBU5CXBV.js";
|
|
19
|
-
import "./chunk-KZAAWQNP.js";
|
|
20
|
-
import "./chunk-S5RYMCV6.js";
|
|
21
|
-
import "./chunk-POJRB2AE.js";
|
|
22
|
-
import "./chunk-YLYINX2H.js";
|
|
23
|
-
import "./chunk-MJZZTKCC.js";
|
|
24
|
-
import "./chunk-7FK2UN2T.js";
|
|
25
|
-
import {
|
|
26
|
-
describeWallet,
|
|
27
|
-
resolveSpendAuthorizer,
|
|
28
|
-
resolveWalletProvider
|
|
29
|
-
} from "./chunk-CPCX67TI.js";
|
|
30
|
-
import "./chunk-M2O56UK7.js";
|
|
31
|
-
import "./chunk-UHTVXQ2O.js";
|
|
32
|
-
import {
|
|
33
|
-
fetchFailureToCliError,
|
|
34
|
-
httpRequest
|
|
35
|
-
} from "./chunk-5QQTYWEU.js";
|
|
36
|
-
import "./chunk-GHLVXVZD.js";
|
|
37
|
-
import {
|
|
38
|
-
sanitizeForTerminal
|
|
39
|
-
} from "./chunk-OLWTRUTS.js";
|
|
40
|
-
import {
|
|
41
|
-
resolveContextSettings
|
|
42
|
-
} from "./chunk-VYOJOX4Z.js";
|
|
43
|
-
import {
|
|
44
|
-
parseUsdToAtomic,
|
|
45
|
-
toMoney
|
|
46
|
-
} from "./chunk-EFWZPUTC.js";
|
|
47
|
-
import "./chunk-U6VPKMGC.js";
|
|
48
|
-
import "./chunk-UO22YNY4.js";
|
|
49
|
-
import "./chunk-3GL2Z5QK.js";
|
|
50
|
-
import "./chunk-JBIKAAT3.js";
|
|
51
|
-
import {
|
|
52
|
-
isSameDeployment
|
|
53
|
-
} from "./chunk-2MYQN7HM.js";
|
|
54
|
-
import "./chunk-ZOBNS7CX.js";
|
|
55
|
-
import {
|
|
56
|
-
CliError
|
|
57
|
-
} from "./chunk-ZFJJ3EXC.js";
|
|
58
|
-
import "./chunk-W6R3HAAG.js";
|
|
59
|
-
import "./chunk-U5S527PP.js";
|
|
60
|
-
import "./chunk-47PP7TAG.js";
|
|
61
|
-
import "./chunk-XJN5WUKL.js";
|
|
62
|
-
import "./chunk-RBJPAZFI.js";
|
|
63
|
-
import "./chunk-KYQVEKP5.js";
|
|
64
|
-
import "./chunk-ZXTAQYNA.js";
|
|
65
|
-
|
|
66
|
-
// src/commands/pay.ts
|
|
67
|
-
var PAYMENT_REQUIRED_HEADER = "PAYMENT-REQUIRED";
|
|
68
|
-
var PAYMENT_RESPONSE_HEADER = "PAYMENT-RESPONSE";
|
|
69
|
-
var BODY_PREVIEW_CHARS = 1200;
|
|
70
|
-
async function runPay(args, ctx, deps = {}) {
|
|
71
|
-
const settings = await resolveContextSettings(ctx);
|
|
72
|
-
const maxPriceAtomic = args.maxPrice !== void 0 ? BigInt(parseUsdToAtomic(args.maxPrice)) : void 0;
|
|
73
|
-
const url = args.url.trim();
|
|
74
|
-
const lane = resolveLane(url, settings);
|
|
75
|
-
const method = resolveMethod(args);
|
|
76
|
-
const jsonBody = parseBody(args.data);
|
|
77
|
-
const fetchOpts = {
|
|
78
|
-
timeoutMs: ctx.flags.timeout,
|
|
79
|
-
// Both legs: the probe's 402 is money-path input, and the paid retry
|
|
80
|
-
// carries a signed header (which pins redirects on its own; this pins the
|
|
81
|
-
// probe too, so the challenge always comes from the URL that was gated).
|
|
82
|
-
blockRedirects: true,
|
|
83
|
-
...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {},
|
|
84
|
-
...jsonBody !== void 0 ? { jsonBody } : {},
|
|
85
|
-
method
|
|
86
|
-
};
|
|
87
|
-
const probe = await httpRequest(url, fetchOpts);
|
|
88
|
-
if (!probe.ok) throw fetchFailureToCliError(probe);
|
|
89
|
-
if (probe.status >= 200 && probe.status < 300) {
|
|
90
|
-
return deliver(url, lane, probe, { paid: false, printBody: args.printBody === true });
|
|
91
|
-
}
|
|
92
|
-
if (probe.status !== 402) {
|
|
93
|
-
throw new CliError("API_UNREACHABLE", `${url} answered ${probe.status}.`, {
|
|
94
|
-
fix: "Check the URL and the endpoint status, then retry.",
|
|
95
|
-
details: { status: probe.status, body: probe.json }
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
const paymentRequired = decodeChallenge(probe, url);
|
|
99
|
-
const requirement = paymentRequired.accepts[0];
|
|
100
|
-
if (requirement === void 0) {
|
|
101
|
-
throw new CliError("PAYMENT_FAILED", "The 402 advertised no payment requirements.", {
|
|
102
|
-
fix: "The endpoint looks misconfigured."
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
const firstSeenAmount = BigInt(requirement.amount);
|
|
106
|
-
const host = new URL(url).host;
|
|
107
|
-
let registry;
|
|
108
|
-
if (lane === "bazaar") {
|
|
109
|
-
registry = await assertRegistryVerified(settings, url, requirement, ctx.flags.timeout, ctx);
|
|
110
|
-
}
|
|
111
|
-
const provider = resolveWalletProvider(
|
|
112
|
-
ctx,
|
|
113
|
-
deps.provider !== void 0 ? { provider: deps.provider } : {}
|
|
114
|
-
);
|
|
115
|
-
await describeWallet(provider);
|
|
116
|
-
const signer = await provider.getSigner();
|
|
117
|
-
let effectiveChallenge = paymentRequired;
|
|
118
|
-
let effectiveRequirement = requirement;
|
|
119
|
-
if (paymentRequired.extensions?.[SIGN_IN_WITH_X] !== void 0) {
|
|
120
|
-
const siwxHeader = await buildSiwxHeader(signer, {
|
|
121
|
-
baseUrl: new URL(url).origin,
|
|
122
|
-
chainId: requirement.network
|
|
123
|
-
});
|
|
124
|
-
const recheck = await httpRequest(url, {
|
|
125
|
-
...fetchOpts,
|
|
126
|
-
headers: { [SIWX_HEADER]: siwxHeader }
|
|
127
|
-
});
|
|
128
|
-
if (!recheck.ok) throw fetchFailureToCliError(recheck);
|
|
129
|
-
if (recheck.status >= 200 && recheck.status < 300) {
|
|
130
|
-
return deliver(url, lane, recheck, {
|
|
131
|
-
paid: false,
|
|
132
|
-
entitled: true,
|
|
133
|
-
printBody: args.printBody === true
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
if (recheck.status !== 402) {
|
|
137
|
-
throw new CliError(
|
|
138
|
-
"API_UNREACHABLE",
|
|
139
|
-
`${url} answered ${recheck.status} on the entitlement re-check.`,
|
|
140
|
-
{
|
|
141
|
-
fix: "Retry; if it persists the endpoint looks misconfigured.",
|
|
142
|
-
details: { status: recheck.status, body: recheck.json }
|
|
143
|
-
}
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
effectiveChallenge = decodeChallenge(recheck, url);
|
|
147
|
-
const fresh = effectiveChallenge.accepts[0];
|
|
148
|
-
if (fresh === void 0) {
|
|
149
|
-
throw new CliError("PAYMENT_FAILED", "The fresh 402 advertised no payment requirements.", {
|
|
150
|
-
fix: "The endpoint looks misconfigured."
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
if (BigInt(fresh.amount) > firstSeenAmount) {
|
|
154
|
-
throw new CliError("PAYMENT_FAILED", "The price increased before signing; refusing to pay.", {
|
|
155
|
-
fix: "Re-run `tenjin pay` to review the new price, and set --max-price to cap it.",
|
|
156
|
-
details: {
|
|
157
|
-
firstSeenAtomic: firstSeenAmount.toString(),
|
|
158
|
-
currentAtomic: fresh.amount
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
effectiveRequirement = fresh;
|
|
163
|
-
if (lane === "bazaar") {
|
|
164
|
-
registry = await assertRegistryVerified(settings, url, fresh, ctx.flags.timeout, ctx);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
const amountAtomic = BigInt(effectiveRequirement.amount);
|
|
168
|
-
const authorizer = resolveSpendAuthorizer(
|
|
169
|
-
ctx,
|
|
170
|
-
settings.policy,
|
|
171
|
-
deps.authorizer !== void 0 ? { authorizer: deps.authorizer } : {}
|
|
172
|
-
);
|
|
173
|
-
const via = registry !== void 0 ? ` (listed on ${sanitizeForTerminal(registry)})` : "";
|
|
174
|
-
const reservationId = await gateSpend({
|
|
175
|
-
ctx,
|
|
176
|
-
authorizer,
|
|
177
|
-
amountAtomic,
|
|
178
|
-
creator: host,
|
|
179
|
-
...maxPriceAtomic !== void 0 ? { maxPriceAtomic } : {},
|
|
180
|
-
yes: args.yes === true,
|
|
181
|
-
...deps.confirm !== void 0 ? { confirm: deps.confirm } : {},
|
|
182
|
-
payeeLabel: `${sanitizeForTerminal(host)}${via}`,
|
|
183
|
-
allowlistSubject: "this host",
|
|
184
|
-
notConfirmedMessage: "Payment not confirmed."
|
|
185
|
-
});
|
|
186
|
-
let payment;
|
|
187
|
-
try {
|
|
188
|
-
payment = await buildExactPayment(effectiveChallenge, signer);
|
|
189
|
-
} catch (err) {
|
|
190
|
-
await authorizer.release(reservationId);
|
|
191
|
-
throw err;
|
|
192
|
-
}
|
|
193
|
-
const paid = await httpRequest(url, { ...fetchOpts, headers: payment.headers });
|
|
194
|
-
await authorizer.commit(reservationId, payment.amountAtomic);
|
|
195
|
-
if (!paid.ok) throw fetchFailureToCliError(paid);
|
|
196
|
-
if (paid.status >= 200 && paid.status < 300) {
|
|
197
|
-
return deliver(url, lane, paid, {
|
|
198
|
-
paid: true,
|
|
199
|
-
amountAtomic: payment.amountAtomic,
|
|
200
|
-
requirement: effectiveRequirement,
|
|
201
|
-
...registry !== void 0 ? { registry } : {},
|
|
202
|
-
printBody: args.printBody === true
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
throw new CliError(
|
|
206
|
-
"PAYMENT_FAILED",
|
|
207
|
-
paid.status === 402 ? "Payment was not accepted by the endpoint." : `The endpoint answered ${paid.status} on the paid request; whether it settled is unknown.`,
|
|
208
|
-
{
|
|
209
|
-
fix: "The signed payment already left and is counted against the session budget; the endpoint may still settle it. Do not simply retry: each attempt signs a fresh authorization. Verify the endpoint (and this listing, if Bazaar) before paying again.",
|
|
210
|
-
details: { status: paid.status, body: paid.json }
|
|
211
|
-
}
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
function resolveLane(url, settings) {
|
|
215
|
-
let target;
|
|
216
|
-
try {
|
|
217
|
-
target = new URL(url);
|
|
218
|
-
} catch {
|
|
219
|
-
throw new CliError("USAGE", `Invalid URL: ${JSON.stringify(url)}`, {
|
|
220
|
-
fix: "Pass an absolute http(s) URL."
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
if (target.protocol !== "http:" && target.protocol !== "https:") {
|
|
224
|
-
throw new CliError("USAGE", `URL must be http or https: ${JSON.stringify(url)}`, {
|
|
225
|
-
fix: "Pass an absolute http(s) URL."
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
if (isSameDeployment(target.origin, new URL(settings.baseUrl).origin)) return "tenjin";
|
|
229
|
-
if (settings.bazaarPay !== true) {
|
|
230
|
-
throw new CliError(
|
|
231
|
-
"USAGE",
|
|
232
|
-
`${target.origin} is not the configured base URL, and the Bazaar pay lane is off.`,
|
|
233
|
-
{
|
|
234
|
-
fix: "An operator enables paying registry-listed non-Tenjin endpoints with `tenjin config set bazaarPay on`."
|
|
235
|
-
}
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
if (target.protocol !== "https:") {
|
|
239
|
-
throw new CliError("USAGE", "The Bazaar lane pays https endpoints only.", {
|
|
240
|
-
fix: "Use the https URL the registry lists."
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
return "bazaar";
|
|
244
|
-
}
|
|
245
|
-
function resolveMethod(args) {
|
|
246
|
-
const method = args.method?.toUpperCase() ?? (args.data !== void 0 ? "POST" : "GET");
|
|
247
|
-
if (method !== "GET" && method !== "POST") {
|
|
248
|
-
throw new CliError("USAGE", `Unsupported method ${JSON.stringify(args.method)}`, {
|
|
249
|
-
fix: "Use -X GET or -X POST."
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
if (method === "GET" && args.data !== void 0) {
|
|
253
|
-
throw new CliError("USAGE", "A request body needs -X POST.", {
|
|
254
|
-
fix: "Drop --data, or pass -X POST."
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
return method;
|
|
258
|
-
}
|
|
259
|
-
function parseBody(data) {
|
|
260
|
-
if (data === void 0) return void 0;
|
|
261
|
-
try {
|
|
262
|
-
return JSON.parse(data);
|
|
263
|
-
} catch {
|
|
264
|
-
throw new CliError("USAGE", "The --data value is not valid JSON.", {
|
|
265
|
-
fix: `Pass a JSON object/array/string, e.g. --data '{"question":"..."}'.`
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
function decodeChallenge(res, url) {
|
|
270
|
-
const encoded = res.header(PAYMENT_REQUIRED_HEADER);
|
|
271
|
-
if (encoded === void 0) {
|
|
272
|
-
throw new CliError(
|
|
273
|
-
"CONTRACT_MISMATCH",
|
|
274
|
-
`The 402 from ${url} carried no PAYMENT-REQUIRED header.`,
|
|
275
|
-
{
|
|
276
|
-
fix: "The endpoint does not speak x402 v2; nothing was paid."
|
|
277
|
-
}
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
try {
|
|
281
|
-
return decodePaymentRequiredHeader(encoded);
|
|
282
|
-
} catch (err) {
|
|
283
|
-
throw new CliError("CONTRACT_MISMATCH", "Could not decode the PAYMENT-REQUIRED header.", {
|
|
284
|
-
cause: err
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
async function assertRegistryVerified(settings, url, requirement, timeoutMs, ctx) {
|
|
289
|
-
const verification = await verifyAgainstRegistries(
|
|
290
|
-
settings.bazaarRegistries,
|
|
291
|
-
url,
|
|
292
|
-
requirement,
|
|
293
|
-
timeoutMs,
|
|
294
|
-
{ dataDir: ctx.dataDir }
|
|
295
|
-
);
|
|
296
|
-
switch (verification.outcome) {
|
|
297
|
-
case "verified":
|
|
298
|
-
return verification.registry;
|
|
299
|
-
case "mismatch":
|
|
300
|
-
throw new CliError(
|
|
301
|
-
"REGISTRY_MISMATCH",
|
|
302
|
-
`The live 402 does not match what ${verification.registry} advertises for this resource (${verification.detail}).`,
|
|
303
|
-
{
|
|
304
|
-
fix: "Nothing was signed. Re-run `tenjin discover` to see the advertised terms; if the seller changed them, the registry will catch up.",
|
|
305
|
-
details: { registry: verification.registry, detail: verification.detail }
|
|
306
|
-
}
|
|
307
|
-
);
|
|
308
|
-
case "unlisted":
|
|
309
|
-
throw new CliError("USAGE", "No configured registry is known to list this resource.", {
|
|
310
|
-
fix: "The Bazaar lane pays publicly listed deals only, and pay-time lookup leans on the local `discover` cache: run `tenjin discover [query]` so a sweep can surface this endpoint, then re-run pay."
|
|
311
|
-
});
|
|
312
|
-
case "unavailable":
|
|
313
|
-
throw new CliError(
|
|
314
|
-
"NETWORK_ERROR",
|
|
315
|
-
"No configured registry answered; the Bazaar lane fails closed.",
|
|
316
|
-
{
|
|
317
|
-
fix: "Retry when the registries are reachable.",
|
|
318
|
-
details: { errors: verification.errors }
|
|
319
|
-
}
|
|
320
|
-
);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
function deliver(url, lane, res, opts) {
|
|
324
|
-
const settlementTxHash = opts.paid ? settlementTx(res) : void 0;
|
|
325
|
-
const data = {
|
|
326
|
-
url,
|
|
327
|
-
lane,
|
|
328
|
-
status: res.status,
|
|
329
|
-
paid: opts.paid,
|
|
330
|
-
...opts.paid ? {
|
|
331
|
-
amountPaid: toMoney(opts.amountAtomic.toString()),
|
|
332
|
-
payTo: opts.requirement.payTo,
|
|
333
|
-
network: opts.requirement.network,
|
|
334
|
-
...opts.registry !== void 0 ? { registry: opts.registry } : {}
|
|
335
|
-
} : opts.entitled === true ? { entitled: true } : {},
|
|
336
|
-
...settlementTxHash !== void 0 ? { settlementTxHash } : {},
|
|
337
|
-
// The body is the product: JSON when the endpoint spoke it, raw text always.
|
|
338
|
-
...res.json !== void 0 ? { body: res.json } : {},
|
|
339
|
-
bodyText: res.text
|
|
340
|
-
};
|
|
341
|
-
const headline = opts.paid ? `paid ${toMoney(opts.amountAtomic.toString()).usd} USD to ${sanitizeForTerminal(new URL(url).host)}` + (settlementTxHash !== void 0 ? ` (tx ${settlementTxHash})` : "") : opts.entitled === true ? `free (entitled, no charge)` : `free (${res.status}, no charge)`;
|
|
342
|
-
const body = sanitizeForTerminal(res.text);
|
|
343
|
-
const preview = opts.printBody || body.length <= BODY_PREVIEW_CHARS ? body : `${body.slice(0, BODY_PREVIEW_CHARS)}
|
|
344
|
-
\u2026 truncated; run with --print-body or --json for the full body`;
|
|
345
|
-
return { data, humanLines: [headline, ...preview.length > 0 ? [preview] : []] };
|
|
346
|
-
}
|
|
347
|
-
function settlementTx(res) {
|
|
348
|
-
const header = res.header(PAYMENT_RESPONSE_HEADER);
|
|
349
|
-
if (header === void 0) return void 0;
|
|
350
|
-
try {
|
|
351
|
-
const settle = decodePaymentResponseHeader(header);
|
|
352
|
-
const tx = settle.transaction;
|
|
353
|
-
return typeof tx === "string" ? tx : void 0;
|
|
354
|
-
} catch {
|
|
355
|
-
return void 0;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
export {
|
|
359
|
-
runPay
|
|
360
|
-
};
|
|
361
|
-
//# sourceMappingURL=pay-BC4UICPA.js.map
|
package/dist/pay-BC4UICPA.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/commands/pay.ts"],"sourcesContent":["import { decodePaymentRequiredHeader, decodePaymentResponseHeader } from '@x402/core/http';\nimport { SIGN_IN_WITH_X } from '@x402/extensions/sign-in-with-x';\nimport type { PaymentRequired, PaymentRequirements } from '@x402/core/types';\nimport { verifyAgainstRegistries } from '../lib/bazaar';\nimport { CliError } from '../lib/errors';\nimport { fetchFailureToCliError, httpRequest } from '../lib/http';\nimport type { HttpResponse } from '../lib/http';\nimport { parseUsdToAtomic, toMoney } from '../lib/money';\nimport { sanitizeForTerminal } from '../lib/output';\nimport { isSameDeployment } from '../lib/production-origin';\nimport { resolveContextSettings } from '../lib/settings';\nimport { SIWX_HEADER, buildSiwxHeader } from '../lib/siwx';\nimport { gateSpend } from '../lib/spend-gate';\nimport type { ResolvedSettings } from '../lib/settings';\nimport {\n describeWallet,\n resolveSpendAuthorizer,\n resolveWalletProvider,\n type SpendAuthorizer,\n type WalletProvider,\n} from '../lib/wallet';\nimport { buildExactPayment } from '../lib/x402-pay';\nimport type { CommandContext, CommandResult } from '../context';\n\n/**\n * `tenjin pay <url>`: the standard x402 client verb, for ANY paid endpoint\n * rather than marketplace pieces. One probe; a 2xx delivers free; a 402 runs\n * the same money gates as `buy` (spend policy, price cap, session budget,\n * confirm; `--yes` clears only the confirm) and retries once with the\n * `PAYMENT-SIGNATURE`. Deliberately NOT `buy`: no library idempotence (every\n * paid call pays; the session budget and `--max-price` are the brakes) and no\n * search attribution. SIWX rides ONLY when the 402 advertises the standard\n * sign-in-with-x extension, and the signature is bound to the TARGET origin\n * (never the configured deployment's), so an entitled wallet re-reads free at\n * any seller that supports it while nothing origin-bound can leak elsewhere.\n *\n * The origin gate has two lanes. The configured base URL is always payable.\n * Any other https origin is payable only when the operator turned `bazaarPay`\n * on AND a configured registry publicly lists this exact resource with terms\n * the live 402 does not exceed (lib/bazaar); a mismatch is REGISTRY_MISMATCH\n * and nothing is signed. The response body is delivered raw in the machine\n * envelope and sanitized for the terminal: paid or not, it is other people's\n * content, never instructions.\n */\n\nconst PAYMENT_REQUIRED_HEADER = 'PAYMENT-REQUIRED';\nconst PAYMENT_RESPONSE_HEADER = 'PAYMENT-RESPONSE';\n\n/** Terminal preview cap; `--print-body` lifts it. The machine body is never cut. */\nconst BODY_PREVIEW_CHARS = 1200;\n\nexport interface PayArgs {\n url: string;\n /** GET (default) or POST; POST is implied when --data is given. */\n method?: string;\n /** A JSON request body; content-type is always application/json. */\n data?: string;\n /** Decimal USD; the hard price cap, never bypassed by --yes. */\n maxPrice?: string;\n /** Bypass the interactive confirm only (never the price cap or a hard deny). */\n yes?: boolean;\n /** Print the full body to the terminal instead of the capped preview. */\n printBody?: boolean;\n}\n\nexport interface PayDeps {\n fetchImpl?: typeof fetch;\n provider?: WalletProvider;\n authorizer?: SpendAuthorizer;\n confirm?: (prompt: string) => Promise<boolean>;\n}\n\ntype Lane = 'tenjin' | 'bazaar';\n\nexport async function runPay(\n args: PayArgs,\n ctx: CommandContext,\n deps: PayDeps = {},\n): Promise<CommandResult> {\n const settings = await resolveContextSettings(ctx);\n const maxPriceAtomic =\n args.maxPrice !== undefined ? BigInt(parseUsdToAtomic(args.maxPrice)) : undefined;\n const url = args.url.trim();\n const lane = resolveLane(url, settings);\n const method = resolveMethod(args);\n const jsonBody = parseBody(args.data);\n\n const fetchOpts = {\n timeoutMs: ctx.flags.timeout,\n // Both legs: the probe's 402 is money-path input, and the paid retry\n // carries a signed header (which pins redirects on its own; this pins the\n // probe too, so the challenge always comes from the URL that was gated).\n blockRedirects: true as const,\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n ...(jsonBody !== undefined ? { jsonBody } : {}),\n method,\n };\n\n const probe = await httpRequest(url, fetchOpts);\n if (!probe.ok) throw fetchFailureToCliError(probe);\n if (probe.status >= 200 && probe.status < 300) {\n return deliver(url, lane, probe, { paid: false, printBody: args.printBody === true });\n }\n if (probe.status !== 402) {\n throw new CliError('API_UNREACHABLE', `${url} answered ${probe.status}.`, {\n fix: 'Check the URL and the endpoint status, then retry.',\n details: { status: probe.status, body: probe.json },\n });\n }\n\n const paymentRequired = decodeChallenge(probe, url);\n const requirement = paymentRequired.accepts[0];\n if (requirement === undefined) {\n throw new CliError('PAYMENT_FAILED', 'The 402 advertised no payment requirements.', {\n fix: 'The endpoint looks misconfigured.',\n });\n }\n // The FIRST-SEEN amount: a later challenge may never cost more than this.\n const firstSeenAmount = BigInt(requirement.amount);\n const host = new URL(url).host;\n\n // The Bazaar lane's registry check runs BEFORE the wallet is even opened:\n // an unverifiable deal must not reach a signer.\n let registry: string | undefined;\n if (lane === 'bazaar') {\n registry = await assertRegistryVerified(settings, url, requirement, ctx.flags.timeout, ctx);\n }\n\n const provider = resolveWalletProvider(\n ctx,\n deps.provider !== undefined ? { provider: deps.provider } : {},\n );\n await describeWallet(provider); // WALLET_MISSING with its own fix if none exists\n const signer = await provider.getSigner();\n\n // The standard sign-in-with-x extension, same sequence as `buy`: when the 402\n // advertises it, an entitled wallet re-reads FREE before any payment exists,\n // and the re-check doubles as the fresh-challenge refetch the payment is\n // built against. The signature binds to the TARGET origin (host-with-port),\n // so a foreign seller gets a credential worth nothing anywhere else.\n let effectiveChallenge = paymentRequired;\n let effectiveRequirement = requirement;\n if (paymentRequired.extensions?.[SIGN_IN_WITH_X] !== undefined) {\n const siwxHeader = await buildSiwxHeader(signer, {\n baseUrl: new URL(url).origin,\n chainId: requirement.network,\n });\n const recheck = await httpRequest(url, {\n ...fetchOpts,\n headers: { [SIWX_HEADER]: siwxHeader },\n });\n if (!recheck.ok) throw fetchFailureToCliError(recheck);\n if (recheck.status >= 200 && recheck.status < 300) {\n return deliver(url, lane, recheck, {\n paid: false,\n entitled: true,\n printBody: args.printBody === true,\n });\n }\n if (recheck.status !== 402) {\n throw new CliError(\n 'API_UNREACHABLE',\n `${url} answered ${recheck.status} on the entitlement re-check.`,\n {\n fix: 'Retry; if it persists the endpoint looks misconfigured.',\n details: { status: recheck.status, body: recheck.json },\n },\n );\n }\n effectiveChallenge = decodeChallenge(recheck, url);\n const fresh = effectiveChallenge.accepts[0];\n if (fresh === undefined) {\n throw new CliError('PAYMENT_FAILED', 'The fresh 402 advertised no payment requirements.', {\n fix: 'The endpoint looks misconfigured.',\n });\n }\n // Refuse a price bump between the first look and signing, exactly as `buy`.\n if (BigInt(fresh.amount) > firstSeenAmount) {\n throw new CliError('PAYMENT_FAILED', 'The price increased before signing; refusing to pay.', {\n fix: 'Re-run `tenjin pay` to review the new price, and set --max-price to cap it.',\n details: {\n firstSeenAtomic: firstSeenAmount.toString(),\n currentAtomic: fresh.amount,\n },\n });\n }\n effectiveRequirement = fresh;\n // The Bazaar lane verifies the challenge it will actually SIGN: the store\n // answers this without a network round trip in the common case.\n if (lane === 'bazaar') {\n registry = await assertRegistryVerified(settings, url, fresh, ctx.flags.timeout, ctx);\n }\n }\n const amountAtomic = BigInt(effectiveRequirement.amount);\n\n const authorizer = resolveSpendAuthorizer(\n ctx,\n settings.policy,\n deps.authorizer !== undefined ? { authorizer: deps.authorizer } : {},\n );\n // The host is the creator identity here (`allowlistCreators` users pin\n // hosts); the gate itself is shared with `buy` so the two verbs cannot drift.\n const via = registry !== undefined ? ` (listed on ${sanitizeForTerminal(registry)})` : '';\n const reservationId = await gateSpend({\n ctx,\n authorizer,\n amountAtomic,\n creator: host,\n ...(maxPriceAtomic !== undefined ? { maxPriceAtomic } : {}),\n yes: args.yes === true,\n ...(deps.confirm !== undefined ? { confirm: deps.confirm } : {}),\n payeeLabel: `${sanitizeForTerminal(host)}${via}`,\n allowlistSubject: 'this host',\n notConfirmedMessage: 'Payment not confirmed.',\n });\n\n // A failure BEFORE transmission (the build) releases: no signature exists,\n // nothing can move. That is the last point where releasing is honest.\n let payment: Awaited<ReturnType<typeof buildExactPayment>>;\n try {\n payment = await buildExactPayment(effectiveChallenge, signer);\n } catch (err) {\n await authorizer.release(reservationId);\n throw err;\n }\n\n // From here the signed EIP-3009 authorization leaves the process, and it is a\n // bearer instrument: the counterparty can settle it whatever it answers, or\n // if it answers nothing. So EVERY post-transmission outcome commits the\n // reservation; money that may move is money accounted. Releasing here let a\n // hostile registry-listed seller answer 402 after each signature while\n // sessionBudget counted zero of the authorizations it was stacking up.\n // (httpRequest never throws on transport failure; it returns ok:false.)\n const paid = await httpRequest(url, { ...fetchOpts, headers: payment.headers });\n await authorizer.commit(reservationId, payment.amountAtomic);\n if (!paid.ok) throw fetchFailureToCliError(paid);\n if (paid.status >= 200 && paid.status < 300) {\n return deliver(url, lane, paid, {\n paid: true,\n amountAtomic: payment.amountAtomic,\n requirement: effectiveRequirement,\n ...(registry !== undefined ? { registry } : {}),\n printBody: args.printBody === true,\n });\n }\n // Still 402 (payment rejected) or anything else: nothing was delivered, but\n // the seller holds a live authorization, so the amount stays counted and the\n // fix must NOT coach a retry loop, since each retry signs a fresh authorization.\n throw new CliError(\n 'PAYMENT_FAILED',\n paid.status === 402\n ? 'Payment was not accepted by the endpoint.'\n : `The endpoint answered ${paid.status} on the paid request; whether it settled is unknown.`,\n {\n fix: 'The signed payment already left and is counted against the session budget; the endpoint may still settle it. Do not simply retry: each attempt signs a fresh authorization. Verify the endpoint (and this listing, if Bazaar) before paying again.',\n details: { status: paid.status, body: paid.json },\n },\n );\n}\n\n/** Which lane may pay this URL, or the exact refusal. */\nfunction resolveLane(url: string, settings: ResolvedSettings): Lane {\n let target: URL;\n try {\n target = new URL(url);\n } catch {\n throw new CliError('USAGE', `Invalid URL: ${JSON.stringify(url)}`, {\n fix: 'Pass an absolute http(s) URL.',\n });\n }\n if (target.protocol !== 'http:' && target.protocol !== 'https:') {\n throw new CliError('USAGE', `URL must be http or https: ${JSON.stringify(url)}`, {\n fix: 'Pass an absolute http(s) URL.',\n });\n }\n // Same deployment, not merely the same spelling: without this a URL on the\n // deployment's other origin falls through to the Bazaar lane, which then\n // refuses it as a third-party endpoint or pays it under registry rules meant\n // for one. The SIWX signature below binds to the TARGET origin either way.\n if (isSameDeployment(target.origin, new URL(settings.baseUrl).origin)) return 'tenjin';\n if (settings.bazaarPay !== true) {\n // The fix names the operator act without coaching around the gate that just\n // fired: this URL may have arrived in a task, a page, or purchased content.\n throw new CliError(\n 'USAGE',\n `${target.origin} is not the configured base URL, and the Bazaar pay lane is off.`,\n {\n fix: 'An operator enables paying registry-listed non-Tenjin endpoints with `tenjin config set bazaarPay on`.',\n },\n );\n }\n if (target.protocol !== 'https:') {\n throw new CliError('USAGE', 'The Bazaar lane pays https endpoints only.', {\n fix: 'Use the https URL the registry lists.',\n });\n }\n return 'bazaar';\n}\n\nfunction resolveMethod(args: PayArgs): 'GET' | 'POST' {\n const method = args.method?.toUpperCase() ?? (args.data !== undefined ? 'POST' : 'GET');\n if (method !== 'GET' && method !== 'POST') {\n throw new CliError('USAGE', `Unsupported method ${JSON.stringify(args.method)}`, {\n fix: 'Use -X GET or -X POST.',\n });\n }\n if (method === 'GET' && args.data !== undefined) {\n throw new CliError('USAGE', 'A request body needs -X POST.', {\n fix: 'Drop --data, or pass -X POST.',\n });\n }\n return method;\n}\n\nfunction parseBody(data: string | undefined): unknown {\n if (data === undefined) return undefined;\n try {\n return JSON.parse(data);\n } catch {\n throw new CliError('USAGE', 'The --data value is not valid JSON.', {\n fix: 'Pass a JSON object/array/string, e.g. --data \\'{\"question\":\"...\"}\\'.',\n });\n }\n}\n\nfunction decodeChallenge(res: HttpResponse, url: string): PaymentRequired {\n const encoded = res.header(PAYMENT_REQUIRED_HEADER);\n if (encoded === undefined) {\n throw new CliError(\n 'CONTRACT_MISMATCH',\n `The 402 from ${url} carried no PAYMENT-REQUIRED header.`,\n {\n fix: 'The endpoint does not speak x402 v2; nothing was paid.',\n },\n );\n }\n try {\n return decodePaymentRequiredHeader(encoded);\n } catch (err) {\n throw new CliError('CONTRACT_MISMATCH', 'Could not decode the PAYMENT-REQUIRED header.', {\n cause: err,\n });\n }\n}\n\n/** The registry gate: only a `verified` outcome returns; everything else throws. */\nasync function assertRegistryVerified(\n settings: ResolvedSettings,\n url: string,\n requirement: PaymentRequirements,\n timeoutMs: number,\n ctx: CommandContext,\n): Promise<string> {\n const verification = await verifyAgainstRegistries(\n settings.bazaarRegistries,\n url,\n requirement,\n timeoutMs,\n { dataDir: ctx.dataDir },\n );\n switch (verification.outcome) {\n case 'verified':\n return verification.registry;\n case 'mismatch':\n throw new CliError(\n 'REGISTRY_MISMATCH',\n `The live 402 does not match what ${verification.registry} advertises for this resource (${verification.detail}).`,\n {\n fix: 'Nothing was signed. Re-run `tenjin discover` to see the advertised terms; if the seller changed them, the registry will catch up.',\n details: { registry: verification.registry, detail: verification.detail },\n },\n );\n case 'unlisted':\n throw new CliError('USAGE', 'No configured registry is known to list this resource.', {\n fix: 'The Bazaar lane pays publicly listed deals only, and pay-time lookup leans on the local `discover` cache: run `tenjin discover [query]` so a sweep can surface this endpoint, then re-run pay.',\n });\n case 'unavailable':\n throw new CliError(\n 'NETWORK_ERROR',\n 'No configured registry answered; the Bazaar lane fails closed.',\n {\n fix: 'Retry when the registries are reachable.',\n details: { errors: verification.errors },\n },\n );\n }\n}\n\n/** Discriminated on `paid`: a paid delivery always carries what it paid and to\n * whom, so no branch ever reaches for an amount that might not be there. */\ntype DeliverOpts =\n | {\n paid: false;\n /** Free because the wallet was already entitled (SIWX), not free-of-price. */\n entitled?: boolean;\n printBody: boolean;\n }\n | {\n paid: true;\n amountAtomic: bigint;\n requirement: PaymentRequirements;\n registry?: string;\n printBody: boolean;\n };\n\nfunction deliver(url: string, lane: Lane, res: HttpResponse, opts: DeliverOpts): CommandResult {\n const settlementTxHash = opts.paid ? settlementTx(res) : undefined;\n const data = {\n url,\n lane,\n status: res.status,\n paid: opts.paid,\n ...(opts.paid\n ? {\n amountPaid: toMoney(opts.amountAtomic.toString()),\n payTo: opts.requirement.payTo,\n network: opts.requirement.network,\n ...(opts.registry !== undefined ? { registry: opts.registry } : {}),\n }\n : opts.entitled === true\n ? { entitled: true }\n : {}),\n ...(settlementTxHash !== undefined ? { settlementTxHash } : {}),\n // The body is the product: JSON when the endpoint spoke it, raw text always.\n ...(res.json !== undefined ? { body: res.json } : {}),\n bodyText: res.text,\n };\n const headline = opts.paid\n ? `paid ${toMoney(opts.amountAtomic.toString()).usd} USD to ${sanitizeForTerminal(new URL(url).host)}` +\n (settlementTxHash !== undefined ? ` (tx ${settlementTxHash})` : '')\n : opts.entitled === true\n ? `free (entitled, no charge)`\n : `free (${res.status}, no charge)`;\n const body = sanitizeForTerminal(res.text);\n const preview =\n opts.printBody || body.length <= BODY_PREVIEW_CHARS\n ? body\n : `${body.slice(0, BODY_PREVIEW_CHARS)}\\n… truncated; run with --print-body or --json for the full body`;\n return { data, humanLines: [headline, ...(preview.length > 0 ? [preview] : [])] };\n}\n\nfunction settlementTx(res: HttpResponse): string | undefined {\n const header = res.header(PAYMENT_RESPONSE_HEADER);\n if (header === undefined) return undefined;\n try {\n const settle = decodePaymentResponseHeader(header);\n const tx = (settle as { transaction?: unknown }).transaction;\n return typeof tx === 'string' ? tx : undefined;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAM,0BAA0B;AAChC,IAAM,0BAA0B;AAGhC,IAA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AoB,IAAI,IAAI,GAAG,EAAE,IAAI,CAAC,MACjG,qBAAqB,SAAY,QAAQ,gBAAgB,MAAM,MAChE,KAAK,aAAa,OAChB,+BACA,SAAS,IAAI,MAAM;AACzB,QAAM,OAAO,oBAAoB,IAAI,IAAI;AACzC,QAAM,UACJ,KAAK,aAAa,KAAK,UAAU,qBAC7B,OACA,GAAG,KAAK,MAAM,GAAG,kBAAkB,CAAC;AAAA;AAC1C,SAAO,EAAE,MAAM,YAAY,CAAC,UAAU,GAAI,QAAQ,SAAS,IAAI,CAAC,OAAO,IAAI,CAAC,CAAE,EAAE;AAClF;AAEA,SAAS,aAAa,KAAuC;AAC3D,QAAM,SAAS,IAAI,OAAO,uBAAuB;AACjD,MAAI,WAAW,OAAW,QAAO;AACjC,MAAI;AACF,UAAM,SAAS,4BAA4B,MAAM;AACjD,UAAM,KAAM,OAAqC;AACjD,WAAO,OAAO,OAAO,WAAW,KAAK;AAAA,EACvC,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/publish-LXWFDIKF.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
runPublish
|
|
4
|
-
} from "./chunk-V44J2MXV.js";
|
|
5
|
-
import "./chunk-VJSQSLBM.js";
|
|
6
|
-
import "./chunk-QQ6ELLSA.js";
|
|
7
|
-
import "./chunk-SGK2B724.js";
|
|
8
|
-
import "./chunk-KINZ23CV.js";
|
|
9
|
-
import "./chunk-DBU5CXBV.js";
|
|
10
|
-
import "./chunk-KZAAWQNP.js";
|
|
11
|
-
import "./chunk-S5RYMCV6.js";
|
|
12
|
-
import "./chunk-POJRB2AE.js";
|
|
13
|
-
import "./chunk-YLYINX2H.js";
|
|
14
|
-
import "./chunk-ITUXPJIS.js";
|
|
15
|
-
import "./chunk-CPCX67TI.js";
|
|
16
|
-
import "./chunk-M2O56UK7.js";
|
|
17
|
-
import "./chunk-UHTVXQ2O.js";
|
|
18
|
-
import "./chunk-HRGBS2PA.js";
|
|
19
|
-
import "./chunk-EDZSNPE5.js";
|
|
20
|
-
import "./chunk-5QQTYWEU.js";
|
|
21
|
-
import "./chunk-GHLVXVZD.js";
|
|
22
|
-
import "./chunk-OLWTRUTS.js";
|
|
23
|
-
import "./chunk-VYOJOX4Z.js";
|
|
24
|
-
import "./chunk-EFWZPUTC.js";
|
|
25
|
-
import "./chunk-U6VPKMGC.js";
|
|
26
|
-
import "./chunk-UO22YNY4.js";
|
|
27
|
-
import "./chunk-A5DKHMUN.js";
|
|
28
|
-
import "./chunk-3GL2Z5QK.js";
|
|
29
|
-
import "./chunk-JBIKAAT3.js";
|
|
30
|
-
import "./chunk-2MYQN7HM.js";
|
|
31
|
-
import "./chunk-ZOBNS7CX.js";
|
|
32
|
-
import "./chunk-ZFJJ3EXC.js";
|
|
33
|
-
import "./chunk-W6R3HAAG.js";
|
|
34
|
-
import "./chunk-47PP7TAG.js";
|
|
35
|
-
import "./chunk-XJN5WUKL.js";
|
|
36
|
-
import "./chunk-RBJPAZFI.js";
|
|
37
|
-
import "./chunk-KYQVEKP5.js";
|
|
38
|
-
import "./chunk-ZXTAQYNA.js";
|
|
39
|
-
export {
|
|
40
|
-
runPublish
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=publish-LXWFDIKF.js.map
|
package/dist/read-JMNUQ56P.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
deliverExisting,
|
|
4
|
-
deliverFresh,
|
|
5
|
-
parseSectionsBudget
|
|
6
|
-
} from "./chunk-CAR6FHK6.js";
|
|
7
|
-
import {
|
|
8
|
-
fetchRead
|
|
9
|
-
} from "./chunk-LRYV3SK7.js";
|
|
10
|
-
import "./chunk-SGK2B724.js";
|
|
11
|
-
import "./chunk-KINZ23CV.js";
|
|
12
|
-
import "./chunk-DBU5CXBV.js";
|
|
13
|
-
import "./chunk-KZAAWQNP.js";
|
|
14
|
-
import "./chunk-S5RYMCV6.js";
|
|
15
|
-
import "./chunk-POJRB2AE.js";
|
|
16
|
-
import "./chunk-YLYINX2H.js";
|
|
17
|
-
import {
|
|
18
|
-
findDelivered,
|
|
19
|
-
findDeliveredByUrl,
|
|
20
|
-
resolveResourceRef
|
|
21
|
-
} from "./chunk-VJQKL3YH.js";
|
|
22
|
-
import "./chunk-ITUXPJIS.js";
|
|
23
|
-
import "./chunk-UHTVXQ2O.js";
|
|
24
|
-
import {
|
|
25
|
-
isSessionPresentable,
|
|
26
|
-
loadSessionFile,
|
|
27
|
-
signWithSession
|
|
28
|
-
} from "./chunk-HRGBS2PA.js";
|
|
29
|
-
import {
|
|
30
|
-
originOf
|
|
31
|
-
} from "./chunk-EDZSNPE5.js";
|
|
32
|
-
import "./chunk-5QQTYWEU.js";
|
|
33
|
-
import {
|
|
34
|
-
sanitizeForTerminal
|
|
35
|
-
} from "./chunk-OLWTRUTS.js";
|
|
36
|
-
import {
|
|
37
|
-
resolveContextSettings
|
|
38
|
-
} from "./chunk-VYOJOX4Z.js";
|
|
39
|
-
import {
|
|
40
|
-
formatUsdDisplay,
|
|
41
|
-
toMoney
|
|
42
|
-
} from "./chunk-EFWZPUTC.js";
|
|
43
|
-
import "./chunk-U6VPKMGC.js";
|
|
44
|
-
import "./chunk-UO22YNY4.js";
|
|
45
|
-
import "./chunk-A5DKHMUN.js";
|
|
46
|
-
import "./chunk-3GL2Z5QK.js";
|
|
47
|
-
import "./chunk-JBIKAAT3.js";
|
|
48
|
-
import "./chunk-2MYQN7HM.js";
|
|
49
|
-
import "./chunk-ZOBNS7CX.js";
|
|
50
|
-
import {
|
|
51
|
-
CliError
|
|
52
|
-
} from "./chunk-ZFJJ3EXC.js";
|
|
53
|
-
import "./chunk-W6R3HAAG.js";
|
|
54
|
-
import "./chunk-XJN5WUKL.js";
|
|
55
|
-
import "./chunk-RBJPAZFI.js";
|
|
56
|
-
import "./chunk-KYQVEKP5.js";
|
|
57
|
-
import "./chunk-ZXTAQYNA.js";
|
|
58
|
-
|
|
59
|
-
// src/commands/read.ts
|
|
60
|
-
async function runRead(args, ctx, deps = {}) {
|
|
61
|
-
const settings = await resolveContextSettings(ctx);
|
|
62
|
-
const sectionsBudget = parseSectionsBudget(args.sections);
|
|
63
|
-
const ref = await resolveResourceRef(args.ref, ctx.dataDir, settings.baseUrl);
|
|
64
|
-
const presentOpts = { printBody: args.printBody === true, sectionsBudget };
|
|
65
|
-
const existing = ref.resourceId !== void 0 ? await findDelivered(ctx.dataDir, ref.resourceId) : await findDeliveredByUrl(ctx.dataDir, ref.url);
|
|
66
|
-
if (existing !== null) {
|
|
67
|
-
return deliverExisting(existing, presentOpts);
|
|
68
|
-
}
|
|
69
|
-
const fetchOpts = {
|
|
70
|
-
timeoutMs: ctx.flags.timeout,
|
|
71
|
-
...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
|
|
72
|
-
};
|
|
73
|
-
const first = await fetchRead(ref.url, fetchOpts);
|
|
74
|
-
if (first.kind === "entitled") {
|
|
75
|
-
return await deliverFresh(ctx.dataDir, ref.url, first.body, "free", void 0, presentOpts);
|
|
76
|
-
}
|
|
77
|
-
if (first.kind === "already_purchased") {
|
|
78
|
-
throw new CliError("API_UNREACHABLE", "Unexpected 409 on an unauthenticated read.", {
|
|
79
|
-
fix: "Retry; if it persists, update tenjin-cli."
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
const firstRequirement = first.paymentRequired.accepts[0];
|
|
83
|
-
if (firstRequirement === void 0) {
|
|
84
|
-
throw new CliError("PAYMENT_FAILED", "The 402 advertised no payment requirements.", {
|
|
85
|
-
fix: "Try another candidate; this resource looks misconfigured."
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
const cached = await loadSessionFile(ctx.dataDir);
|
|
89
|
-
const now = deps.now ?? Date.now;
|
|
90
|
-
const origin = originOf(ref.url);
|
|
91
|
-
const outcome = await presentIfUsable(cached, origin, now, ref.url, fetchOpts);
|
|
92
|
-
if (outcome.kind === "entitled") {
|
|
93
|
-
return await deliverFresh(
|
|
94
|
-
ctx.dataDir,
|
|
95
|
-
ref.url,
|
|
96
|
-
outcome.body,
|
|
97
|
-
"entitled",
|
|
98
|
-
void 0,
|
|
99
|
-
presentOpts
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
throw refusal(ref, firstRequirement, outcome.check);
|
|
103
|
-
}
|
|
104
|
-
var LOUD_CODES = /* @__PURE__ */ new Set(["CONTRACT_MISMATCH", "RATE_LIMITED"]);
|
|
105
|
-
async function presentIfUsable(cached, origin, now, url, fetchOpts) {
|
|
106
|
-
if (cached === null) return { kind: "refuse", check: "not_performed" };
|
|
107
|
-
if (cached.origin !== origin) {
|
|
108
|
-
return { kind: "refuse", check: "session_origin_mismatch" };
|
|
109
|
-
}
|
|
110
|
-
if (!isSessionPresentable(cached, now(), "read", origin)) {
|
|
111
|
-
return { kind: "refuse", check: "not_performed" };
|
|
112
|
-
}
|
|
113
|
-
return await present(cached, url, fetchOpts, now);
|
|
114
|
-
}
|
|
115
|
-
async function present(session, url, fetchOpts, now) {
|
|
116
|
-
let second;
|
|
117
|
-
try {
|
|
118
|
-
const sessionHeaders = await signWithSession(session, { method: "GET", url }, { now });
|
|
119
|
-
second = await fetchRead(url, { ...fetchOpts, sessionHeaders });
|
|
120
|
-
} catch (err) {
|
|
121
|
-
if (err instanceof CliError && LOUD_CODES.has(err.code)) throw err;
|
|
122
|
-
return { kind: "refuse", check: "session_inconclusive" };
|
|
123
|
-
}
|
|
124
|
-
switch (second.kind) {
|
|
125
|
-
case "entitled":
|
|
126
|
-
return { kind: "entitled", body: second.body };
|
|
127
|
-
case "payment_required":
|
|
128
|
-
return { kind: "refuse", check: "session" };
|
|
129
|
-
case "session_rejected":
|
|
130
|
-
return { kind: "refuse", check: "session_rejected" };
|
|
131
|
-
case "already_purchased":
|
|
132
|
-
return { kind: "refuse", check: "session_inconclusive" };
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
function refusal(ref, requirement, check) {
|
|
136
|
-
const price = toMoney(requirement.amount);
|
|
137
|
-
const priceText = `${formatUsdDisplay(price.atomic)} USD (${price.atomic} atomic)`;
|
|
138
|
-
const url = sanitizeForTerminal(ref.url);
|
|
139
|
-
const buyFix = `Run \`tenjin buy ${url}\` to pay and read it, or \`tenjin inspect\` for the card first.`;
|
|
140
|
-
const mismatch = check === "session_origin_mismatch";
|
|
141
|
-
const mintable = check !== "session" && !mismatch;
|
|
142
|
-
const fix = mismatch ? `Your session key was minted for a different Tenjin deployment, so it was not presented. Read from the origin it belongs to, rather than minting a new session against this one. Check the configured origin with \`tenjin config get baseUrl\` and drop any host override. ${buyFix}` : mintable ? `${buyFix} If you already bought it, \`tenjin session start --scope read\` lets this read recover it free.` : buyFix;
|
|
143
|
-
return new CliError("REFUSED", `This piece costs ${priceText}; \`tenjin read\` never pays.`, {
|
|
144
|
-
fix,
|
|
145
|
-
details: {
|
|
146
|
-
reason: "payment_required",
|
|
147
|
-
entitlementCheck: check,
|
|
148
|
-
url: ref.url,
|
|
149
|
-
...ref.resourceId !== void 0 ? { resourceId: ref.resourceId } : {},
|
|
150
|
-
price,
|
|
151
|
-
network: requirement.network,
|
|
152
|
-
buyCommand: `tenjin buy ${ref.url}`,
|
|
153
|
-
...mintable ? { sessionCommand: "tenjin session start --scope read" } : {}
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
export {
|
|
158
|
-
runRead
|
|
159
|
-
};
|
|
160
|
-
//# sourceMappingURL=read-JMNUQ56P.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/commands/read.ts"],"sourcesContent":["import { CliError } from '../lib/errors';\nimport { formatUsdDisplay, toMoney } from '../lib/money';\nimport { resolveContextSettings } from '../lib/settings';\nimport { resolveResourceRef } from '../lib/resource-ref';\nimport { fetchRead } from '../lib/read-client';\nimport type { ReadBody, SessionReadResult } from '../lib/read-client';\nimport { findDelivered, findDeliveredByUrl } from '../lib/library';\nimport {\n deliverExisting,\n deliverFresh,\n parseSectionsBudget,\n type PresentOpts,\n} from '../lib/delivery';\nimport { sanitizeForTerminal } from '../lib/output';\nimport { isSessionPresentable, loadSessionFile, signWithSession } from '../lib/session-present';\nimport type { SessionFile } from '../lib/session-present';\nimport { originOf } from '../lib/url';\nimport type { CommandContext, CommandResult } from '../context';\n\n/**\n * `tenjin read <resource-url-or-id>`, the FREE-ONLY delivery verb (#42).\n *\n * `buy` was the only verb that delivered a body, so a zero-cost re-read of\n * something you already own was indistinguishable — to a prefix-matching harness\n * permission classifier, and to a human reading a transcript — from a purchase.\n * `read` is the half of `buy` that never spends:\n * 1. local library (already delivered → re-deliver from disk, no network)\n * 2. first GET, unauthenticated → a FREE resource delivers immediately\n * 3. a PAID resource, with a read-scoped session key on disk for THIS origin →\n * present it on ONE bodyless signed GET; a 200 means this wallet owns the\n * piece and it delivers, free\n * 4. anything else → REFUSED (exit 3), naming the price, and pointing at\n * `tenjin buy` only when the server actually answered \"you do not own this\".\n * Nothing is charged, and the refusal lands before any payment could be\n * constructed, because none can be.\n *\n * The hard invariant, test-pinned rather than merely intended (read.test.ts): this\n * module and its whole transitive import graph never reach `lib/x402-pay`,\n * `lib/wallet`, or `lib/session-key`. Step 3 uses the present-only half, so read\n * can load a delegation and sign with it but cannot mint one and cannot pay.\n * Those two are the whole of what the pin guarantees; what a minted delegation is\n * worth to a holder is answered in `lib/permissions.ts`.\n *\n * Step 3 therefore presents ONLY to the origin the session was minted against.\n * `--base-url` rides this verb like every other and `read` is always-safe, so\n * without that check one auto-allowed command line would hand a wallet-derived\n * credential to a host an agent picked.\n */\n\nexport interface ReadArgs {\n ref: string;\n /** Include the full body in the machine output (default: outline only). */\n printBody?: boolean;\n /** Include leading sections within this token budget (deterministic split). */\n sections?: string;\n}\n\nexport interface ReadDeps {\n /** No `provider`/`authorizer` seam, unlike BuyDeps: there is no wallet to inject. */\n fetchImpl?: typeof fetch;\n /** Clock seam (ms since epoch) for the session-expiry decision. */\n now?: () => number;\n}\n\nexport async function runRead(\n args: ReadArgs,\n ctx: CommandContext,\n deps: ReadDeps = {},\n): Promise<CommandResult> {\n const settings = await resolveContextSettings(ctx);\n const sectionsBudget = parseSectionsBudget(args.sections);\n const ref = await resolveResourceRef(args.ref, ctx.dataDir, settings.baseUrl);\n const presentOpts: PresentOpts = { printBody: args.printBody === true, sectionsBudget };\n\n // 1. Library idempotence, BEFORE any network: an owned resource re-delivers\n // from disk. This is the case #42 exists for — the re-read that used to need\n // a `buy` approval. Matched by id or by url, exactly as buy matches it.\n const existing =\n ref.resourceId !== undefined\n ? await findDelivered(ctx.dataDir, ref.resourceId)\n : await findDeliveredByUrl(ctx.dataDir, ref.url);\n if (existing !== null) {\n return deliverExisting(existing, presentOpts);\n }\n\n const fetchOpts = {\n timeoutMs: ctx.flags.timeout,\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n };\n\n // 2. First GET, unauthenticated — the same probe buy opens with, and like buy's\n // probe it is unattributed (no search id rides a non-purchase).\n const first = await fetchRead(ref.url, fetchOpts);\n\n if (first.kind === 'entitled') {\n // Free resource (no payment challenge was issued): deliver and save. No wallet\n // was resolved to get here.\n return await deliverFresh(ctx.dataDir, ref.url, first.body, 'free', undefined, presentOpts);\n }\n\n if (first.kind === 'already_purchased') {\n // A plain GET carries no payment header, so the read route cannot answer the\n // owned-re-pay 409 here; the contract makes this unreachable. Same loud failure\n // buy raises rather than guessing a recovery chain.\n throw new CliError('API_UNREACHABLE', 'Unexpected 409 on an unauthenticated read.', {\n fix: 'Retry; if it persists, update tenjin-cli.',\n });\n }\n\n // A paid resource. Capture the advertised price: it is what the refusal reports.\n const firstRequirement = first.paymentRequired.accepts[0];\n if (firstRequirement === undefined) {\n throw new CliError('PAYMENT_FAILED', 'The 402 advertised no payment requirements.', {\n fix: 'Try another candidate; this resource looks misconfigured.',\n });\n }\n\n // 3. Paid and not on disk. A live session key minted for THIS origin means the\n // wallet may already own the piece. Exactly one attempt: re-establishing\n // would need the wallet this module cannot reach.\n const cached = await loadSessionFile(ctx.dataDir);\n const now = deps.now ?? Date.now;\n // Against the origin of the URL actually being signed, not the configured base\n // URL. They are equal only because `resolveResourceRef` asserted it in another\n // module; checking the request target makes this guard locally sound instead of\n // dependent on a pin someone could move.\n const origin = originOf(ref.url);\n const outcome = await presentIfUsable(cached, origin, now, ref.url, fetchOpts);\n if (outcome.kind === 'entitled') {\n return await deliverFresh(\n ctx.dataDir,\n ref.url,\n outcome.body,\n 'entitled',\n undefined,\n presentOpts,\n );\n }\n\n // 4. Not entitled, not asked, or not answered: refuse (exit 3) on the advertised\n // price. No payment is constructed; none can be.\n throw refusal(ref, firstRequirement, outcome.check);\n}\n\n/** What the entitlement question got, which is not the same as what was asked. */\ntype EntitlementCheck =\n | 'not_performed'\n | 'session'\n | 'session_rejected'\n | 'session_inconclusive'\n | 'session_origin_mismatch';\n\ntype PresentOutcome =\n { kind: 'entitled'; body: ReadBody } | { kind: 'refuse'; check: EntitlementCheck };\n\n/** Failures that must NOT be folded into a price refusal; see `present`. */\nconst LOUD_CODES = new Set(['CONTRACT_MISMATCH', 'RATE_LIMITED']);\n\n/**\n * Decide whether the cached session may be presented, and present it if so.\n *\n * The origin mismatch is its own outcome rather than \"no session\": the two are\n * indistinguishable to an agent, and the remedy for one is the remedy the other\n * must NOT get. `not_performed` tells the agent to run `session start`, which is\n * the single verb that opens the keystore — and an agent that reached a mismatch\n * by carrying `--base-url` would carry it straight into that suggestion, minting\n * a wallet-signed delegation against the wrong host and clobbering the good one.\n */\nasync function presentIfUsable(\n cached: SessionFile | null,\n origin: string,\n now: () => number,\n url: string,\n fetchOpts: { timeoutMs: number; fetchImpl?: typeof fetch },\n): Promise<PresentOutcome> {\n if (cached === null) return { kind: 'refuse', check: 'not_performed' };\n if (cached.origin !== origin) {\n return { kind: 'refuse', check: 'session_origin_mismatch' };\n }\n if (!isSessionPresentable(cached, now(), 'read', origin)) {\n return { kind: 'refuse', check: 'not_performed' };\n }\n return await present(cached, url, fetchOpts, now);\n}\n\n/**\n * The one signed GET. Never throws for a transport failure: the first 402 already\n * told us the price, and losing it turns a recoverable refusal into a bare\n * network error that says nothing about the piece. Two exceptions stay loud: a\n * blocked redirect (a signal about where a credential was nearly sent) and a\n * rate limit (a recoverable pause the CLI models explicitly everywhere else —\n * swallowing it costs a looping agent its backoff and points it at a\n * keystore-opening command instead).\n */\nasync function present(\n session: SessionFile,\n url: string,\n fetchOpts: { timeoutMs: number; fetchImpl?: typeof fetch },\n now: () => number,\n): Promise<PresentOutcome> {\n let second: SessionReadResult;\n try {\n const sessionHeaders = await signWithSession(session, { method: 'GET', url }, { now });\n second = await fetchRead(url, { ...fetchOpts, sessionHeaders });\n } catch (err) {\n if (err instanceof CliError && LOUD_CODES.has(err.code)) throw err;\n return { kind: 'refuse', check: 'session_inconclusive' };\n }\n switch (second.kind) {\n case 'entitled':\n return { kind: 'entitled', body: second.body };\n case 'payment_required':\n // The only state where the server actually answered the ownership question.\n return { kind: 'refuse', check: 'session' };\n case 'session_rejected':\n // The delegation was declined (expired, revoked, origin drift, rotated\n // wallet). The entitlement question was never asked, so \"you must buy\" is\n // not the answer — re-minting is.\n return { kind: 'refuse', check: 'session_rejected' };\n case 'already_purchased':\n // A 409 on a request carrying no payment is contract-anomalous: the server\n // said \"already purchased\" and delivered nothing. Handled by name rather\n // than swept into a default, because the one thing this must never become\n // is a price refusal telling the agent to buy what it was just told it owns.\n return { kind: 'refuse', check: 'session_inconclusive' };\n }\n}\n\n/**\n * The exit-3 refusal: the price, in human money, plus the move that actually gets\n * past it. `entitlementCheck` reports what the server said, and the fix follows\n * from it rather than from a single default:\n *\n * - `session` — the server answered \"you do not own this\". Buying is the answer.\n * - `session_origin_mismatch` — a session exists, for a DIFFERENT origin. The\n * remedy is to stop redirecting the CLI, never to mint. `sessionCommand` is\n * deliberately absent: recommending it here would send an agent that still\n * carries `--base-url` to wallet-sign a delegation against the wrong host and\n * overwrite the good one.\n * - everything else — the question is still open, so re-minting may deliver it\n * free and `sessionCommand` rides.\n */\nfunction refusal(\n ref: { url: string; resourceId?: string },\n requirement: { amount: string; network: string },\n check: EntitlementCheck,\n): CliError {\n const price = toMoney(requirement.amount);\n // formatUsdDisplay (not the machine `usd`) because this string is human copy:\n // a price a person reads renders as 0.10, never 0.1.\n const priceText = `${formatUsdDisplay(price.atomic)} USD (${price.atomic} atomic)`;\n const url = sanitizeForTerminal(ref.url);\n const buyFix = `Run \\`tenjin buy ${url}\\` to pay and read it, or \\`tenjin inspect\\` for the card first.`;\n const mismatch = check === 'session_origin_mismatch';\n const mintable = check !== 'session' && !mismatch;\n const fix = mismatch\n ? `Your session key was minted for a different Tenjin deployment, so it was not presented. Read from the origin it belongs to, rather than minting a new session against this one. Check the configured origin with \\`tenjin config get baseUrl\\` and drop any host override. ${buyFix}`\n : mintable\n ? `${buyFix} If you already bought it, \\`tenjin session start --scope read\\` lets this read recover it free.`\n : buyFix;\n return new CliError('REFUSED', `This piece costs ${priceText}; \\`tenjin read\\` never pays.`, {\n fix,\n details: {\n reason: 'payment_required',\n entitlementCheck: check,\n url: ref.url,\n ...(ref.resourceId !== undefined ? { resourceId: ref.resourceId } : {}),\n price,\n network: requirement.network,\n buyCommand: `tenjin buy ${ref.url}`,\n ...(mintable ? { sessionCommand: 'tenjin session start --scope read' } : {}),\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,eAAsB,QACpB,MACA,KACA,OAAiB,CAAC,GACM;AACxB,QAAM,WAAW,MAAM,uBAAuB,GAAG;AACjD,QAAM,iBAAiB,oBAAoB,KAAK,QAAQ;AACxD,QAAM,MAAM,MAAM,mBAAmB,KAAK,KAAK,IAAI,SA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