@wirecat/zoom-cli 0.80.0 → 0.82.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/contracts/wirecat.json +71 -3
- package/dist/answers.d.ts +100 -0
- package/dist/answers.d.ts.map +1 -1
- package/dist/bin/zm.js +2 -2
- package/dist/bundle/agent-F4TRJWWS.js +46 -0
- package/dist/bundle/{all-profiles-5GOKWOT4.js → all-profiles-RULEKTDQ.js} +64 -22
- package/dist/bundle/answer-policy-6XC57AEZ.js +131 -0
- package/dist/bundle/{anthropic-NHXMOFYS.js → anthropic-4NAQBZFL.js} +6 -6
- package/dist/bundle/{app-server-HFW5Z5PI.js → app-server-VLR42U5L.js} +92 -80
- package/dist/bundle/{bun-M5IGY2TG.js → bun-OPDGMZZQ.js} +2 -2
- package/dist/bundle/{bun-sqlite-MTP5JJQ2.js → bun-sqlite-HC6X4AOX.js} +7 -7
- package/dist/bundle/{chunk-TNL3YQ33.js → chunk-274SLQNW.js} +2 -2
- package/dist/bundle/{chunk-5CJ6AAUI.js → chunk-2CI2OEZQ.js} +4 -4
- package/dist/bundle/{chunk-GVKZZT7E.js → chunk-2DBF2IIC.js} +7 -78
- package/dist/bundle/{chunk-NRVMK5H3.js → chunk-2GP573Q4.js} +15748 -11939
- package/dist/bundle/{chunk-4OAR7BGU.js → chunk-2JHVQMVC.js} +1 -1
- package/dist/bundle/{chunk-XKLU5KV2.js → chunk-2SWKQ7C4.js} +1 -1
- package/dist/bundle/{chunk-W3GZ7JUO.js → chunk-2XBDILVW.js} +1 -1
- package/dist/bundle/{chunk-3UONR5HW.js → chunk-3HC5F3P7.js} +1 -1
- package/dist/bundle/{chunk-VN7TKMOW.js → chunk-3YM4B2GT.js} +1 -1
- package/dist/bundle/{chunk-PCPOO5FS.js → chunk-434YFJAE.js} +2 -2
- package/dist/bundle/{chunk-CW6CPQHI.js → chunk-4HLQ2JGK.js} +4 -4
- package/dist/bundle/{chunk-RT7C3SSJ.js → chunk-4N7PP76S.js} +1 -1
- package/dist/bundle/{chunk-JJX4HKDV.js → chunk-52Y4ETKU.js} +4 -4
- package/dist/bundle/{chunk-BIKHHFD2.js → chunk-5HAUK3I4.js} +2166 -2760
- package/dist/bundle/{chunk-W2QDYMAM.js → chunk-5KYQ53EF.js} +13 -9
- package/dist/bundle/{chunk-BW5JEOBE.js → chunk-5TU7Y5UW.js} +12 -12
- package/dist/bundle/{chunk-P2JTVRGU.js → chunk-66ALX4ZI.js} +168 -168
- package/dist/bundle/{chunk-EPIA2UUM.js → chunk-676C2LE6.js} +12 -12
- package/dist/bundle/{chunk-BNEJKGG7.js → chunk-6CWL5BKG.js} +78 -76
- package/dist/bundle/{chunk-TDBVM2SS.js → chunk-6QYZP4E2.js} +3 -3
- package/dist/bundle/{chunk-JXSEH64A.js → chunk-6VK332XS.js} +3 -3
- package/dist/bundle/{chunk-W7M4JYEE.js → chunk-73MOMNLL.js} +1 -1
- package/dist/bundle/{chunk-K672XJ2P.js → chunk-7QPIUMUG.js} +12 -12
- package/dist/bundle/{chunk-CWCDCNXA.js → chunk-7UVDPRFK.js} +6 -6
- package/dist/bundle/{chunk-RMX2WPWS.js → chunk-A6EZK5RG.js} +4 -4
- package/dist/bundle/{chunk-ONJPUFLX.js → chunk-AC6VJNMJ.js} +1 -1
- package/dist/bundle/{chunk-QIK2IBJ4.js → chunk-ACI4YIEH.js} +23 -7
- package/dist/bundle/{chunk-UX4JZMA4.js → chunk-AIKFOBDO.js} +278 -59
- package/dist/bundle/{chunk-GCPO7T2X.js → chunk-ASBDFXLS.js} +3 -3
- package/dist/bundle/{chunk-O4ZBFATF.js → chunk-B32KZRQM.js} +12 -12
- package/dist/bundle/{chunk-5RVXXDN7.js → chunk-BBGJQMRI.js} +1 -1
- package/dist/bundle/chunk-BDKVOU3I.js +52 -0
- package/dist/bundle/{chunk-GCUOZ2OA.js → chunk-BP4FYANF.js} +6 -6
- package/dist/bundle/{chunk-XTCAWNBP.js → chunk-DCYFT3FR.js} +4 -4
- package/dist/bundle/{chunk-FPUGMDJV.js → chunk-DNCLQPOM.js} +1 -1
- package/dist/bundle/{chunk-PKW3TPNP.js → chunk-DSZYABYL.js} +38 -19
- package/dist/bundle/{chunk-6MDL2LZA.js → chunk-E745WZKY.js} +8 -8
- package/dist/bundle/chunk-EGTCQKHV.js +340 -0
- package/dist/bundle/chunk-EQG3PIH2.js +108 -0
- package/dist/bundle/{chunk-ZPZT46O6.js → chunk-ESN3W2MZ.js} +48 -12
- package/dist/bundle/{chunk-7U5X37TE.js → chunk-G46WJ7YO.js} +6 -6
- package/dist/bundle/{chunk-L6FM5RQY.js → chunk-G6PETRMV.js} +3 -3
- package/dist/bundle/chunk-GBHMT2IU.js +755 -0
- package/dist/bundle/{chunk-6QCBTBDA.js → chunk-GGMAIIVE.js} +1 -1
- package/dist/bundle/{chunk-6I4C4ZFT.js → chunk-GTKPMYK7.js} +2 -2
- package/dist/bundle/{chunk-N5YUHN6S.js → chunk-GWGHH56B.js} +12 -12
- package/dist/bundle/{chunk-5XO2AY6D.js → chunk-HC6VN5CO.js} +10 -10
- package/dist/bundle/{chunk-ARL2TTPZ.js → chunk-HP7A2ZOP.js} +9 -9
- package/dist/bundle/chunk-HZENBDW2.js +209 -0
- package/dist/bundle/{chunk-ST3ZB7LS.js → chunk-IANKXHSE.js} +1 -1
- package/dist/bundle/{chunk-GGKEQQME.js → chunk-ICPJT672.js} +13 -9
- package/dist/bundle/chunk-JQ54DYAQ.js +80 -0
- package/dist/bundle/chunk-K5JGJIV2.js +640 -0
- package/dist/bundle/{chunk-DYRISFHZ.js → chunk-KJ6USQDZ.js} +19 -9
- package/dist/bundle/{chunk-TMYZKDQ7.js → chunk-KKFY23AK.js} +65 -65
- package/dist/bundle/chunk-KQPUVXKX.js +84 -0
- package/dist/bundle/{chunk-BPSURRAD.js → chunk-KVJ3I7UL.js} +43 -64
- package/dist/bundle/{chunk-NXFKZFTC.js → chunk-KWU46LNK.js} +3 -3
- package/dist/bundle/chunk-KXJ3JEDH.js +2 -0
- package/dist/bundle/{chunk-YAA2D6RP.js → chunk-L75SMSJR.js} +5 -5
- package/dist/bundle/{chunk-OXPHJEJ2.js → chunk-LAYYO4WD.js} +3 -3
- package/dist/bundle/{chunk-6PIXP5IH.js → chunk-LEKKTJKK.js} +40 -26
- package/dist/bundle/{chunk-3AOESMW6.js → chunk-M7H4MCAX.js} +18 -259
- package/dist/bundle/{chunk-DZ6H3YJH.js → chunk-MAJJ4PG3.js} +19 -16
- package/dist/bundle/{chunk-G5VH4WUF.js → chunk-MQLPZBMQ.js} +2 -2
- package/dist/bundle/{chunk-3Z7CFQTI.js → chunk-N3JLO63O.js} +1 -1
- package/dist/bundle/{chunk-NMETTKCV.js → chunk-N46F72AF.js} +14 -14
- package/dist/bundle/{chunk-A3TUG2DP.js → chunk-NB7EOAUZ.js} +36 -1
- package/dist/bundle/{chunk-BRMV33MO.js → chunk-NEMX3UNN.js} +4 -4
- package/dist/bundle/{chunk-6CDMGT6Q.js → chunk-OBXQLFT5.js} +2 -2
- package/dist/bundle/{chunk-HH7GR6TN.js → chunk-OGNO35A2.js} +6 -6
- package/dist/bundle/{chunk-Q6MISDKJ.js → chunk-OIPYBF43.js} +3 -3
- package/dist/bundle/{chunk-6LY4LBSD.js → chunk-OO4TRVPB.js} +7 -7
- package/dist/bundle/{chunk-CHEHK6IW.js → chunk-OQFQ77AY.js} +214 -118
- package/dist/bundle/{chunk-5D4AEUVA.js → chunk-PL5P7UKW.js} +434 -1
- package/dist/bundle/{chunk-Q5LUGY2V.js → chunk-PMUPN6JW.js} +9 -9
- package/dist/bundle/chunk-PSKTMMCO.js +561 -0
- package/dist/bundle/{chunk-U5N2PKKM.js → chunk-PWVJUIDQ.js} +2 -2
- package/dist/bundle/{chunk-475P3LWG.js → chunk-Q7ICVP25.js} +1 -1
- package/dist/bundle/{chunk-JGSVWLL2.js → chunk-QG6PILDO.js} +2 -2
- package/dist/bundle/{chunk-5K54M6RD.js → chunk-QPHBK63S.js} +1 -1
- package/dist/bundle/{chunk-RFXJLG5V.js → chunk-QVSL5WJ7.js} +5173 -3077
- package/dist/bundle/{chunk-IQWBGMCR.js → chunk-QVYAV7F2.js} +4 -4
- package/dist/bundle/{chunk-XIHENZW6.js → chunk-R2B6PUVI.js} +4 -4
- package/dist/bundle/{chunk-MH4L5LL6.js → chunk-RQOZBTNI.js} +16 -3
- package/dist/bundle/{chunk-FSLR2YGR.js → chunk-T7IAWEBU.js} +7 -7
- package/dist/bundle/{chunk-D4HKTC2T.js → chunk-TKNM22OH.js} +2 -2
- package/dist/bundle/{chunk-EI37UXDR.js → chunk-TKVBFJ5C.js} +1 -1
- package/dist/bundle/{chunk-O3DYRCIT.js → chunk-TXDR6YSF.js} +1 -1
- package/dist/bundle/{chunk-CWXOXIWS.js → chunk-TY7NDMFY.js} +1 -1
- package/dist/bundle/{chunk-Z3CPZ4I4.js → chunk-UAWSINMC.js} +306 -306
- package/dist/bundle/{chunk-4F7Q5CET.js → chunk-UKAAAOPC.js} +31 -180
- package/dist/bundle/{chunk-XL4ND7CZ.js → chunk-UL2PXLKT.js} +26 -26
- package/dist/bundle/{chunk-GRYXOSN6.js → chunk-UQCTXZEP.js} +10 -10
- package/dist/bundle/{chunk-E3JVLVVB.js → chunk-UR5DBODY.js} +37 -30
- package/dist/bundle/{chunk-SUG6YGAF.js → chunk-V5EJSF2B.js} +237 -167
- package/dist/bundle/{chunk-HGSBLY6M.js → chunk-VB72LTSZ.js} +12 -12
- package/dist/bundle/{chunk-2XZ2YKW4.js → chunk-VB7FZOYX.js} +2 -100
- package/dist/bundle/{chunk-PMO2Z6DQ.js → chunk-VS6WURLX.js} +3 -3
- package/dist/bundle/{chunk-5QXQIZJY.js → chunk-VZ5PPYDG.js} +3 -4
- package/dist/bundle/{chunk-YR5TRWT2.js → chunk-W5QHB53X.js} +287 -580
- package/dist/bundle/{chunk-2P6MQH4V.js → chunk-WMANRJR5.js} +6 -6
- package/dist/bundle/chunk-WOPVBRPV.js +29 -0
- package/dist/bundle/{chunk-W32HK7KG.js → chunk-XQ2WL3HB.js} +2 -2
- package/dist/bundle/{chunk-FIJREKLA.js → chunk-XQQVMECZ.js} +3 -3
- package/dist/bundle/{chunk-75JW7X2W.js → chunk-Y6PVS55U.js} +71 -61
- package/dist/bundle/{chunk-EMYRUJCV.js → chunk-YJXJJ2XP.js} +8 -8
- package/dist/bundle/{chunk-L2TURFT6.js → chunk-YY7XKHDY.js} +10 -3
- package/dist/bundle/chunk-ZED2CJW5.js +353 -0
- package/dist/bundle/chunk-ZOYOXWJB.js +746 -0
- package/dist/bundle/{cli-QNBYDOKV.js → cli-U4O5XB7J.js} +171 -124
- package/dist/bundle/command-contract-FBTK6GQX.js +45 -0
- package/dist/bundle/{command-server-entry-WMA4SWJ5.js → command-server-entry-KKH6ZWJV.js} +35 -35
- package/dist/bundle/config-FRJSIZNN.js +118 -0
- package/dist/bundle/{decode-7PXUXNIP.js → decode-TPCNXEK4.js} +6 -6
- package/dist/bundle/{dispatch-AWDROXWN.js → dispatch-FKMIPCPQ.js} +9 -9
- package/dist/bundle/{dist-TSBH4FOU.js → dist-7CLBCYZN.js} +23 -21
- package/dist/bundle/dist-PAKDDIBT.js +191 -0
- package/dist/bundle/{echarts-WIDIUEO6.js → echarts-O3TNDAXJ.js} +2 -2
- package/dist/bundle/{embed-EIRVQF5E.js → embed-WCJSFVSK.js} +7 -7
- package/dist/bundle/{embedder-MXPM6OXK.js → embedder-TBBUPXBX.js} +10 -10
- package/dist/bundle/{failure-JZW73RP7.js → failure-XTWBYI2A.js} +3 -3
- package/dist/bundle/first-run-ELEMFW42.js +29 -0
- package/dist/bundle/first-screen-DIOBWMKP.js +46 -0
- package/dist/bundle/{folders-TGFOE7DY.js → folders-LXOL4N4S.js} +5 -5
- package/dist/bundle/{instructions-D5LNE6NJ.js → instructions-AMH5RWVJ.js} +1 -1
- package/dist/bundle/{main-OHW5Z56X.js → main-YAA7WQ23.js} +24 -24
- package/dist/bundle/{mcp-RGNRW77S.js → mcp-5HFPWC3W.js} +2 -2
- package/dist/bundle/meeting-combined-UXCF4SJ3.js +26 -0
- package/dist/bundle/meeting-model-3BZJ3EQP.js +26 -0
- package/dist/bundle/{meeting-semantic-FYOVY4S2.js → meeting-semantic-3HU7I2SJ.js} +8 -8
- package/dist/bundle/{meetings-WI4SXPBJ.js → meetings-XWMB6FOH.js} +7 -7
- package/dist/bundle/{node-UEWUFR7N.js → node-EGMCBAO7.js} +2 -2
- package/dist/bundle/{node-sqlite-FJWKJHYU.js → node-sqlite-IJBWENFX.js} +8 -8
- package/dist/bundle/oauth-SZDDAP7A.js +20 -0
- package/dist/bundle/{open-EFYTWUGC.js → open-NS3TMKZX.js} +6 -6
- package/dist/bundle/openai-4DN6WI3B.js +28 -0
- package/dist/bundle/{output-file-J4SU6X4I.js → output-file-2UB5JP3R.js} +6 -6
- package/dist/bundle/{process-U5PLNIDC.js → process-SGHEN6MQ.js} +1 -1
- package/dist/bundle/{program-3JICCSA6.js → program-GVCGZP27.js} +170 -160
- package/dist/bundle/{prompt-YPDMSOKC.js → prompt-HJFMPFVC.js} +6 -6
- package/dist/bundle/public-C2ZB2AGQ.js +198 -0
- package/dist/bundle/{recognize-Z2SSWUKH.js → recognize-2SEI5PPM.js} +5 -5
- package/dist/bundle/{remote-R5HMDHOG.js → remote-2DMS74XE.js} +11 -11
- package/dist/bundle/{rerank-6NGBEMQ2.js → rerank-H6GCYVIA.js} +8 -8
- package/dist/bundle/run-log-QU26SUZP.js +145 -0
- package/dist/bundle/{serve-CU3RMWU7.js → serve-ODVRPFJO.js} +11 -11
- package/dist/bundle/server-NBPF6IDZ.js +95 -0
- package/dist/bundle/{server-SOQSVX2Q.js → server-PCLIO24L.js} +82 -69
- package/dist/bundle/{services-LROZ3RDT.js → services-4QAPXBLO.js} +60 -54
- package/dist/bundle/{speech-AS77HFIF.js → speech-MA6ZT3WE.js} +28 -28
- package/dist/bundle/{sqlite-runtime-U25NS6BK.js → sqlite-runtime-PVMAUXRN.js} +7 -7
- package/dist/bundle/{state-CPEVKK66.js → state-QFMTYUME.js} +7 -7
- package/dist/bundle/{store-6CHRMJM7.js → store-25OTAQC3.js} +31 -24
- package/dist/bundle/{store-QKHCZOYR.js → store-F724QIKJ.js} +34 -26
- package/dist/bundle/store-connection-OGPXANGB.js +111 -0
- package/dist/bundle/store-maintenance-command-2CM7LLNQ.js +83 -0
- package/dist/bundle/{streaming-VDJOYGMO.js → streaming-S22C4DG5.js} +7 -7
- package/dist/bundle/surface-7PXHWCF6.js +81 -0
- package/dist/bundle/{tokens-JBN2OHQB.js → tokens-NLUHA2DW.js} +11 -10
- package/dist/bundle/zm.js +9 -9
- package/dist/bundle/{zoom-app-Q4IKYNG3.js → zoom-app-YWFB367P.js} +8 -8
- package/dist/commands.d.ts +1 -0
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +8 -2
- package/dist/commands.js.map +1 -1
- package/dist/setup-commands.d.ts +1 -1
- package/dist/setup-commands.d.ts.map +1 -1
- package/dist/setup-commands.js +31 -5
- package/dist/setup-commands.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/zoom-api/types.d.ts +5 -0
- package/dist/zoom-api/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/bundle/answer-policy-7PYXHK2I.js +0 -122
- package/dist/bundle/chunk-3BTRJYIT.js +0 -729
- package/dist/bundle/chunk-M4LAF627.js +0 -719
- package/dist/bundle/command-contract-CT6MV6YG.js +0 -45
- package/dist/bundle/config-ZFQFDEVL.js +0 -109
- package/dist/bundle/first-run-K6EHRAIM.js +0 -29
- package/dist/bundle/first-screen-C6AF4KT4.js +0 -45
- package/dist/bundle/meeting-combined-3OKFXZNA.js +0 -26
- package/dist/bundle/meeting-model-4XNF725D.js +0 -26
- package/dist/bundle/oauth-KOONTGLW.js +0 -20
- package/dist/bundle/openai-6Y2JRDNY.js +0 -28
- package/dist/bundle/run-log-LG3TI3WI.js +0 -136
- package/dist/bundle/server-X7JYRMKX.js +0 -85
- package/dist/bundle/store-connection-FCDVOPWB.js +0 -102
- package/dist/bundle/store-maintenance-command-6HVOAHOZ.js +0 -77
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
withTimeLimit
|
|
5
|
+
} from "./chunk-QPHBK63S.js";
|
|
6
|
+
import {
|
|
7
|
+
acquireLock
|
|
8
|
+
} from "./chunk-N46F72AF.js";
|
|
9
|
+
import {
|
|
10
|
+
Credentials,
|
|
11
|
+
isMovedRun,
|
|
12
|
+
keyringService,
|
|
13
|
+
realSleep,
|
|
14
|
+
systemKeyring
|
|
15
|
+
} from "./chunk-6CWL5BKG.js";
|
|
16
|
+
import {
|
|
17
|
+
CliError,
|
|
18
|
+
isCliError
|
|
19
|
+
} from "./chunk-IANKXHSE.js";
|
|
20
|
+
import {
|
|
21
|
+
__name
|
|
22
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
23
|
+
|
|
24
|
+
// node_modules/.pnpm/@wirecat+cli-core@1.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_dd5172c52281f8f1e2dd1d4e9555d5c3/node_modules/@wirecat/cli-core/dist/oauth/storage.js
|
|
25
|
+
var invalid = /* @__PURE__ */ __name(() => new CliError("authentication_error", "the saved sign-in cannot be read; sign in again", { reason: "oauth.invalid" }), "invalid");
|
|
26
|
+
var parse = /* @__PURE__ */ __name((raw) => {
|
|
27
|
+
let value;
|
|
28
|
+
try {
|
|
29
|
+
value = JSON.parse(raw);
|
|
30
|
+
} catch {
|
|
31
|
+
throw invalid();
|
|
32
|
+
}
|
|
33
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
34
|
+
throw invalid();
|
|
35
|
+
return value;
|
|
36
|
+
}, "parse");
|
|
37
|
+
var text = /* @__PURE__ */ __name((value) => typeof value === "string" && value ? value : void 0, "text");
|
|
38
|
+
var finite = /* @__PURE__ */ __name((value) => typeof value === "number" && Number.isFinite(value) ? value : void 0, "finite");
|
|
39
|
+
var previousOf = /* @__PURE__ */ __name((raw) => {
|
|
40
|
+
if (raw === void 0)
|
|
41
|
+
return {};
|
|
42
|
+
try {
|
|
43
|
+
return parse(raw);
|
|
44
|
+
} catch {
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
}, "previousOf");
|
|
48
|
+
var defined = /* @__PURE__ */ __name((value) => Object.fromEntries(Object.entries(value).filter(([, field]) => field !== void 0)), "defined");
|
|
49
|
+
var oauthAccount = /* @__PURE__ */ __name((providerId, profile) => {
|
|
50
|
+
if (!profile.trim())
|
|
51
|
+
throw new CliError("validation_error", "name a profile: a sign-in always belongs to one", {
|
|
52
|
+
reason: "profile.missing"
|
|
53
|
+
});
|
|
54
|
+
return `oauth:${providerId}:${profile}`;
|
|
55
|
+
}, "oauthAccount");
|
|
56
|
+
var standardCodec = /* @__PURE__ */ __name((providerId) => ({
|
|
57
|
+
decode: /* @__PURE__ */ __name((raw) => {
|
|
58
|
+
const value = parse(raw);
|
|
59
|
+
const refreshToken = text(value.refreshToken);
|
|
60
|
+
const clientId = text(value.clientId);
|
|
61
|
+
if (value.version !== 1 || value.provider !== providerId || !refreshToken || !clientId)
|
|
62
|
+
throw invalid();
|
|
63
|
+
if (!Array.isArray(value.scopes) || !value.scopes.every((scope) => typeof scope === "string"))
|
|
64
|
+
throw invalid();
|
|
65
|
+
const source = text(value.clientSource);
|
|
66
|
+
return {
|
|
67
|
+
client: defined({ clientId, clientSecret: text(value.clientSecret), source }),
|
|
68
|
+
tokens: defined({
|
|
69
|
+
accessToken: text(value.accessToken),
|
|
70
|
+
refreshToken,
|
|
71
|
+
expiresAt: finite(value.expiresAt),
|
|
72
|
+
scopes: value.scopes,
|
|
73
|
+
tokenType: text(value.tokenType)
|
|
74
|
+
})
|
|
75
|
+
};
|
|
76
|
+
}, "decode"),
|
|
77
|
+
encode: /* @__PURE__ */ __name(({ tokens, client, previous, extra }) => JSON.stringify(defined({
|
|
78
|
+
...previousOf(previous),
|
|
79
|
+
...extra,
|
|
80
|
+
version: 1,
|
|
81
|
+
provider: providerId,
|
|
82
|
+
clientId: client.clientId,
|
|
83
|
+
// Only WireCat's secret, which is public: a later release may ship another default app, and a refresh needs
|
|
84
|
+
// the secret of the app that signed in. An owner's own secret stays where the owner keeps it.
|
|
85
|
+
clientSecret: client.source === "constants" ? client.clientSecret : void 0,
|
|
86
|
+
clientSource: client.source,
|
|
87
|
+
accessToken: tokens.accessToken,
|
|
88
|
+
refreshToken: tokens.refreshToken,
|
|
89
|
+
expiresAt: tokens.expiresAt,
|
|
90
|
+
scopes: tokens.scopes,
|
|
91
|
+
tokenType: tokens.tokenType
|
|
92
|
+
})), "encode")
|
|
93
|
+
}), "standardCodec");
|
|
94
|
+
var googleStandard = standardCodec("google");
|
|
95
|
+
var keyringFailure = /* @__PURE__ */ __name((thrown, secret) => {
|
|
96
|
+
const failure = new CliError("configuration_error", "could not reach the saved sign-in; use an available keyring or file storage", { reason: "oauth.not-saved" });
|
|
97
|
+
const words = thrown instanceof Error ? thrown.message : String(thrown);
|
|
98
|
+
failure.cause = new Error(secret ? words.replaceAll(secret, "[secret]") : words);
|
|
99
|
+
return failure;
|
|
100
|
+
}, "keyringFailure");
|
|
101
|
+
var credentialStorage = /* @__PURE__ */ __name((options) => {
|
|
102
|
+
if (!options.credentials.keyring)
|
|
103
|
+
throw new CliError("configuration_error", "a sign-in store needs its keyring passed in, never a default");
|
|
104
|
+
const credentials = new Credentials(options.credentials);
|
|
105
|
+
const { account, codec } = options;
|
|
106
|
+
const moved = options.credentials.isolated === true || options.credentials.keyring === systemKeyring && isMovedRun({ appName: options.credentials.service, env: options.credentials.env ?? process.env });
|
|
107
|
+
const service = keyringService(options.credentials.service, options.credentials.configDir, options.credentials.isolated);
|
|
108
|
+
const raw = /* @__PURE__ */ __name((name) => {
|
|
109
|
+
try {
|
|
110
|
+
return credentials.read(name)?.secret;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (error instanceof CliError)
|
|
113
|
+
throw error;
|
|
114
|
+
throw keyringFailure(error);
|
|
115
|
+
}
|
|
116
|
+
}, "raw");
|
|
117
|
+
const fallsBack = options.credentials.storage !== "keyring";
|
|
118
|
+
const replaced = /* @__PURE__ */ __name((name) => {
|
|
119
|
+
try {
|
|
120
|
+
return raw(name);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (fallsBack && error instanceof CliError && error.details.reason === "keyring.unreachable")
|
|
123
|
+
return void 0;
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}, "replaced");
|
|
127
|
+
const save = /* @__PURE__ */ __name((value, writeOptions) => {
|
|
128
|
+
try {
|
|
129
|
+
credentials.write(account, value, writeOptions);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
throw keyringFailure(error, value);
|
|
132
|
+
}
|
|
133
|
+
}, "save");
|
|
134
|
+
const current = /* @__PURE__ */ __name(() => {
|
|
135
|
+
const own = raw(account);
|
|
136
|
+
if (own !== void 0)
|
|
137
|
+
return own;
|
|
138
|
+
for (const legacy of options.legacyAccounts ?? []) {
|
|
139
|
+
const found = raw(legacy);
|
|
140
|
+
if (found === void 0)
|
|
141
|
+
continue;
|
|
142
|
+
codec.decode(found);
|
|
143
|
+
if (!moved)
|
|
144
|
+
save(found);
|
|
145
|
+
return found;
|
|
146
|
+
}
|
|
147
|
+
return void 0;
|
|
148
|
+
}, "current");
|
|
149
|
+
return {
|
|
150
|
+
key: `${service}\0${account}`,
|
|
151
|
+
moved,
|
|
152
|
+
...codec.rotating ? { rotating: true } : {},
|
|
153
|
+
probe: /* @__PURE__ */ __name(() => {
|
|
154
|
+
replaced(account);
|
|
155
|
+
}, "probe"),
|
|
156
|
+
read: /* @__PURE__ */ __name(() => {
|
|
157
|
+
const value = current();
|
|
158
|
+
return value === void 0 ? void 0 : codec.decode(value);
|
|
159
|
+
}, "read"),
|
|
160
|
+
write: /* @__PURE__ */ __name((input, writeOptions) => save(codec.encode({ ...input, previous: replaced(account), ...writeOptions?.signIn ? { signIn: true } : {} }), writeOptions), "write"),
|
|
161
|
+
remove: /* @__PURE__ */ __name(() => {
|
|
162
|
+
try {
|
|
163
|
+
return credentials.remove(account);
|
|
164
|
+
} catch (error) {
|
|
165
|
+
throw keyringFailure(error);
|
|
166
|
+
}
|
|
167
|
+
}, "remove")
|
|
168
|
+
};
|
|
169
|
+
}, "credentialStorage");
|
|
170
|
+
|
|
171
|
+
// node_modules/.pnpm/@wirecat+cli-core@1.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_dd5172c52281f8f1e2dd1d4e9555d5c3/node_modules/@wirecat/cli-core/dist/oauth/authorize.js
|
|
172
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
173
|
+
import { createServer } from "node:http";
|
|
174
|
+
var DEFAULT_TIMEOUT_MS = 3e5;
|
|
175
|
+
var pkce = /* @__PURE__ */ __name(() => {
|
|
176
|
+
const codeVerifier = randomBytes(48).toString("base64url");
|
|
177
|
+
return { codeVerifier, codeChallenge: createHash("sha256").update(codeVerifier).digest("base64url") };
|
|
178
|
+
}, "pkce");
|
|
179
|
+
var queryOf = /* @__PURE__ */ __name((text2) => {
|
|
180
|
+
const trimmed = text2.trim();
|
|
181
|
+
const start = trimmed.indexOf("?");
|
|
182
|
+
return new URLSearchParams(start >= 0 ? trimmed.slice(start + 1).split("#")[0] : trimmed);
|
|
183
|
+
}, "queryOf");
|
|
184
|
+
var authorize = /* @__PURE__ */ __name(async (options) => {
|
|
185
|
+
const { provider } = options;
|
|
186
|
+
const cancelled = /* @__PURE__ */ __name(() => isCliError(options.signal?.reason) ? options.signal.reason : new CliError("cancelled", `${provider.name} sign-in was cancelled`), "cancelled");
|
|
187
|
+
if (options.signal?.aborted)
|
|
188
|
+
throw cancelled();
|
|
189
|
+
const { codeVerifier, codeChallenge } = pkce();
|
|
190
|
+
const paste = new AbortController();
|
|
191
|
+
let state = "";
|
|
192
|
+
let settled = false;
|
|
193
|
+
let accept = /* @__PURE__ */ __name(() => {
|
|
194
|
+
}, "accept");
|
|
195
|
+
let fail = /* @__PURE__ */ __name(() => {
|
|
196
|
+
}, "fail");
|
|
197
|
+
const code = new Promise((resolve, reject) => {
|
|
198
|
+
accept = /* @__PURE__ */ __name((value) => {
|
|
199
|
+
settled = true;
|
|
200
|
+
resolve(value);
|
|
201
|
+
}, "accept");
|
|
202
|
+
fail = /* @__PURE__ */ __name((error) => {
|
|
203
|
+
settled = true;
|
|
204
|
+
reject(error);
|
|
205
|
+
}, "fail");
|
|
206
|
+
});
|
|
207
|
+
void code.catch(() => {
|
|
208
|
+
});
|
|
209
|
+
const settle = /* @__PURE__ */ __name((query) => {
|
|
210
|
+
const value = query.get("code");
|
|
211
|
+
if (value)
|
|
212
|
+
accept(value);
|
|
213
|
+
else
|
|
214
|
+
fail(new CliError("authentication_error", `${provider.name} sign-in was declined`, { reason: "oauth.declined" }));
|
|
215
|
+
}, "settle");
|
|
216
|
+
const handler = /* @__PURE__ */ __name((request, response) => {
|
|
217
|
+
let url;
|
|
218
|
+
try {
|
|
219
|
+
url = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
220
|
+
} catch {
|
|
221
|
+
response.writeHead(400).end();
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (request.method !== "GET" || url.pathname !== "/callback") {
|
|
225
|
+
response.writeHead(404).end();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (settled || !state || url.searchParams.get("state") !== state) {
|
|
229
|
+
response.writeHead(400).end("This sign-in link does not belong to the waiting sign-in");
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (!url.searchParams.get("code") && !url.searchParams.get("error")) {
|
|
233
|
+
response.writeHead(400).end("Missing sign-in result");
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
response.end("Sign-in received; you can close this tab");
|
|
237
|
+
settle(url.searchParams);
|
|
238
|
+
}, "handler");
|
|
239
|
+
const server = createServer(handler);
|
|
240
|
+
const localhost = provider.redirect.kind === "loopback" && provider.redirect.host === "localhost";
|
|
241
|
+
const server6 = localhost ? createServer(handler) : void 0;
|
|
242
|
+
const onAbort = /* @__PURE__ */ __name(() => fail(cancelled()), "onAbort");
|
|
243
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
244
|
+
const timer = setTimeout(() => fail(new CliError("timeout", `${provider.name} sign-in timed out`, { reason: "oauth.timeout" })), options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
245
|
+
try {
|
|
246
|
+
await new Promise((resolve, reject) => {
|
|
247
|
+
server.once("error", reject);
|
|
248
|
+
server.listen(0, "127.0.0.1", resolve);
|
|
249
|
+
});
|
|
250
|
+
const address = server.address();
|
|
251
|
+
if (!address || typeof address === "string")
|
|
252
|
+
throw new CliError("configuration_error", "could not start the local sign-in listener");
|
|
253
|
+
if (server6) {
|
|
254
|
+
server6.on("error", () => {
|
|
255
|
+
});
|
|
256
|
+
await new Promise((resolve) => {
|
|
257
|
+
server6.once("error", () => resolve());
|
|
258
|
+
server6.listen(address.port, "::1", () => resolve());
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
const random = randomBytes(32).toString("base64url");
|
|
262
|
+
const relay = provider.redirect.kind === "relay";
|
|
263
|
+
state = relay ? `${address.port}.${random}` : random;
|
|
264
|
+
const redirectUri = provider.redirect.kind === "relay" ? provider.redirect.url : `http://${localhost ? "localhost" : "127.0.0.1"}:${address.port}/callback`;
|
|
265
|
+
const url = new URL(provider.authorizeUrl);
|
|
266
|
+
for (const [key, value] of Object.entries({
|
|
267
|
+
...provider.authorizeParams,
|
|
268
|
+
response_type: "code",
|
|
269
|
+
client_id: provider.client.clientId,
|
|
270
|
+
redirect_uri: redirectUri,
|
|
271
|
+
...options.scopes.length ? { scope: options.scopes.join(" ") } : {},
|
|
272
|
+
state,
|
|
273
|
+
code_challenge: codeChallenge,
|
|
274
|
+
code_challenge_method: "S256"
|
|
275
|
+
}))
|
|
276
|
+
url.searchParams.set(key, value);
|
|
277
|
+
options.showUrl?.(url.toString());
|
|
278
|
+
options.readPaste?.(paste.signal).then((text2) => {
|
|
279
|
+
if (settled)
|
|
280
|
+
return;
|
|
281
|
+
const query = queryOf(text2);
|
|
282
|
+
if (query.get("state") !== state || !query.get("code") && !query.get("error"))
|
|
283
|
+
fail(new CliError("authentication_error", "the pasted sign-in result does not match this sign-in", {
|
|
284
|
+
reason: "oauth.mismatch"
|
|
285
|
+
}));
|
|
286
|
+
else
|
|
287
|
+
settle(query);
|
|
288
|
+
}).catch(() => {
|
|
289
|
+
});
|
|
290
|
+
void Promise.resolve().then(() => options.openBrowser(url.toString())).catch(() => {
|
|
291
|
+
if (!options.readPaste && !options.showUrl)
|
|
292
|
+
fail(new CliError("configuration_error", "could not open the browser, and no sign-in link can be shown"));
|
|
293
|
+
});
|
|
294
|
+
return { code: await code, redirectUri, codeVerifier };
|
|
295
|
+
} finally {
|
|
296
|
+
clearTimeout(timer);
|
|
297
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
298
|
+
paste.abort();
|
|
299
|
+
for (const each of server6 ? [server, server6] : [server]) {
|
|
300
|
+
each.closeAllConnections();
|
|
301
|
+
if (each.listening)
|
|
302
|
+
await new Promise((resolve) => each.close(() => resolve()));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}, "authorize");
|
|
306
|
+
|
|
307
|
+
// node_modules/.pnpm/@wirecat+cli-core@1.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_dd5172c52281f8f1e2dd1d4e9555d5c3/node_modules/@wirecat/cli-core/dist/oauth/requests.js
|
|
308
|
+
var REQUEST_LIMIT_MS = 3e4;
|
|
309
|
+
var TOKEN_LOG_EVENT = "oauth.token";
|
|
310
|
+
var object = /* @__PURE__ */ __name((value) => {
|
|
311
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
312
|
+
throw new Error("not an object");
|
|
313
|
+
return value;
|
|
314
|
+
}, "object");
|
|
315
|
+
var requestSignal = /* @__PURE__ */ __name((deadline, signal) => signal ? AbortSignal.any([signal, deadline]) : deadline, "requestSignal");
|
|
316
|
+
var cancelledBy = /* @__PURE__ */ __name((signal) => {
|
|
317
|
+
if (!signal?.aborted)
|
|
318
|
+
return;
|
|
319
|
+
throw isCliError(signal.reason) ? signal.reason : new CliError("cancelled", "sign-in was cancelled");
|
|
320
|
+
}, "cancelledBy");
|
|
321
|
+
var TRANSIENT = /* @__PURE__ */ new Set([
|
|
322
|
+
"EAI_AGAIN",
|
|
323
|
+
"ENOTFOUND",
|
|
324
|
+
"ECONNRESET",
|
|
325
|
+
"ECONNREFUSED",
|
|
326
|
+
"ETIMEDOUT",
|
|
327
|
+
"EPIPE",
|
|
328
|
+
"UND_ERR_SOCKET"
|
|
329
|
+
]);
|
|
330
|
+
var ATTEMPTS = 3;
|
|
331
|
+
var transientNetworkError = /* @__PURE__ */ __name((error) => {
|
|
332
|
+
if (isCliError(error))
|
|
333
|
+
return error.code === "network_error";
|
|
334
|
+
for (let at = error, depth = 0; at instanceof Error && depth < 4; at = at.cause, depth++) {
|
|
335
|
+
const code = at.code;
|
|
336
|
+
if (typeof code === "string" && TRANSIENT.has(code))
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
return false;
|
|
340
|
+
}, "transientNetworkError");
|
|
341
|
+
var post = /* @__PURE__ */ __name(async (url, body, context, deadline) => {
|
|
342
|
+
const signal = requestSignal(deadline, context.signal);
|
|
343
|
+
for (let attempt = 1; ; attempt++) {
|
|
344
|
+
cancelledBy(context.signal);
|
|
345
|
+
try {
|
|
346
|
+
return await context.fetch(url, {
|
|
347
|
+
method: "POST",
|
|
348
|
+
headers: { "content-type": "application/x-www-form-urlencoded", accept: "application/json" },
|
|
349
|
+
body,
|
|
350
|
+
signal,
|
|
351
|
+
redirect: "error"
|
|
352
|
+
});
|
|
353
|
+
} catch (error) {
|
|
354
|
+
cancelledBy(context.signal);
|
|
355
|
+
if (attempt >= ATTEMPTS || signal.aborted || !transientNetworkError(error))
|
|
356
|
+
return void 0;
|
|
357
|
+
const waited = await realSleep(500 * attempt, signal).then(() => true, () => false);
|
|
358
|
+
cancelledBy(context.signal);
|
|
359
|
+
if (!waited)
|
|
360
|
+
return void 0;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}, "post");
|
|
364
|
+
var clientFields = /* @__PURE__ */ __name(({ client }) => ({
|
|
365
|
+
client_id: client.clientId,
|
|
366
|
+
...client.clientSecret ? { client_secret: client.clientSecret } : {}
|
|
367
|
+
}), "clientFields");
|
|
368
|
+
var requestTokens = /* @__PURE__ */ __name((provider, params, context) => withTimeLimit(REQUEST_LIMIT_MS, (deadline) => exchangeTokens(provider, params, context, deadline)), "requestTokens");
|
|
369
|
+
var exchangeTokens = /* @__PURE__ */ __name(async (provider, params, context, deadline) => {
|
|
370
|
+
const operation = params.grant_type ?? "unknown";
|
|
371
|
+
const record = /* @__PURE__ */ __name((level, fields) => context.log?.[level]({ event: TOKEN_LOG_EVENT, provider: provider.id, operation, pid: process.pid, ...fields }), "record");
|
|
372
|
+
const again = `run ${context.signInCommand} again`;
|
|
373
|
+
const response = await post(provider.tokenUrl, new URLSearchParams({ ...params, ...clientFields(context) }), context, deadline);
|
|
374
|
+
if (!response) {
|
|
375
|
+
record("warn", { outcome: "no_response" });
|
|
376
|
+
throw new CliError("outcome_unknown", `${provider.name} token request did not finish; ${again} if it keeps failing`, {
|
|
377
|
+
reason: "oauth.no-response"
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
if (!response.ok) {
|
|
381
|
+
record("warn", { outcome: "rejected", status: response.status });
|
|
382
|
+
if (response.status === 429 || response.status >= 500)
|
|
383
|
+
throw new CliError("provider_unavailable", `${provider.name} token request failed (HTTP ${response.status})`, {
|
|
384
|
+
status: response.status,
|
|
385
|
+
retryable: true,
|
|
386
|
+
reason: "oauth.unavailable"
|
|
387
|
+
});
|
|
388
|
+
throw new CliError("authentication_error", `${provider.name} sign-in was refused (HTTP ${response.status}); ${again}`, {
|
|
389
|
+
status: response.status,
|
|
390
|
+
reason: "oauth.expired"
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
let body;
|
|
394
|
+
try {
|
|
395
|
+
body = object(await response.json());
|
|
396
|
+
} catch {
|
|
397
|
+
record("error", { outcome: "unreadable_response", status: response.status });
|
|
398
|
+
throw new CliError("invalid_response", `${provider.name} returned an unreadable token response; ${again}`, {
|
|
399
|
+
reason: "oauth.invalid-response"
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
const previous = context.previous;
|
|
403
|
+
const refreshToken = typeof body.refresh_token === "string" && body.refresh_token ? body.refresh_token : previous?.refreshToken;
|
|
404
|
+
const expiresIn = body.expires_in;
|
|
405
|
+
if (typeof body.access_token !== "string" || !body.access_token || expiresIn !== void 0 && (typeof expiresIn !== "number" || !Number.isFinite(expiresIn) || expiresIn <= 0) || body.scope !== void 0 && typeof body.scope !== "string" || body.token_type !== void 0 && typeof body.token_type !== "string") {
|
|
406
|
+
record("error", { outcome: "invalid_response", status: response.status });
|
|
407
|
+
throw new CliError("invalid_response", `${provider.name} returned an invalid token response; ${again}`, {
|
|
408
|
+
reason: "oauth.invalid-response"
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
if (!refreshToken) {
|
|
412
|
+
record("error", { outcome: "no_refresh_token", status: response.status });
|
|
413
|
+
throw new CliError("authentication_error", `${provider.name} returned no offline refresh token; ${again}`, {
|
|
414
|
+
reason: "oauth.failed"
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
const scopes = typeof body.scope === "string" ? body.scope.split(/\s+/).filter(Boolean) : previous?.scopes ?? [];
|
|
418
|
+
const tokenType = typeof body.token_type === "string" ? body.token_type : previous?.tokenType;
|
|
419
|
+
record("info", {
|
|
420
|
+
outcome: "received",
|
|
421
|
+
status: response.status,
|
|
422
|
+
...previous ? { rotated: refreshToken !== previous.refreshToken } : {}
|
|
423
|
+
});
|
|
424
|
+
return {
|
|
425
|
+
accessToken: body.access_token,
|
|
426
|
+
refreshToken,
|
|
427
|
+
...typeof expiresIn === "number" ? { expiresAt: context.now() + expiresIn * 1e3 } : {},
|
|
428
|
+
scopes,
|
|
429
|
+
...tokenType ? { tokenType } : {}
|
|
430
|
+
};
|
|
431
|
+
}, "exchangeTokens");
|
|
432
|
+
var alreadyRevoked = /* @__PURE__ */ __name(async (response) => {
|
|
433
|
+
if (response.status !== 400)
|
|
434
|
+
return false;
|
|
435
|
+
try {
|
|
436
|
+
return object(JSON.parse(await response.text())).error === "invalid_token";
|
|
437
|
+
} catch {
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
}, "alreadyRevoked");
|
|
441
|
+
var revokeToken = /* @__PURE__ */ __name(async (provider, tokens, context) => {
|
|
442
|
+
if (provider.revoke)
|
|
443
|
+
return provider.revoke(tokens, context);
|
|
444
|
+
if (!provider.revokeUrl)
|
|
445
|
+
throw new CliError("validation_error", `${provider.name} declares no way to revoke a sign-in`);
|
|
446
|
+
const { revokeUrl } = provider;
|
|
447
|
+
const form = new URLSearchParams({ token: tokens.refreshToken, ...clientFields(context) });
|
|
448
|
+
const { response, gone } = await withTimeLimit(REQUEST_LIMIT_MS, async (deadline) => {
|
|
449
|
+
const response2 = await post(revokeUrl, form, context, deadline);
|
|
450
|
+
return { response: response2, gone: response2 ? await alreadyRevoked(response2) : false };
|
|
451
|
+
});
|
|
452
|
+
const done = response?.ok || gone;
|
|
453
|
+
context.log?.[done ? "info" : "warn"]({
|
|
454
|
+
event: TOKEN_LOG_EVENT,
|
|
455
|
+
provider: provider.id,
|
|
456
|
+
operation: "revoke",
|
|
457
|
+
pid: process.pid,
|
|
458
|
+
outcome: response?.ok ? "revoked" : gone ? "already_revoked" : response ? "rejected" : "no_response",
|
|
459
|
+
...response ? { status: response.status } : {}
|
|
460
|
+
});
|
|
461
|
+
if (!done)
|
|
462
|
+
throw new CliError("outcome_unknown", `${provider.name} did not confirm the revoke`, {
|
|
463
|
+
reason: "oauth.revoke-failed",
|
|
464
|
+
...response ? { status: response.status } : {}
|
|
465
|
+
});
|
|
466
|
+
}, "revokeToken");
|
|
467
|
+
|
|
468
|
+
// node_modules/.pnpm/@wirecat+cli-core@1.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_dd5172c52281f8f1e2dd1d4e9555d5c3/node_modules/@wirecat/cli-core/dist/oauth/keeper.js
|
|
469
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
470
|
+
import { join } from "node:path";
|
|
471
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
472
|
+
var inFlight = /* @__PURE__ */ new Map();
|
|
473
|
+
var refreshedInMemory = /* @__PURE__ */ new Map();
|
|
474
|
+
var tokenKeeper = /* @__PURE__ */ __name((options) => {
|
|
475
|
+
const { provider, storage, signal, log } = options;
|
|
476
|
+
const now = options.now ?? Date.now;
|
|
477
|
+
const fresh = /* @__PURE__ */ __name((tokens2) => Boolean(tokens2.accessToken) && tokens2.expiresAt !== void 0 && tokens2.expiresAt > now() + (options.freshForMs ?? 6e4), "fresh");
|
|
478
|
+
const lockPath = join(options.lockDir, `oauth-${createHash2("sha256").update(storage.key).digest("hex").slice(0, 16)}.lock`);
|
|
479
|
+
const clientOf = /* @__PURE__ */ __name((stored) => {
|
|
480
|
+
const saved = stored?.client;
|
|
481
|
+
if (!saved || saved.clientSecret || saved.clientId !== provider.client.clientId)
|
|
482
|
+
return saved ?? provider.client;
|
|
483
|
+
return provider.client;
|
|
484
|
+
}, "clientOf");
|
|
485
|
+
const context = /* @__PURE__ */ __name((client, previous) => ({
|
|
486
|
+
fetch: options.fetch,
|
|
487
|
+
client,
|
|
488
|
+
now,
|
|
489
|
+
signInCommand: options.signInCommand,
|
|
490
|
+
...signal ? { signal } : {},
|
|
491
|
+
...log ? { log } : {},
|
|
492
|
+
...previous ? { previous } : {}
|
|
493
|
+
}), "context");
|
|
494
|
+
const exchange = /* @__PURE__ */ __name((params, ctx) => provider.exchange ? provider.exchange(params, ctx) : requestTokens(provider, params, ctx), "exchange");
|
|
495
|
+
const notSignedIn = /* @__PURE__ */ __name(() => new CliError("authentication_error", `not signed in to ${provider.name}; run ${options.signInCommand}`, {
|
|
496
|
+
reason: "session.missing"
|
|
497
|
+
}), "notSignedIn");
|
|
498
|
+
const busy = /* @__PURE__ */ __name((error) => isCliError(error) && error.details.reason === "file.locked", "busy");
|
|
499
|
+
const acquire = /* @__PURE__ */ __name(async () => {
|
|
500
|
+
const started = performance.now();
|
|
501
|
+
let waiting = false;
|
|
502
|
+
for (; ; ) {
|
|
503
|
+
try {
|
|
504
|
+
return await acquireLock(lockPath, signal ? { signal } : {});
|
|
505
|
+
} catch (error) {
|
|
506
|
+
if (!busy(error))
|
|
507
|
+
throw error;
|
|
508
|
+
if (!waiting) {
|
|
509
|
+
waiting = true;
|
|
510
|
+
log?.info({
|
|
511
|
+
event: TOKEN_LOG_EVENT,
|
|
512
|
+
provider: provider.id,
|
|
513
|
+
operation: "lock",
|
|
514
|
+
outcome: "waiting",
|
|
515
|
+
pid: process.pid
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
if (performance.now() - started > (options.lockWaitMs ?? 45e3))
|
|
519
|
+
throw new CliError("provider_unavailable", `another process holds this ${provider.name} sign-in; retry`, {
|
|
520
|
+
reason: "oauth.locked",
|
|
521
|
+
retryable: true
|
|
522
|
+
});
|
|
523
|
+
await delay(options.lockRetryMs ?? 50, void 0, signal ? { signal } : {}).catch(() => {
|
|
524
|
+
throw new CliError("cancelled", `${provider.name} sign-in was cancelled`);
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}, "acquire");
|
|
529
|
+
const locked = /* @__PURE__ */ __name(async (work) => {
|
|
530
|
+
const lock = await acquire();
|
|
531
|
+
try {
|
|
532
|
+
return await work();
|
|
533
|
+
} finally {
|
|
534
|
+
await lock.release().catch(() => {
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
}, "locked");
|
|
538
|
+
const shared = /* @__PURE__ */ __name((work) => {
|
|
539
|
+
const running = inFlight.get(lockPath);
|
|
540
|
+
if (running)
|
|
541
|
+
return running;
|
|
542
|
+
const started = locked(work).finally(() => inFlight.delete(lockPath));
|
|
543
|
+
inFlight.set(lockPath, started);
|
|
544
|
+
return started;
|
|
545
|
+
}, "shared");
|
|
546
|
+
const remembered = /* @__PURE__ */ __name((saved) => {
|
|
547
|
+
const kept = refreshedInMemory.get(lockPath);
|
|
548
|
+
return kept && fresh(kept) && kept.refreshToken === saved.refreshToken ? kept : void 0;
|
|
549
|
+
}, "remembered");
|
|
550
|
+
const forget = /* @__PURE__ */ __name(() => refreshedInMemory.delete(lockPath), "forget");
|
|
551
|
+
let answered;
|
|
552
|
+
const answer = /* @__PURE__ */ __name((given) => {
|
|
553
|
+
answered = given;
|
|
554
|
+
return given;
|
|
555
|
+
}, "answer");
|
|
556
|
+
const tokens = /* @__PURE__ */ __name(async ({ refresh = false } = {}) => {
|
|
557
|
+
const seen = storage.read();
|
|
558
|
+
if (!seen)
|
|
559
|
+
throw notSignedIn();
|
|
560
|
+
if (!refresh) {
|
|
561
|
+
const kept = remembered(seen.tokens);
|
|
562
|
+
if (kept)
|
|
563
|
+
return answer(kept);
|
|
564
|
+
if (fresh(seen.tokens))
|
|
565
|
+
return answer(seen.tokens);
|
|
566
|
+
}
|
|
567
|
+
const refused = answered ?? remembered(seen.tokens) ?? seen.tokens;
|
|
568
|
+
return answer(await shared(async () => {
|
|
569
|
+
const current = storage.read();
|
|
570
|
+
if (!current)
|
|
571
|
+
throw notSignedIn();
|
|
572
|
+
const latest = remembered(current.tokens) ?? current.tokens;
|
|
573
|
+
if (refresh) {
|
|
574
|
+
if (latest.accessToken !== refused.accessToken && fresh(latest))
|
|
575
|
+
return latest;
|
|
576
|
+
} else {
|
|
577
|
+
if (latest !== current.tokens)
|
|
578
|
+
return latest;
|
|
579
|
+
if (fresh(current.tokens) || current.tokens.refreshToken !== seen.tokens.refreshToken)
|
|
580
|
+
return current.tokens;
|
|
581
|
+
}
|
|
582
|
+
if (storage.moved && storage.rotating)
|
|
583
|
+
throw new CliError("authentication_error", `the sign-in to ${provider.name} needs a refresh, which a run with moved folders never makes: the provider rotates its refresh token, and the owner's own sign-in would keep a dead one; run this in the normal run, or sign in again there`, { reason: "oauth.moved-rotating" });
|
|
584
|
+
const client = clientOf(current);
|
|
585
|
+
const refreshed = await exchange({ grant_type: "refresh_token", refresh_token: current.tokens.refreshToken }, context(client, current.tokens));
|
|
586
|
+
if (storage.moved && refreshed.refreshToken === current.tokens.refreshToken)
|
|
587
|
+
refreshedInMemory.set(lockPath, refreshed);
|
|
588
|
+
else
|
|
589
|
+
storage.write({ tokens: refreshed, client });
|
|
590
|
+
return refreshed;
|
|
591
|
+
}));
|
|
592
|
+
}, "tokens");
|
|
593
|
+
return {
|
|
594
|
+
tokens,
|
|
595
|
+
accessToken: /* @__PURE__ */ __name(async (tokensOptions) => {
|
|
596
|
+
const current = await tokens(tokensOptions);
|
|
597
|
+
if (!current.accessToken)
|
|
598
|
+
throw notSignedIn();
|
|
599
|
+
return current.accessToken;
|
|
600
|
+
}, "accessToken"),
|
|
601
|
+
signIn: /* @__PURE__ */ __name(async ({ accept, ...authorizeOptions }) => {
|
|
602
|
+
storage.probe();
|
|
603
|
+
const authorization = await authorize({ ...authorizeOptions, provider, ...signal ? { signal } : {} });
|
|
604
|
+
const client = provider.client;
|
|
605
|
+
const received = await exchange({
|
|
606
|
+
grant_type: "authorization_code",
|
|
607
|
+
code: authorization.code,
|
|
608
|
+
redirect_uri: authorization.redirectUri,
|
|
609
|
+
code_verifier: authorization.codeVerifier
|
|
610
|
+
}, context(client));
|
|
611
|
+
const extra = await accept?.(received) ?? void 0;
|
|
612
|
+
await locked(async () => {
|
|
613
|
+
forget();
|
|
614
|
+
storage.write({ tokens: received, client, ...extra ? { extra } : {} }, { signIn: true });
|
|
615
|
+
});
|
|
616
|
+
return { scopes: received.scopes };
|
|
617
|
+
}, "signIn"),
|
|
618
|
+
save: /* @__PURE__ */ __name((saved, extra) => locked(async () => {
|
|
619
|
+
forget();
|
|
620
|
+
storage.write({ tokens: saved, client: clientOf(storage.read()), ...extra ? { extra } : {} }, { signIn: true });
|
|
621
|
+
}), "save"),
|
|
622
|
+
signOut: /* @__PURE__ */ __name(({ revoke = false } = {}) => locked(async () => {
|
|
623
|
+
forget();
|
|
624
|
+
const current = storage.read();
|
|
625
|
+
let revoked = false;
|
|
626
|
+
if (revoke && current) {
|
|
627
|
+
await revokeToken(provider, current.tokens, context(clientOf(current)));
|
|
628
|
+
revoked = true;
|
|
629
|
+
}
|
|
630
|
+
return { revoked, removed: storage.remove() };
|
|
631
|
+
}), "signOut")
|
|
632
|
+
};
|
|
633
|
+
}, "tokenKeeper");
|
|
634
|
+
|
|
635
|
+
export {
|
|
636
|
+
tokenKeeper,
|
|
637
|
+
oauthAccount,
|
|
638
|
+
standardCodec,
|
|
639
|
+
credentialStorage
|
|
640
|
+
};
|