@wirecat/drive-cli 0.59.0 → 0.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -5
- package/dist/bin/drive.js +2 -2
- package/dist/bin/drive.js.map +1 -1
- package/dist/bundle/{all-profiles-CVISDGMF.js → all-profiles-H4L3Z5UM.js} +14 -14
- package/dist/bundle/{anthropic-WLNQC23G.js → anthropic-PPGFISVP.js} +9 -9
- package/dist/bundle/{app-server-P2VOONXF.js → app-server-YXVK2FUZ.js} +52 -52
- package/dist/bundle/{bun-CDFBNTKV.js → bun-DKZAL6ML.js} +2 -2
- package/dist/bundle/{bun-sqlite-MNZICITP.js → bun-sqlite-MTZY36QK.js} +8 -8
- package/dist/bundle/{chunk-TFH5X46A.js → chunk-2RJA4BQB.js} +19 -19
- package/dist/bundle/{chunk-VVCZS42A.js → chunk-3252WXOL.js} +1 -1
- package/dist/bundle/{chunk-H2BKXPBL.js → chunk-36CWGEVX.js} +2 -2
- package/dist/bundle/{chunk-HWLLVLAB.js → chunk-3I2D5TK2.js} +14 -11
- package/dist/bundle/{chunk-PAEVBAM3.js → chunk-3SJQNS72.js} +5 -5
- package/dist/bundle/{chunk-GI5JBGXH.js → chunk-3UPIJ7DW.js} +615 -374
- package/dist/bundle/{chunk-EORMZCVF.js → chunk-3WZH3WV3.js} +3 -3
- package/dist/bundle/{chunk-ZSMCJKGP.js → chunk-5W56YMQS.js} +28 -27
- package/dist/bundle/{chunk-LJ7E4HLQ.js → chunk-5W7D5H2R.js} +1 -1
- package/dist/bundle/{chunk-6C6255U6.js → chunk-67HS46KM.js} +12 -12
- package/dist/bundle/{chunk-AD62XJKO.js → chunk-6DN4VPA7.js} +25 -25
- package/dist/bundle/{chunk-HIP43OGZ.js → chunk-6IBM4Z3V.js} +1 -1
- package/dist/bundle/{chunk-QTM7USFA.js → chunk-6SUGANRJ.js} +6 -6
- package/dist/bundle/{chunk-II7LST64.js → chunk-6Y2FWJZ4.js} +4 -3
- package/dist/bundle/{chunk-XCOCPXCM.js → chunk-73WSULMI.js} +2 -2
- package/dist/bundle/{chunk-V42KAPU3.js → chunk-AM4RIWOZ.js} +4 -4
- package/dist/bundle/{chunk-DI5Z4SH5.js → chunk-AWN22PJK.js} +3 -3
- package/dist/bundle/{chunk-HMZAMHKN.js → chunk-BCWUDTYQ.js} +2 -2
- package/dist/bundle/{chunk-EHEZSV6I.js → chunk-BF6TQMNB.js} +8 -8
- package/dist/bundle/chunk-BQMIDYBA.js +415 -0
- package/dist/bundle/{chunk-FVQCM7IQ.js → chunk-BXR7BKM3.js} +5 -5
- package/dist/bundle/{chunk-OKXSTWKW.js → chunk-CACYL36O.js} +8 -8
- package/dist/bundle/{chunk-CBM2XAEZ.js → chunk-DCBFNBEB.js} +113 -51
- package/dist/bundle/{chunk-GT5KTGCN.js → chunk-DEPMQHXQ.js} +4 -4
- package/dist/bundle/{chunk-3KJTJDDT.js → chunk-DXPOVLQC.js} +46 -28
- package/dist/bundle/{chunk-P7WPYKSB.js → chunk-E5EXJ2XS.js} +4 -4
- package/dist/bundle/{chunk-IGF6EXBR.js → chunk-E6J5YH2N.js} +34 -34
- package/dist/bundle/{chunk-IIP43FQJ.js → chunk-ECEYAQGN.js} +2 -2
- package/dist/bundle/{chunk-OMMEQJOB.js → chunk-EPCJUL6M.js} +3 -3
- package/dist/bundle/{chunk-JSDVK3JA.js → chunk-FE5JJXKA.js} +2 -2
- package/dist/bundle/{chunk-FICVPYE4.js → chunk-HFM653T3.js} +49 -49
- package/dist/bundle/{chunk-KPRGTTJH.js → chunk-HGOYQUT7.js} +1 -1
- package/dist/bundle/{chunk-3VSUT6BD.js → chunk-I26VL4W7.js} +2 -2
- package/dist/bundle/{chunk-V36RIXFA.js → chunk-J4HQVHMN.js} +6 -5
- package/dist/bundle/{chunk-P3ZTW2ZM.js → chunk-J5UDQD5S.js} +5 -5
- package/dist/bundle/{chunk-3KNZADHJ.js → chunk-JVBLXSAA.js} +437 -193
- package/dist/bundle/{chunk-TJXPJ3A5.js → chunk-K7LS3NGM.js} +137 -62
- package/dist/bundle/{chunk-2AXA5SKP.js → chunk-KV4267S4.js} +1 -1
- package/dist/bundle/{chunk-YU3PTU3D.js → chunk-LARQTWIL.js} +1 -1
- package/dist/bundle/{chunk-B5GBJ35N.js → chunk-N2RLJTIW.js} +4 -4
- package/dist/bundle/{chunk-K4LXGZTE.js → chunk-NIX2MWHZ.js} +242 -344
- package/dist/bundle/{chunk-L5SE2XZP.js → chunk-NZ2EIZLX.js} +14 -10
- package/dist/bundle/{chunk-F3FOL42A.js → chunk-O5CUFS7T.js} +2 -2
- package/dist/bundle/{chunk-UQPKAY6I.js → chunk-OFFA54TW.js} +2 -2
- package/dist/bundle/{chunk-W62CON5K.js → chunk-OGNOQDWB.js} +4 -4
- package/dist/bundle/{chunk-MUUHUHWC.js → chunk-OLPJRD4S.js} +1 -22
- package/dist/bundle/{chunk-YADXWQHV.js → chunk-PJTX2MOI.js} +26 -26
- package/dist/bundle/{chunk-M6I2SQN7.js → chunk-PY7LKNOS.js} +2 -2
- package/dist/bundle/{chunk-GJ4ZCIOP.js → chunk-Q4XVBKX4.js} +3 -3
- package/dist/bundle/{chunk-A6SLYOP2.js → chunk-QR5VQXQ5.js} +69 -36
- package/dist/bundle/{chunk-OZH4ALTI.js → chunk-QSGT4ZH4.js} +1 -1
- package/dist/bundle/{chunk-UWVNRPT7.js → chunk-RFRCOAWS.js} +22 -22
- package/dist/bundle/{chunk-A6EG7ZDS.js → chunk-S4YK6TTG.js} +13 -13
- package/dist/bundle/{chunk-LPHMAQJQ.js → chunk-TKGAYKXW.js} +16 -16
- package/dist/bundle/{chunk-KFZUODXB.js → chunk-UKOYQC5O.js} +39 -22
- package/dist/bundle/{chunk-MEAPA4EZ.js → chunk-UO2IUDVK.js} +2 -2
- package/dist/bundle/{chunk-HIOJRPCT.js → chunk-VPDAH7PJ.js} +1 -1
- package/dist/bundle/{chunk-3U22QTU6.js → chunk-VYXVPYA3.js} +24 -6
- package/dist/bundle/{chunk-VT6GZAF4.js → chunk-W767AUNR.js} +4 -4
- package/dist/bundle/{chunk-5C7K6XIT.js → chunk-WIU733D2.js} +1 -1
- package/dist/bundle/{chunk-IADOBOKB.js → chunk-WUP2MJDN.js} +2 -2
- package/dist/bundle/{chunk-EBLA7GXY.js → chunk-WZ5XK74U.js} +2 -1
- package/dist/bundle/{chunk-IBZ3IBO4.js → chunk-X2CXW4HM.js} +7 -7
- package/dist/bundle/{chunk-JW2CVCUH.js → chunk-XGMDWIUP.js} +4 -4
- package/dist/bundle/{chunk-BSGOM3BD.js → chunk-XGNC5OJG.js} +1 -1
- package/dist/bundle/{chunk-TI55J3BA.js → chunk-XLFJLZJL.js} +4 -4
- package/dist/bundle/{chunk-7QTVIZII.js → chunk-XYCCGGKN.js} +792 -327
- package/dist/bundle/{chunk-6CQO2FIN.js → chunk-XZBR2O63.js} +400 -291
- package/dist/bundle/{chunk-EVETU3TF.js → chunk-YMBFZA3H.js} +8 -8
- package/dist/bundle/{chunk-ZYCLPJ7U.js → chunk-YPF6OS37.js} +1 -1
- package/dist/bundle/{chunk-36B7AIGP.js → chunk-YWIU4HOT.js} +1 -1
- package/dist/bundle/{chunk-MKCNUI72.js → chunk-ZHYRHERD.js} +2 -2
- package/dist/bundle/{chunk-YV4ABH6J.js → chunk-ZMNYK3FC.js} +5 -5
- package/dist/bundle/command-contract-T3EO5AYD.js +39 -0
- package/dist/bundle/{decode-XTOMXMGN.js → decode-62A3HGPW.js} +8 -8
- package/dist/bundle/{dispatch-T6TW2JJB.js → dispatch-IE7PBEQC.js} +9 -9
- package/dist/bundle/drive.js +12 -12
- package/dist/bundle/{echarts-RKKIOYVV.js → echarts-BGBPRGR5.js} +2 -2
- package/dist/bundle/{embed-STHKKA6G.js → embed-J3IBVV2V.js} +9 -9
- package/dist/bundle/{embedder-3XZEWHRO.js → embedder-QFPMDRT2.js} +12 -12
- package/dist/bundle/entry-YQSYER66.js +22 -0
- package/dist/bundle/{failure-DNQYXP2T.js → failure-BKOGBMIC.js} +4 -4
- package/dist/bundle/first-run-ZIFPVZAI.js +30 -0
- package/dist/bundle/first-screen-L5U26EY7.js +37 -0
- package/dist/bundle/{google-BYNSAIQI.js → google-RXM2XEPD.js} +13 -13
- package/dist/bundle/{google-api-4VTZH7OP.js → google-api-NC65BZO4.js} +83 -64
- package/dist/bundle/grants-SEWUYYH3.js +105 -0
- package/dist/bundle/{identity-ARDPFYV5.js → identity-PI6F2GWA.js} +6 -6
- package/dist/bundle/{instructions-N3OH5X2Y.js → instructions-6LPDSKAD.js} +1 -1
- package/dist/bundle/{login-4VQEC7VI.js → login-HTY7GT2S.js} +66 -68
- package/dist/bundle/{mcp-WBHKX5E3.js → mcp-PPVOM4SE.js} +2 -2
- package/dist/bundle/{node-YU5JBNAA.js → node-IB246NCQ.js} +2 -2
- package/dist/bundle/{node-sqlite-3C6PSBIW.js → node-sqlite-G2Y5SFJM.js} +9 -9
- package/dist/bundle/oauth-MWBKBI4T.js +22 -0
- package/dist/bundle/{open-M2V2VYXO.js → open-WD4GFSJD.js} +8 -8
- package/dist/bundle/{openai-ST2IWNUX.js → openai-QVM4PMY7.js} +17 -17
- package/dist/bundle/{process-PYNNBBTV.js → process-SWPJGPQC.js} +1 -1
- package/dist/bundle/{program-Q4VWV2MR.js → program-WHYFAMXR.js} +142 -106
- package/dist/bundle/prompt-OVYCGZB7.js +17 -0
- package/dist/bundle/{reasons-LOQ5J73F.js → reasons-Q34DQWB6.js} +5 -5
- package/dist/bundle/{recognize-FBLMWXNE.js → recognize-DM3YWHSE.js} +7 -7
- package/dist/bundle/{remote-XC3OXE4T.js → remote-KXVWRK7J.js} +10 -10
- package/dist/bundle/{rerank-2XMKKF4S.js → rerank-TINXM3MY.js} +10 -10
- package/dist/bundle/{serve-Q2BQHNZB.js → serve-IY2WL656.js} +12 -12
- package/dist/bundle/server-EMWVVT2C.js +70 -0
- package/dist/bundle/{server-42HPV3AH.js → server-VPY3OWPC.js} +44 -44
- package/dist/bundle/{services-WU22S2MU.js → services-PXNBOCOC.js} +34 -32
- package/dist/bundle/{sqlite-runtime-CSO6K6B2.js → sqlite-runtime-5ZK2CV7Y.js} +9 -9
- package/dist/bundle/{start-TZWKM4AH.js → start-LDVCN3DK.js} +7 -7
- package/dist/bundle/{state-FLUT7U7R.js → state-3MKTT3VS.js} +9 -9
- package/dist/bundle/{store-TG6622NG.js → store-4VQOT5IJ.js} +18 -18
- package/dist/bundle/{store-HDWMJ44E.js → store-7M4MSUJV.js} +28 -22
- package/dist/bundle/store-maintenance-command-NRATYBWD.js +60 -0
- package/dist/bundle/tokens-XUKLM3SL.js +103 -0
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +15 -6
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/context.d.ts +4 -2
- package/dist/commands/context.d.ts.map +1 -1
- package/dist/commands/context.js.map +1 -1
- package/dist/commands/session.d.ts.map +1 -1
- package/dist/commands/session.js +15 -4
- package/dist/commands/session.js.map +1 -1
- package/dist/config.d.ts +23 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +33 -20
- package/dist/config.js.map +1 -1
- package/dist/download.d.ts +3 -2
- package/dist/download.d.ts.map +1 -1
- package/dist/download.js +21 -9
- package/dist/download.js.map +1 -1
- package/dist/errors.js +4 -4
- package/dist/errors.js.map +1 -1
- package/dist/google-api.d.ts +3 -1
- package/dist/google-api.d.ts.map +1 -1
- package/dist/google-api.js +27 -7
- package/dist/google-api.js.map +1 -1
- package/dist/login.d.ts.map +1 -1
- package/dist/login.js +4 -6
- package/dist/login.js.map +1 -1
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +11 -7
- package/dist/program.js.map +1 -1
- package/dist/reasons.d.ts +1 -1
- package/dist/reasons.d.ts.map +1 -1
- package/dist/reasons.js +1 -22
- package/dist/reasons.js.map +1 -1
- package/dist/registry.d.ts +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +2 -1
- package/dist/registry.js.map +1 -1
- package/dist/tokens.js +5 -5
- package/dist/tokens.js.map +1 -1
- package/dist/upload.js +1 -1
- package/dist/upload.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/dist/bundle/chunk-PGKIOSN3.js +0 -249
- package/dist/bundle/command-contract-LQDNHZJU.js +0 -39
- package/dist/bundle/entry-CNOYSSSD.js +0 -22
- package/dist/bundle/first-run-F2SI24PK.js +0 -30
- package/dist/bundle/first-screen-TYYF6VXY.js +0 -37
- package/dist/bundle/grants-EUQXSICG.js +0 -105
- package/dist/bundle/oauth-D6NJFPYU.js +0 -22
- package/dist/bundle/prompt-MFIOJMAF.js +0 -17
- package/dist/bundle/server-EWZYN323.js +0 -70
- package/dist/bundle/store-maintenance-command-RHWRUREJ.js +0 -60
- package/dist/bundle/tokens-TXYURU4S.js +0 -103
- package/dist/oauth-application.d.ts +0 -5
- package/dist/oauth-application.d.ts.map +0 -1
- package/dist/oauth-application.js +0 -9
- package/dist/oauth-application.js.map +0 -1
- /package/dist/bundle/{chunk-LK2E2ELG.js → chunk-LU3WKZBA.js} +0 -0
|
@@ -1,73 +1,45 @@
|
|
|
1
1
|
import { createRequire as __bundleRequire } from "node:module";
|
|
2
2
|
const require = __bundleRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "./chunk-
|
|
4
|
+
activeProfile,
|
|
5
|
+
paths
|
|
6
|
+
} from "./chunk-BQMIDYBA.js";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
READ_SCOPE,
|
|
9
|
+
WRITE_SCOPE,
|
|
10
|
+
providerRequest
|
|
11
|
+
} from "./chunk-XZBR2O63.js";
|
|
11
12
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
issueMessage,
|
|
15
|
-
settingsFor,
|
|
16
|
-
usableProfileName
|
|
17
|
-
} from "./chunk-3KNZADHJ.js";
|
|
13
|
+
googleError
|
|
14
|
+
} from "./chunk-BXR7BKM3.js";
|
|
18
15
|
import {
|
|
19
16
|
acquireLock
|
|
20
|
-
} from "./chunk-
|
|
21
|
-
import {
|
|
22
|
-
LEVELS
|
|
23
|
-
} from "./chunk-AD62XJKO.js";
|
|
24
|
-
import {
|
|
25
|
-
MAX_TEXT_CHARS
|
|
26
|
-
} from "./chunk-IADOBOKB.js";
|
|
27
|
-
import {
|
|
28
|
-
DRIVE_APP
|
|
29
|
-
} from "./chunk-MEAPA4EZ.js";
|
|
17
|
+
} from "./chunk-S4YK6TTG.js";
|
|
30
18
|
import {
|
|
31
19
|
Credentials,
|
|
32
20
|
isMovedRun,
|
|
33
21
|
keyringService,
|
|
34
|
-
resolvePaths,
|
|
35
|
-
saveConfigFile,
|
|
36
22
|
systemKeyring
|
|
37
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-DCBFNBEB.js";
|
|
38
24
|
import {
|
|
39
|
-
array,
|
|
40
|
-
boolean,
|
|
41
|
-
integer,
|
|
42
|
-
literal,
|
|
43
|
-
maxValue,
|
|
44
25
|
minLength,
|
|
45
|
-
|
|
26
|
+
nullable,
|
|
46
27
|
number,
|
|
28
|
+
object,
|
|
47
29
|
optional,
|
|
48
|
-
parse,
|
|
49
|
-
picklist,
|
|
50
30
|
pipe,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
string,
|
|
55
|
-
union
|
|
56
|
-
} from "./chunk-3U22QTU6.js";
|
|
31
|
+
safeParse,
|
|
32
|
+
string
|
|
33
|
+
} from "./chunk-VYXVPYA3.js";
|
|
57
34
|
import {
|
|
58
35
|
CliError,
|
|
59
36
|
isCliError
|
|
60
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-WZ5XK74U.js";
|
|
61
38
|
import {
|
|
62
39
|
__name
|
|
63
40
|
} from "./chunk-ZVVMGPBJ.js";
|
|
64
41
|
|
|
65
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
66
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
67
|
-
import { join } from "node:path";
|
|
68
|
-
import { setTimeout as delay } from "node:timers/promises";
|
|
69
|
-
|
|
70
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.561.0_@wirecat+cli-base@0.75.2_commander@15.0.0_esbuild@0.28.2_type_ef328e5cd047e3c19bb2231542618c08/node_modules/@wirecat/cli-core/dist/oauth/authorize.js
|
|
42
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.566.0_@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_type_2c70ab84360472ff0036a7904a884c42/node_modules/@wirecat/cli-core/dist/oauth/authorize.js
|
|
71
43
|
import { createHash, randomBytes } from "node:crypto";
|
|
72
44
|
import { createServer } from "node:http";
|
|
73
45
|
var DEFAULT_TIMEOUT_MS = 3e5;
|
|
@@ -203,10 +175,15 @@ var authorize = /* @__PURE__ */ __name(async (options) => {
|
|
|
203
175
|
}
|
|
204
176
|
}, "authorize");
|
|
205
177
|
|
|
206
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
178
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.566.0_@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_type_2c70ab84360472ff0036a7904a884c42/node_modules/@wirecat/cli-core/dist/oauth/keeper.js
|
|
179
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
180
|
+
import { join } from "node:path";
|
|
181
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
182
|
+
|
|
183
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.566.0_@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_type_2c70ab84360472ff0036a7904a884c42/node_modules/@wirecat/cli-core/dist/oauth/requests.js
|
|
207
184
|
var REQUEST_LIMIT_MS = 3e4;
|
|
208
185
|
var TOKEN_LOG_EVENT = "oauth.token";
|
|
209
|
-
var
|
|
186
|
+
var object2 = /* @__PURE__ */ __name((value) => {
|
|
210
187
|
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
211
188
|
throw new Error("not an object");
|
|
212
189
|
return value;
|
|
@@ -238,17 +215,17 @@ var clientFields = /* @__PURE__ */ __name(({ client }) => ({
|
|
|
238
215
|
}), "clientFields");
|
|
239
216
|
var requestTokens = /* @__PURE__ */ __name(async (provider, params, context) => {
|
|
240
217
|
const operation = params.grant_type ?? "unknown";
|
|
241
|
-
const
|
|
218
|
+
const record = /* @__PURE__ */ __name((level, fields) => context.log?.[level]({ event: TOKEN_LOG_EVENT, provider: provider.id, operation, pid: process.pid, ...fields }), "record");
|
|
242
219
|
const again = `run ${context.signInCommand} again`;
|
|
243
220
|
const response = await post(provider.tokenUrl, new URLSearchParams({ ...params, ...clientFields(context) }), context);
|
|
244
221
|
if (!response) {
|
|
245
|
-
|
|
222
|
+
record("warn", { outcome: "no_response" });
|
|
246
223
|
throw new CliError("outcome_unknown", `${provider.name} token request did not finish; ${again} if it keeps failing`, {
|
|
247
224
|
reason: "oauth.no-response"
|
|
248
225
|
});
|
|
249
226
|
}
|
|
250
227
|
if (!response.ok) {
|
|
251
|
-
|
|
228
|
+
record("warn", { outcome: "rejected", status: response.status });
|
|
252
229
|
if (response.status === 429 || response.status >= 500)
|
|
253
230
|
throw new CliError("provider_unavailable", `${provider.name} token request failed (HTTP ${response.status})`, {
|
|
254
231
|
status: response.status,
|
|
@@ -262,9 +239,9 @@ var requestTokens = /* @__PURE__ */ __name(async (provider, params, context) =>
|
|
|
262
239
|
}
|
|
263
240
|
let body;
|
|
264
241
|
try {
|
|
265
|
-
body =
|
|
242
|
+
body = object2(await response.json());
|
|
266
243
|
} catch {
|
|
267
|
-
|
|
244
|
+
record("error", { outcome: "unreadable_response", status: response.status });
|
|
268
245
|
throw new CliError("invalid_response", `${provider.name} returned an unreadable token response; ${again}`, {
|
|
269
246
|
reason: "oauth.invalid-response"
|
|
270
247
|
});
|
|
@@ -273,20 +250,20 @@ var requestTokens = /* @__PURE__ */ __name(async (provider, params, context) =>
|
|
|
273
250
|
const refreshToken = typeof body.refresh_token === "string" && body.refresh_token ? body.refresh_token : previous?.refreshToken;
|
|
274
251
|
const expiresIn = body.expires_in;
|
|
275
252
|
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") {
|
|
276
|
-
|
|
253
|
+
record("error", { outcome: "invalid_response", status: response.status });
|
|
277
254
|
throw new CliError("invalid_response", `${provider.name} returned an invalid token response; ${again}`, {
|
|
278
255
|
reason: "oauth.invalid-response"
|
|
279
256
|
});
|
|
280
257
|
}
|
|
281
258
|
if (!refreshToken) {
|
|
282
|
-
|
|
259
|
+
record("error", { outcome: "no_refresh_token", status: response.status });
|
|
283
260
|
throw new CliError("authentication_error", `${provider.name} returned no offline refresh token; ${again}`, {
|
|
284
261
|
reason: "oauth.failed"
|
|
285
262
|
});
|
|
286
263
|
}
|
|
287
264
|
const scopes = typeof body.scope === "string" ? body.scope.split(/\s+/).filter(Boolean) : previous?.scopes ?? [];
|
|
288
265
|
const tokenType = typeof body.token_type === "string" ? body.token_type : previous?.tokenType;
|
|
289
|
-
|
|
266
|
+
record("info", {
|
|
290
267
|
outcome: "received",
|
|
291
268
|
status: response.status,
|
|
292
269
|
...previous ? { rotated: refreshToken !== previous.refreshToken } : {}
|
|
@@ -320,7 +297,7 @@ var revokeToken = /* @__PURE__ */ __name(async (provider, tokens, context) => {
|
|
|
320
297
|
});
|
|
321
298
|
}, "revokeToken");
|
|
322
299
|
|
|
323
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
300
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.566.0_@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_type_2c70ab84360472ff0036a7904a884c42/node_modules/@wirecat/cli-core/dist/oauth/keeper.js
|
|
324
301
|
var inFlight = /* @__PURE__ */ new Map();
|
|
325
302
|
var refreshedInMemory = /* @__PURE__ */ new Map();
|
|
326
303
|
var tokenKeeper = /* @__PURE__ */ __name((options) => {
|
|
@@ -482,9 +459,9 @@ var tokenKeeper = /* @__PURE__ */ __name((options) => {
|
|
|
482
459
|
};
|
|
483
460
|
}, "tokenKeeper");
|
|
484
461
|
|
|
485
|
-
// node_modules/.pnpm/@wirecat+cli-core@0.
|
|
462
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.566.0_@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_type_2c70ab84360472ff0036a7904a884c42/node_modules/@wirecat/cli-core/dist/oauth/storage.js
|
|
486
463
|
var invalid = /* @__PURE__ */ __name(() => new CliError("authentication_error", "the saved sign-in cannot be read; sign in again", { reason: "oauth.invalid" }), "invalid");
|
|
487
|
-
var
|
|
464
|
+
var parse = /* @__PURE__ */ __name((raw) => {
|
|
488
465
|
let value;
|
|
489
466
|
try {
|
|
490
467
|
value = JSON.parse(raw);
|
|
@@ -501,7 +478,7 @@ var previousOf = /* @__PURE__ */ __name((raw) => {
|
|
|
501
478
|
if (raw === void 0)
|
|
502
479
|
return {};
|
|
503
480
|
try {
|
|
504
|
-
return
|
|
481
|
+
return parse(raw);
|
|
505
482
|
} catch {
|
|
506
483
|
return {};
|
|
507
484
|
}
|
|
@@ -509,7 +486,7 @@ var previousOf = /* @__PURE__ */ __name((raw) => {
|
|
|
509
486
|
var defined = /* @__PURE__ */ __name((value) => Object.fromEntries(Object.entries(value).filter(([, field]) => field !== void 0)), "defined");
|
|
510
487
|
var driveSessionCodec = {
|
|
511
488
|
decode: /* @__PURE__ */ __name((raw) => {
|
|
512
|
-
const value =
|
|
489
|
+
const value = parse(raw);
|
|
513
490
|
const tokens = value.tokens;
|
|
514
491
|
if (typeof tokens !== "object" || tokens === null || Array.isArray(tokens))
|
|
515
492
|
throw invalid();
|
|
@@ -519,7 +496,11 @@ var driveSessionCodec = {
|
|
|
519
496
|
if (!refreshToken || !clientId || typeof value.principal !== "string")
|
|
520
497
|
throw invalid();
|
|
521
498
|
return {
|
|
522
|
-
client: defined({
|
|
499
|
+
client: defined({
|
|
500
|
+
clientId,
|
|
501
|
+
clientSecret: text(value.clientSecret),
|
|
502
|
+
source: text(value.clientSource)
|
|
503
|
+
}),
|
|
523
504
|
tokens: defined({
|
|
524
505
|
accessToken: text(fields.access_token),
|
|
525
506
|
refreshToken,
|
|
@@ -537,6 +518,7 @@ var driveSessionCodec = {
|
|
|
537
518
|
...extra,
|
|
538
519
|
clientId: client.clientId,
|
|
539
520
|
...client.clientSecret ? { clientSecret: client.clientSecret } : {},
|
|
521
|
+
...client.source ? { clientSource: client.source } : {},
|
|
540
522
|
tokens: defined({
|
|
541
523
|
...oldTokens,
|
|
542
524
|
access_token: tokens.accessToken,
|
|
@@ -560,20 +542,20 @@ var keyringFailure = /* @__PURE__ */ __name((thrown, secret) => {
|
|
|
560
542
|
var credentialStorage = /* @__PURE__ */ __name((options) => {
|
|
561
543
|
if (!options.credentials.keyring)
|
|
562
544
|
throw new CliError("configuration_error", "a sign-in store needs its keyring passed in, never a default");
|
|
563
|
-
const
|
|
545
|
+
const credentials2 = new Credentials(options.credentials);
|
|
564
546
|
const { account, codec } = options;
|
|
565
547
|
const moved = options.credentials.isolated === true || options.credentials.keyring === systemKeyring && isMovedRun({ appName: options.credentials.service, env: options.credentials.env ?? process.env });
|
|
566
548
|
const service = keyringService(options.credentials.service, options.credentials.configDir, options.credentials.isolated);
|
|
567
549
|
const raw = /* @__PURE__ */ __name((name) => {
|
|
568
550
|
try {
|
|
569
|
-
return
|
|
551
|
+
return credentials2.read(name)?.secret;
|
|
570
552
|
} catch (error) {
|
|
571
553
|
throw keyringFailure(error);
|
|
572
554
|
}
|
|
573
555
|
}, "raw");
|
|
574
556
|
const save = /* @__PURE__ */ __name((value, writeOptions) => {
|
|
575
557
|
try {
|
|
576
|
-
|
|
558
|
+
credentials2.write(account, value, writeOptions);
|
|
577
559
|
} catch (error) {
|
|
578
560
|
throw keyringFailure(error, value);
|
|
579
561
|
}
|
|
@@ -606,7 +588,7 @@ var credentialStorage = /* @__PURE__ */ __name((options) => {
|
|
|
606
588
|
write: /* @__PURE__ */ __name((input, writeOptions) => save(codec.encode({ ...input, previous: raw(account) }), writeOptions), "write"),
|
|
607
589
|
remove: /* @__PURE__ */ __name(() => {
|
|
608
590
|
try {
|
|
609
|
-
return
|
|
591
|
+
return credentials2.remove(account);
|
|
610
592
|
} catch (error) {
|
|
611
593
|
throw keyringFailure(error);
|
|
612
594
|
}
|
|
@@ -614,296 +596,212 @@ var credentialStorage = /* @__PURE__ */ __name((options) => {
|
|
|
614
596
|
};
|
|
615
597
|
}, "credentialStorage");
|
|
616
598
|
|
|
617
|
-
//
|
|
618
|
-
import {
|
|
619
|
-
var
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
599
|
+
// dist/tokens.js
|
|
600
|
+
import { OAuth2Client } from "google-auth-library";
|
|
601
|
+
var Session = object({
|
|
602
|
+
principal: string(),
|
|
603
|
+
clientId: string(),
|
|
604
|
+
clientSecret: optional(string()),
|
|
605
|
+
tokens: object({
|
|
606
|
+
access_token: optional(nullable(string())),
|
|
607
|
+
refresh_token: pipe(string(), minLength(1)),
|
|
608
|
+
expiry_date: optional(nullable(number())),
|
|
609
|
+
scope: optional(string()),
|
|
610
|
+
token_type: optional(nullable(string()))
|
|
611
|
+
})
|
|
612
|
+
});
|
|
613
|
+
var credentialOptions = /* @__PURE__ */ __name((env, storage, keyring) => ({
|
|
614
|
+
configDir: paths(env).config,
|
|
615
|
+
service: "drive-cli",
|
|
616
|
+
// The keyring falls back to the private file by itself (WC-SECR-4); `file` skips the keyring.
|
|
617
|
+
storage: storage === "keyring" ? "auto" : storage,
|
|
618
|
+
env,
|
|
619
|
+
isolated: isMovedRun({ appName: "drive-cli", prefix: "DRIVE", env }),
|
|
620
|
+
...keyring ? { keyring } : {}
|
|
621
|
+
}), "credentialOptions");
|
|
622
|
+
var credentials = /* @__PURE__ */ __name((env, storage, keyring) => new Credentials(credentialOptions(env, storage, keyring)), "credentials");
|
|
623
|
+
var notSaved = /* @__PURE__ */ __name(() => new CliError("configuration_error", "could not save Google sign-in: the private credentials file cannot be read; move it aside and sign in again", { reason: "oauth.not-saved" }), "notSaved");
|
|
624
|
+
var saveSession = /* @__PURE__ */ __name((env, name, session, storage, keyring) => {
|
|
625
625
|
try {
|
|
626
|
-
|
|
627
|
-
const { client_id: clientId, client_secret: clientSecret } = installed;
|
|
628
|
-
if (typeof clientId !== "string" || !clientId)
|
|
629
|
-
throw new TypeError("client_id");
|
|
630
|
-
if (clientSecret !== void 0 && typeof clientSecret !== "string")
|
|
631
|
-
throw new TypeError("client_secret");
|
|
632
|
-
return { clientId, ...clientSecret ? { clientSecret } : {} };
|
|
626
|
+
credentials(env, storage, keyring).write(name, JSON.stringify(session));
|
|
633
627
|
} catch {
|
|
634
|
-
throw
|
|
628
|
+
throw notSaved();
|
|
635
629
|
}
|
|
636
|
-
}, "
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
630
|
+
}, "saveSession");
|
|
631
|
+
var googleProvider = /* @__PURE__ */ __name((client) => ({
|
|
632
|
+
id: "google",
|
|
633
|
+
name: "Google",
|
|
634
|
+
authorizeUrl: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
635
|
+
tokenUrl: "https://oauth2.googleapis.com/token",
|
|
636
|
+
revokeUrl: "https://oauth2.googleapis.com/revoke",
|
|
637
|
+
client,
|
|
638
|
+
redirect: { kind: "loopback" },
|
|
639
|
+
// Without offline access Google returns no refresh token; without consent it does not return one again.
|
|
640
|
+
authorizeParams: { access_type: "offline", prompt: "select_account consent" }
|
|
641
|
+
}), "googleProvider");
|
|
642
|
+
var sessionKeeper = /* @__PURE__ */ __name((options) => tokenKeeper({
|
|
643
|
+
provider: googleProvider(options.client),
|
|
644
|
+
storage: credentialStorage({
|
|
645
|
+
credentials: { ...credentialOptions(options.env, options.storage), keyring: options.keyring ?? systemKeyring },
|
|
646
|
+
account: options.name,
|
|
647
|
+
codec: driveSessionCodec
|
|
648
|
+
}),
|
|
649
|
+
lockDir: paths(options.env).config,
|
|
650
|
+
fetch: options.fetch ?? globalThis.fetch,
|
|
651
|
+
signInCommand: `drive ${options.name} session start`,
|
|
652
|
+
// Above the client's own 5-minute early refresh, so a token it asks to replace is replaced.
|
|
653
|
+
freshForMs: 6 * 6e4,
|
|
654
|
+
...options.signal ? { signal: options.signal } : {}
|
|
655
|
+
}), "sessionKeeper");
|
|
656
|
+
var authorizedClient = /* @__PURE__ */ __name((env, name, keyring, signal) => {
|
|
657
|
+
const profile = activeProfile(env, name);
|
|
658
|
+
let parsed;
|
|
659
|
+
try {
|
|
660
|
+
const secret = credentials(env, profile.storage, keyring).read(name)?.secret;
|
|
661
|
+
if (!secret)
|
|
662
|
+
throw new Error("missing login");
|
|
663
|
+
parsed = safeParse(Session, JSON.parse(secret));
|
|
664
|
+
} catch {
|
|
665
|
+
throw new CliError("authentication_error", `could not load Google sign-in \u2014 run drive ${name} session start again`, {
|
|
666
|
+
reason: "oauth.expired"
|
|
667
|
+
});
|
|
662
668
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
keys.push("sheets.insert");
|
|
694
|
-
if (request.repeatCell || request.updateCells || request.appendCells || request.updateBorders || request.addConditionalFormatRule || request.updateConditionalFormatRule || request.deleteConditionalFormatRule || request.addBanding || request.updateBanding || request.deleteBanding)
|
|
695
|
-
keys.push("sheets.format");
|
|
696
|
-
if (request.updateCells || request.appendCells || request.findReplace || request.pasteData || request.copyPaste || request.cutPaste || request.autoFill)
|
|
697
|
-
keys.push("sheets.update");
|
|
698
|
-
if (request.pasteData || request.copyPaste || request.cutPaste || request.autoFill)
|
|
699
|
-
keys.push("sheets.format");
|
|
700
|
-
if (object2(request.repeatCell) && (String(request.repeatCell.fields).split(",").some((field) => field.trim() === "*" || field.includes("userEnteredValue")) || object2(request.repeatCell.cell) && request.repeatCell.cell.userEnteredValue !== void 0))
|
|
701
|
-
keys.push("sheets.update");
|
|
669
|
+
if (!parsed.success || parsed.output.principal !== profile.principal)
|
|
670
|
+
throw new CliError("authentication_error", "saved sign-in is invalid or belongs to another account", {
|
|
671
|
+
reason: "oauth.expired"
|
|
672
|
+
});
|
|
673
|
+
const session = parsed.output;
|
|
674
|
+
const keeper = sessionKeeper({
|
|
675
|
+
env,
|
|
676
|
+
name,
|
|
677
|
+
storage: profile.storage,
|
|
678
|
+
client: { clientId: session.clientId, ...session.clientSecret ? { clientSecret: session.clientSecret } : {} },
|
|
679
|
+
...keyring ? { keyring } : {},
|
|
680
|
+
...signal ? { signal } : {}
|
|
681
|
+
});
|
|
682
|
+
const client = new OAuth2Client({
|
|
683
|
+
clientId: session.clientId,
|
|
684
|
+
clientSecret: session.clientSecret,
|
|
685
|
+
transporterOptions: { timeout: 3e4, ...signal ? { signal } : {} }
|
|
686
|
+
});
|
|
687
|
+
client.refreshHandler = async () => {
|
|
688
|
+
try {
|
|
689
|
+
const tokens = await keeper.tokens();
|
|
690
|
+
if (!tokens.accessToken || tokens.expiresAt === void 0)
|
|
691
|
+
throw new Error("no access token");
|
|
692
|
+
return { access_token: tokens.accessToken, expiry_date: tokens.expiresAt };
|
|
693
|
+
} catch (error) {
|
|
694
|
+
if (isCliError(error) && error.code !== "authentication_error")
|
|
695
|
+
throw error;
|
|
696
|
+
throw new CliError("authentication_error", `Google sign-in expired \u2014 run drive ${name} session start again`, {
|
|
697
|
+
reason: "oauth.expired"
|
|
698
|
+
});
|
|
702
699
|
}
|
|
703
|
-
}
|
|
704
|
-
return [...new Set(keys)];
|
|
705
|
-
}, "methodPolicyKeys");
|
|
706
|
-
|
|
707
|
-
// dist/config.js
|
|
708
|
-
import { readFileSync as readFileSync2 } from "node:fs";
|
|
709
|
-
import { join as join2 } from "node:path";
|
|
710
|
-
|
|
711
|
-
// dist/oauth-application.js
|
|
712
|
-
var WIRECAT_APPLICATION = Object.freeze({
|
|
713
|
-
clientId: "240274586781-vssrlm9c0l3n1ti12ce7tg95ro4bghal.apps.googleusercontent.com",
|
|
714
|
-
// biome-ignore lint/security/noSecrets: public installed-app OAuth identity, non-confidential per Google native-app guidance
|
|
715
|
-
clientSecret: "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"
|
|
716
|
-
// gitleaks:allow -- public installed-app identity
|
|
717
|
-
});
|
|
718
|
-
|
|
719
|
-
// dist/config.js
|
|
720
|
-
var Common = {
|
|
721
|
-
...AI_ENTRIES,
|
|
722
|
-
permissions: optional(record(string(), picklist(LEVELS))),
|
|
723
|
-
max_text_chars: optional(pipe(number(), integer(), minValue(1), maxValue(MAX_TEXT_CHARS)))
|
|
724
|
-
};
|
|
725
|
-
var RunSettings = {
|
|
726
|
-
record: optional(boolean()),
|
|
727
|
-
keep_runs_for_days: optional(pipe(number(), integer(), minValue(1))),
|
|
728
|
-
keep_successful_runs_for_days: optional(pipe(number(), integer(), minValue(1))),
|
|
729
|
-
runs_size_limit_mb: optional(pipe(number(), integer(), minValue(1))),
|
|
730
|
-
record_input: optional(union([boolean(), literal("failed")]))
|
|
731
|
-
};
|
|
732
|
-
var SharedDefaults = {
|
|
733
|
-
limit: optional(pipe(number(), integer(), minValue(1))),
|
|
734
|
-
sends_per_hour: optional(pipe(number(), integer(), minValue(0))),
|
|
735
|
-
update_check: optional(boolean()),
|
|
736
|
-
skill_hint: optional(boolean())
|
|
737
|
-
};
|
|
738
|
-
var DEFAULTS_ONLY = /* @__PURE__ */ new Set([...Object.keys(RunSettings), "update_check", "skill_hint"]);
|
|
739
|
-
var SETTING_NAMES = /* @__PURE__ */ new Set([...Object.keys(Common), "picture_search", ...DEFAULTS_ONLY]);
|
|
740
|
-
var Mirror = strictObject({
|
|
741
|
-
id: pipe(string(), regex(/^[a-z0-9-]{1,40}$/)),
|
|
742
|
-
path: pipe(string(), minLength(1)),
|
|
743
|
-
folder: pipe(string(), regex(/^[A-Za-z0-9_-]{1,200}$/))
|
|
744
|
-
});
|
|
745
|
-
var Profile = strictObject({
|
|
746
|
-
principal: string(),
|
|
747
|
-
roots: optional(array(pipe(string(), regex(/^[A-Za-z0-9_-]{1,200}$/))), []),
|
|
748
|
-
mirrors: optional(array(Mirror)),
|
|
749
|
-
storage: picklist(["keyring", "file"]),
|
|
750
|
-
picture_search: optional(boolean()),
|
|
751
|
-
...Common
|
|
752
|
-
});
|
|
753
|
-
var ConfigSchema = strictObject({
|
|
754
|
-
profiles: optional(record(string(), Profile), {}),
|
|
755
|
-
defaults: optional(strictObject({ ...Common, ...RunSettings, ...SharedDefaults }))
|
|
756
|
-
});
|
|
757
|
-
var keyOf = /* @__PURE__ */ __name((path) => {
|
|
758
|
-
if (path[0] !== "api" || path[1] === void 0)
|
|
759
|
-
return commandPathKey(path);
|
|
760
|
-
if (["call", "list", "show"].includes(path[1]))
|
|
761
|
-
return null;
|
|
762
|
-
const operation = operations.find((one) => one.command === path[1]);
|
|
763
|
-
return operation ? `api.${operation.id}` : commandPathKey(path);
|
|
764
|
-
}, "keyOf");
|
|
765
|
-
var configuration = settingsFor(DRIVE_APP, {
|
|
766
|
-
// drive's own schema decides what the file may hold, so `doctor` names a profile that lacks its principal.
|
|
767
|
-
schema: ConfigSchema,
|
|
768
|
-
profile: {
|
|
769
|
-
principal: optional(string()),
|
|
770
|
-
roots: optional(array(pipe(string(), regex(/^[A-Za-z0-9_-]{1,200}$/)))),
|
|
771
|
-
mirrors: optional(array(Mirror)),
|
|
772
|
-
storage: optional(picklist(["keyring", "file"])),
|
|
773
|
-
max_text_chars: Common.max_text_chars
|
|
774
|
-
},
|
|
775
|
-
permissions: commandPermissions({ keyOf, extra: [...permissionKeys([])], defaults: DEFAULT_LEVELS })
|
|
776
|
-
});
|
|
777
|
-
var paths = /* @__PURE__ */ __name((env) => resolvePaths({ appName: "drive-cli", prefix: "DRIVE", env }), "paths");
|
|
778
|
-
var configPath = /* @__PURE__ */ __name((env) => join2(paths(env).config, "config.json"), "configPath");
|
|
779
|
-
var TOOL = "drive";
|
|
780
|
-
var isNode = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null && !Array.isArray(value), "isNode");
|
|
781
|
-
var withoutIncomplete = /* @__PURE__ */ __name((raw, issues) => {
|
|
782
|
-
const incomplete = new Set(issues.flatMap((issue) => issue.kind === "missing_setting" && issue.profile ? [issue.profile] : []));
|
|
783
|
-
if (!incomplete.size || !isNode(raw) || !isNode(raw.profiles))
|
|
784
|
-
return void 0;
|
|
785
|
-
return {
|
|
786
|
-
...raw,
|
|
787
|
-
profiles: Object.fromEntries(Object.entries(raw.profiles).filter(([name]) => !incomplete.has(name)))
|
|
788
|
-
};
|
|
789
|
-
}, "withoutIncomplete");
|
|
790
|
-
var examine = /* @__PURE__ */ __name((text2, file, knownPermissions) => {
|
|
791
|
-
const check = /* @__PURE__ */ __name((body) => checkConfigText(body, { file, tool: TOOL, schema: ConfigSchema, ...knownPermissions ? { knownPermissions } : {} }), "check");
|
|
792
|
-
const first = check(text2);
|
|
793
|
-
if (first.issues.some((issue) => issue.kind === "invalid_json"))
|
|
794
|
-
return { raw: {}, config: { profiles: {} }, issues: first.issues };
|
|
795
|
-
const raw = JSON.parse(text2);
|
|
796
|
-
if (first.config)
|
|
797
|
-
return { raw, config: first.config, issues: first.issues };
|
|
798
|
-
const rest = withoutIncomplete(raw, first.issues);
|
|
799
|
-
const second = rest && check(JSON.stringify(rest));
|
|
800
|
-
return {
|
|
801
|
-
raw,
|
|
802
|
-
config: second?.config ?? { profiles: {} },
|
|
803
|
-
// Saved permissions are checked only in what loads, and the first pass loaded nothing.
|
|
804
|
-
issues: [...first.issues, ...(second?.issues ?? []).filter((issue) => issue.kind === "unknown_permission")]
|
|
805
700
|
};
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
701
|
+
const { refresh_token: _refresh, ...current } = session.tokens;
|
|
702
|
+
client.setCredentials(current);
|
|
703
|
+
return observeRequests(client);
|
|
704
|
+
}, "authorizedClient");
|
|
705
|
+
var covers = /* @__PURE__ */ __name((granted, required) => granted.includes(required) || required === READ_SCOPE && granted.includes(WRITE_SCOPE), "covers");
|
|
706
|
+
var grantedScopes = /* @__PURE__ */ __name((env, name, keyring) => {
|
|
810
707
|
try {
|
|
811
|
-
|
|
708
|
+
const secret = credentials(env, activeProfile(env, name).storage, keyring).read(name)?.secret;
|
|
709
|
+
const parsed = secret ? safeParse(Session, JSON.parse(secret)) : void 0;
|
|
710
|
+
if (!parsed?.success)
|
|
711
|
+
return [];
|
|
712
|
+
return parsed.output.tokens.scope?.split(/\s+/).filter(Boolean);
|
|
812
713
|
} catch {
|
|
813
|
-
return
|
|
714
|
+
return [];
|
|
814
715
|
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
const [issue] = configIssues(config, "drive settings");
|
|
827
|
-
if (issue)
|
|
828
|
-
throw new CliError("configuration_error", `drive settings: ${issue.profile === void 0 ? "" : `profile ${issue.profile}: `}${issue.what}`);
|
|
829
|
-
saveConfigFile(configPath(env), parse(ConfigSchema, config));
|
|
830
|
-
}, "writeConfig");
|
|
831
|
-
var profileName = usableProfileName;
|
|
832
|
-
var fileId = /* @__PURE__ */ __name((input) => {
|
|
833
|
-
let id = input;
|
|
834
|
-
if (input.startsWith("https://")) {
|
|
835
|
-
const url = new URL(input);
|
|
836
|
-
if (url.hostname !== "drive.google.com" && url.hostname !== "docs.google.com")
|
|
837
|
-
throw new CliError("validation_error", "use a Google Drive/Docs URL or file ID");
|
|
838
|
-
id = url.pathname.match(/\/(?:folders|d)\/([^/]+)/)?.[1] ?? "";
|
|
716
|
+
}, "grantedScopes");
|
|
717
|
+
var checkAuthorization = /* @__PURE__ */ __name(async (client, required = READ_SCOPE) => {
|
|
718
|
+
try {
|
|
719
|
+
const { token } = await client.getAccessToken();
|
|
720
|
+
if (!token)
|
|
721
|
+
throw new CliError("authentication_error", "Google returned no access token");
|
|
722
|
+
const info = await client.getTokenInfo(token);
|
|
723
|
+
if (!covers(info.scopes, required))
|
|
724
|
+
throw new CliError("permission_error", "sign-in lacks the required permission; run drive <profile> session start --grant write, activity or apps when needed", { reason: "oauth.scope-missing" });
|
|
725
|
+
} catch (error) {
|
|
726
|
+
throw googleError(error);
|
|
839
727
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
const
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
throw new CliError("validation_error", "max_text_chars must be a positive whole number of characters");
|
|
855
|
-
if (value > MAX_TEXT_CHARS)
|
|
856
|
-
throw new CliError("validation_error", `max_text_chars can be at most ${MAX_TEXT_CHARS}: the document readers return at most that many characters`);
|
|
857
|
-
return value;
|
|
858
|
-
}, "checkTextLimit");
|
|
859
|
-
var textLimit = /* @__PURE__ */ __name((env, name) => activeProfile(env, name).max_text_chars ?? readConfig(env).defaults?.max_text_chars ?? MAX_TEXT_CHARS, "textLimit");
|
|
860
|
-
var pictureSearch = /* @__PURE__ */ __name((env, name) => activeProfile(env, name).picture_search ?? false, "pictureSearch");
|
|
861
|
-
var application = /* @__PURE__ */ __name((env, file) => {
|
|
862
|
-
if (!file) {
|
|
863
|
-
if (!env.DRIVE_GOOGLE_CLIENT_ID) {
|
|
864
|
-
if (env.DRIVE_GOOGLE_CLIENT_SECRET)
|
|
865
|
-
throw new CliError("configuration_error", "DRIVE_GOOGLE_CLIENT_SECRET requires DRIVE_GOOGLE_CLIENT_ID");
|
|
866
|
-
return { ...WIRECAT_APPLICATION };
|
|
867
|
-
}
|
|
868
|
-
return {
|
|
869
|
-
clientId: env.DRIVE_GOOGLE_CLIENT_ID,
|
|
870
|
-
...env.DRIVE_GOOGLE_CLIENT_SECRET ? { clientSecret: env.DRIVE_GOOGLE_CLIENT_SECRET } : {}
|
|
871
|
-
};
|
|
728
|
+
}, "checkAuthorization");
|
|
729
|
+
var WORD = /^[a-z][a-z_]{0,23}$/;
|
|
730
|
+
var VERB = /^[a-z][A-Za-z]{0,31}$/;
|
|
731
|
+
var segment = /* @__PURE__ */ __name((part) => {
|
|
732
|
+
if (/^v\d+$/.test(part) || WORD.test(part))
|
|
733
|
+
return part;
|
|
734
|
+
const verb = part.split(":")[1];
|
|
735
|
+
return verb !== void 0 && VERB.test(verb) ? `:id:${verb}` : ":id";
|
|
736
|
+
}, "segment");
|
|
737
|
+
var operationOf = /* @__PURE__ */ __name((method, url) => {
|
|
738
|
+
let path = "";
|
|
739
|
+
try {
|
|
740
|
+
path = new URL(String(url ?? "")).pathname;
|
|
741
|
+
} catch {
|
|
872
742
|
}
|
|
873
|
-
|
|
874
|
-
|
|
743
|
+
const template = path.split("/").filter(Boolean).map((part) => segment(decodeURIComponent(part))).join("/");
|
|
744
|
+
return `${(method ?? "GET").toUpperCase()} /${template}`;
|
|
745
|
+
}, "operationOf");
|
|
746
|
+
var reasonOf = /* @__PURE__ */ __name((data) => {
|
|
747
|
+
const error = data?.error;
|
|
748
|
+
const reason = error?.errors?.[0]?.reason ?? error?.status;
|
|
749
|
+
return typeof reason === "string" ? reason : void 0;
|
|
750
|
+
}, "reasonOf");
|
|
751
|
+
var observeRequests = /* @__PURE__ */ __name((client) => {
|
|
752
|
+
const transporter = client.transporter;
|
|
753
|
+
const request = transporter.request.bind(transporter);
|
|
754
|
+
transporter.request = (async (options) => {
|
|
755
|
+
const method = (options.method ?? "GET").toUpperCase();
|
|
756
|
+
const operation = operationOf(method, options.url);
|
|
757
|
+
const call = { method, endpointTemplate: operation.slice(method.length + 1), transport: "http" };
|
|
758
|
+
let ended;
|
|
759
|
+
const adapter = /* @__PURE__ */ __name(async (prepared, next) => {
|
|
760
|
+
const attempt = (prepared.retryConfig?.currentRetryAttempt ?? 0) + 1;
|
|
761
|
+
const waitMs = ended === void 0 ? void 0 : Math.round(performance.now() - ended);
|
|
762
|
+
const answered = providerRequest(operation, void 0, {
|
|
763
|
+
...call,
|
|
764
|
+
attempt,
|
|
765
|
+
...waitMs === void 0 ? {} : { waitMs }
|
|
766
|
+
});
|
|
767
|
+
try {
|
|
768
|
+
const response = await (options.adapter ? options.adapter(prepared, next) : next(prepared));
|
|
769
|
+
const failed = !(prepared.validateStatus?.(response.status) ?? response.status < 400);
|
|
770
|
+
const providerError = failed ? reasonOf(response.data) : void 0;
|
|
771
|
+
answered({
|
|
772
|
+
status: response.status,
|
|
773
|
+
...failed ? { errorCode: "provider_error" } : {},
|
|
774
|
+
...providerError ? { providerError } : {}
|
|
775
|
+
});
|
|
776
|
+
return response;
|
|
777
|
+
} catch (error) {
|
|
778
|
+
answered({ error, errorCode: googleError(error).code });
|
|
779
|
+
throw error;
|
|
780
|
+
} finally {
|
|
781
|
+
ended = performance.now();
|
|
782
|
+
}
|
|
783
|
+
}, "adapter");
|
|
784
|
+
try {
|
|
785
|
+
return await request({ ...options, adapter });
|
|
786
|
+
} catch (error) {
|
|
787
|
+
if (ended === void 0)
|
|
788
|
+
providerRequest(operation, void 0, { ...call, attempt: 1 })({ error, errorCode: googleError(error).code });
|
|
789
|
+
throw error;
|
|
790
|
+
}
|
|
875
791
|
});
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
var configuredMirrors = /* @__PURE__ */ __name((env, profile, filter = {}) => (activeProfile(env, profile).mirrors ?? []).filter((row) => Object.entries(filter).every(([key, value]) => row[key] === value)), "configuredMirrors");
|
|
879
|
-
var configuredSessions = /* @__PURE__ */ __name((env, filter, knownPermissions) => Object.entries(readConfig(env, knownPermissions).profiles).flatMap(([name, row]) => (filter.profile === void 0 || filter.profile === name) && (filter.storage === void 0 || filter.storage === row.storage) ? [{ profile: name, selected_folders: row.roots.length, storage: row.storage }] : []), "configuredSessions");
|
|
792
|
+
return client;
|
|
793
|
+
}, "observeRequests");
|
|
880
794
|
|
|
881
795
|
export {
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
inspectConfig,
|
|
894
|
-
configIssues,
|
|
895
|
-
refusal,
|
|
896
|
-
readConfig,
|
|
897
|
-
writeConfig,
|
|
898
|
-
profileName,
|
|
899
|
-
fileId,
|
|
900
|
-
unknownProfile,
|
|
901
|
-
activeProfile,
|
|
902
|
-
checkTextLimit,
|
|
903
|
-
textLimit,
|
|
904
|
-
pictureSearch,
|
|
905
|
-
application,
|
|
906
|
-
selectedFolders,
|
|
907
|
-
configuredMirrors,
|
|
908
|
-
configuredSessions
|
|
796
|
+
credentials,
|
|
797
|
+
notSaved,
|
|
798
|
+
saveSession,
|
|
799
|
+
googleProvider,
|
|
800
|
+
sessionKeeper,
|
|
801
|
+
authorizedClient,
|
|
802
|
+
covers,
|
|
803
|
+
grantedScopes,
|
|
804
|
+
checkAuthorization,
|
|
805
|
+
operationOf,
|
|
806
|
+
observeRequests
|
|
909
807
|
};
|