@introspection-ai/recipes 0.23.0 → 0.25.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 -4
- package/dist/channels/config.d.ts +10 -0
- package/dist/channels/config.d.ts.map +1 -0
- package/dist/channels/config.js +13 -0
- package/dist/channels/config.js.map +1 -0
- package/dist/channels/index.d.ts +4 -2
- package/dist/channels/index.d.ts.map +1 -1
- package/dist/channels/index.js +2 -1
- package/dist/channels/index.js.map +1 -1
- package/dist/channels/module.d.ts +11 -6
- package/dist/channels/module.d.ts.map +1 -1
- package/dist/channels/module.js +22 -10
- package/dist/channels/module.js.map +1 -1
- package/dist/channels/refs.d.ts +3 -3
- package/dist/channels/refs.d.ts.map +1 -1
- package/dist/channels/refs.js +11 -8
- package/dist/channels/refs.js.map +1 -1
- package/dist/channels/tools.d.ts +15 -22
- package/dist/channels/tools.d.ts.map +1 -1
- package/dist/channels/tools.js +279 -114
- package/dist/channels/tools.js.map +1 -1
- package/dist/channels/types.d.ts +34 -29
- package/dist/channels/types.d.ts.map +1 -1
- package/dist/channels/types.js +4 -17
- package/dist/channels/types.js.map +1 -1
- package/dist/connector-tools.d.ts +2 -0
- package/dist/connector-tools.d.ts.map +1 -1
- package/dist/connector-tools.js +17 -15
- package/dist/connector-tools.js.map +1 -1
- package/dist/mcp-chunks/{auth-command-4OEOMU2V.js → auth-command-4WFRNU2I.js} +24 -24
- package/dist/mcp-chunks/call-arguments-4DWPBLQP.js +15 -0
- package/dist/mcp-chunks/{call-command-AUEKSBMD.js → call-command-JBIKXOGC.js} +36 -36
- package/dist/mcp-chunks/{chunk-L4CUJJI5.js → chunk-36VIJRYY.js} +4 -4
- package/dist/mcp-chunks/{chunk-PPIXUCYQ.js → chunk-3JGS7LQB.js} +2 -2
- package/dist/mcp-chunks/{chunk-4NDR45CX.js → chunk-3R2WK3NB.js} +28 -9
- package/dist/mcp-chunks/{chunk-YX2NKW6O.js → chunk-3Z7MFS6K.js} +23 -6
- package/dist/mcp-chunks/{chunk-ACTRQW5L.js → chunk-4ZNBWL65.js} +2 -2
- package/dist/mcp-chunks/chunk-53NRFMB3.js +990 -0
- package/dist/mcp-chunks/{chunk-6QH47GNE.js → chunk-6YZW3XAE.js} +68 -6
- package/dist/mcp-chunks/{chunk-X3FOKZ5C.js → chunk-7WOKCV6Q.js} +1 -1
- package/dist/mcp-chunks/{chunk-MOML5C2E.js → chunk-AD3FQ73K.js} +1 -1
- package/dist/mcp-chunks/{chunk-HDUKEFBI.js → chunk-AIKLVBYU.js} +2 -2
- package/dist/mcp-chunks/{chunk-SQTXZR56.js → chunk-ASG4OY3M.js} +21 -604
- package/dist/mcp-chunks/{chunk-V4RYLZM5.js → chunk-B2LNXGAP.js} +1 -1
- package/dist/mcp-chunks/{chunk-XVJAASVZ.js → chunk-BWW4XRUC.js} +16 -16
- package/dist/mcp-chunks/{chunk-MRXSXBZT.js → chunk-C2KNLFZR.js} +2 -2
- package/dist/mcp-chunks/{chunk-KPXFBRTG.js → chunk-CZKDJZER.js} +1 -1
- package/dist/mcp-chunks/{chunk-6CYJ6RN3.js → chunk-DTZHEVKC.js} +1 -1
- package/dist/mcp-chunks/{chunk-JZDXKYQM.js → chunk-ED2WN5BI.js} +9 -4
- package/dist/mcp-chunks/{chunk-OGFFBNIC.js → chunk-ELA77TDC.js} +4 -4
- package/dist/mcp-chunks/{chunk-5WGJPYOR.js → chunk-EMSNQHZZ.js} +1 -1
- package/dist/mcp-chunks/{chunk-AB7MHBEG.js → chunk-EPT4MYOF.js} +11 -11
- package/dist/mcp-chunks/{chunk-HHMWZ2FZ.js → chunk-FAJPJTOC.js} +1 -1
- package/dist/mcp-chunks/{chunk-TGJOZDKG.js → chunk-FS5JIKT6.js} +2 -2
- package/dist/mcp-chunks/{chunk-IPH6U7SE.js → chunk-FX5NYWBH.js} +3 -3
- package/dist/mcp-chunks/{chunk-SCGMRUKI.js → chunk-G6OMDUNG.js} +5 -5
- package/dist/mcp-chunks/{chunk-47N2EELW.js → chunk-GQ6NSIDS.js} +30 -30
- package/dist/mcp-chunks/{chunk-PPOHGQKM.js → chunk-GUXMP7QB.js} +2 -2
- package/dist/mcp-chunks/{chunk-NMFI6AUD.js → chunk-H3JCYHGS.js} +25 -25
- package/dist/mcp-chunks/{chunk-3VLPWGJL.js → chunk-HCOKLSOB.js} +4 -4
- package/dist/mcp-chunks/{chunk-J6VOMOKI.js → chunk-HLRCUHNO.js} +1 -1
- package/dist/mcp-chunks/{chunk-LWVFSQYX.js → chunk-HN7WPMCA.js} +7806 -3454
- package/dist/mcp-chunks/chunk-I5GI2A2D.js +92 -0
- package/dist/mcp-chunks/{chunk-7KEDX7SE.js → chunk-IME7DGLJ.js} +2 -2
- package/dist/mcp-chunks/{chunk-E4YYMOT2.js → chunk-IPNSPKQK.js} +33 -21
- package/dist/mcp-chunks/{chunk-ZKFG37TB.js → chunk-IRTJXFWA.js} +2 -2
- package/dist/mcp-chunks/{chunk-KMH3PHLA.js → chunk-ITCCROID.js} +13 -7
- package/dist/mcp-chunks/{chunk-ADINDBOF.js → chunk-ITR7FQM3.js} +2 -2
- package/dist/mcp-chunks/{chunk-JILBFEBD.js → chunk-IYWYVHHD.js} +1 -1
- package/dist/mcp-chunks/{chunk-RO2Y34XX.js → chunk-JG4TRUPF.js} +1 -1
- package/dist/mcp-chunks/{chunk-DEYKPG4K.js → chunk-KW3ANJ36.js} +4 -4
- package/dist/mcp-chunks/{chunk-NWLOPQT7.js → chunk-MOEZ43ZL.js} +1 -1
- package/dist/mcp-chunks/{chunk-AFKE4BTR.js → chunk-NTHUNCXJ.js} +21 -21
- package/dist/mcp-chunks/{chunk-J3J3NQ4X.js → chunk-OD3MSMXY.js} +1 -1
- package/dist/mcp-chunks/{chunk-PRZCYXVO.js → chunk-OP3IW2V6.js} +2 -2
- package/dist/mcp-chunks/{chunk-K56RW4HB.js → chunk-PZ323CXI.js} +1 -1
- package/dist/mcp-chunks/{chunk-US57PK4B.js → chunk-QZUC2T72.js} +59 -4
- package/dist/mcp-chunks/{chunk-Z7O6NF7X.js → chunk-RD7NHCRK.js} +19 -19
- package/dist/mcp-chunks/{chunk-756YH7S4.js → chunk-RSTKSBVF.js} +2 -2
- package/dist/mcp-chunks/{chunk-6DL2C6V5.js → chunk-SCOMDV54.js} +1 -1
- package/dist/mcp-chunks/{chunk-SAK5KCLR.js → chunk-SNKXMWDB.js} +1 -1
- package/dist/mcp-chunks/{chunk-LC2CCTQN.js → chunk-TF2YTYE4.js} +1 -1
- package/dist/mcp-chunks/chunk-TPHPAEDH.js +3769 -0
- package/dist/mcp-chunks/{chunk-AF74TOWM.js → chunk-V5AYEKSL.js} +5 -5
- package/dist/mcp-chunks/{chunk-HBDCHBJP.js → chunk-WTMJMM3B.js} +12 -1
- package/dist/mcp-chunks/{chunk-ZZSD2JT7.js → chunk-WYLHHXI6.js} +1 -1
- package/dist/mcp-chunks/{chunk-MFFE5QSH.js → chunk-Y3EDWN2P.js} +1 -1
- package/dist/mcp-chunks/{chunk-ZRZ7C6L3.js → chunk-YIRGLKDA.js} +8 -8
- package/dist/mcp-chunks/{chunk-RE4EVQNC.js → chunk-ZOAQDFAO.js} +62 -7
- package/dist/mcp-chunks/{cli-B7WQQUME.js → cli-XU26MUCN.js} +67 -67
- package/dist/mcp-chunks/client-OT34CKRH.js +21 -0
- package/dist/mcp-chunks/{config-command-FF3JPMOP.js → config-command-UQMMIK2U.js} +37 -30
- package/dist/mcp-chunks/daemon-command-YCIOZGPZ.js +35 -0
- package/dist/mcp-chunks/{dist-V4UB7RTR.js → dist-DM2RXZMU.js} +47 -44
- package/dist/mcp-chunks/{emit-ts-command-4X56IZ32.js → emit-ts-command-KAOL6DAN.js} +16 -16
- package/dist/mcp-chunks/{generate-cli-runner-MIPF73SJ.js → generate-cli-runner-AK6XNRTK.js} +70 -50
- package/dist/mcp-chunks/{inspect-cli-command-GX54ZXKR.js → inspect-cli-command-6FVJO7H2.js} +10 -10
- package/dist/mcp-chunks/{launch-E2LWGPZS.js → launch-EIT73HX4.js} +1 -1
- package/dist/mcp-chunks/{lifecycle-TONHXXXJ.js → lifecycle-QH4TUI3K.js} +1 -1
- package/dist/mcp-chunks/{list-command-YUGRZO4G.js → list-command-UOB2XZK7.js} +30 -30
- package/dist/mcp-chunks/{output-utils-AZY6N2VQ.js → output-utils-6YXH23T7.js} +3 -3
- package/dist/mcp-chunks/{prompt-CH6TK0bC-NSBYYJZH.js → prompt-CH6TK0bC-ZB6RFAXR.js} +1 -1
- package/dist/mcp-chunks/{record-command-25DLELA2.js → record-command-FO5TTERC.js} +5 -5
- package/dist/mcp-chunks/{replay-command-6SLDG6PC.js → replay-command-SCBPCGQ7.js} +6 -6
- package/dist/mcp-chunks/{resource-command-YVOB4JCU.js → resource-command-S2J7XEMV.js} +10 -10
- package/dist/mcp-chunks/{result-utils-ZXB5DM36.js → result-utils-OME6HGS6.js} +4 -4
- package/dist/mcp-chunks/runtime-QIPMLIJI.js +39 -0
- package/dist/mcp-chunks/runtime-wrapper-X4YFKMJI.js +16 -0
- package/dist/mcp-chunks/{serve-command-QYGM2AMB.js → serve-command-DDBZZSG6.js} +28 -28
- package/dist/mcp-chunks/{timeouts-P3TBB3AX.js → timeouts-HNGNKDQN.js} +3 -3
- package/dist/mcp-chunks/{vault-command-VDMPATIX.js → vault-command-TJZYS3YI.js} +8 -7
- package/dist/mcp-chunks/{webapi-BLTNWSB2.js → webapi-4GWO2UBA.js} +887 -703
- package/dist/mcp-daemon.js +31 -31
- package/dist/mcp-run-worker.js +31 -31
- package/dist/recipe-package.d.ts +4 -2
- package/dist/recipe-package.d.ts.map +1 -1
- package/dist/recipe-package.js +31 -18
- package/dist/recipe-package.js.map +1 -1
- package/docs/channels.md +174 -60
- package/docs/pi-extension.md +1 -1
- package/docs/recipe-format.md +14 -9
- package/docs/slack.md +55 -59
- package/package.json +11 -11
- package/dist/mcp-chunks/call-arguments-RPXZJOXL.js +0 -15
- package/dist/mcp-chunks/chunk-7CS27CWE.js +0 -431
- package/dist/mcp-chunks/chunk-LJCZWKGJ.js +0 -372
- package/dist/mcp-chunks/chunk-Q7ESBNJG.js +0 -57
- package/dist/mcp-chunks/client-4ZHIBB67.js +0 -21
- package/dist/mcp-chunks/daemon-command-FKW6YELL.js +0 -35
- package/dist/mcp-chunks/runtime-NOWGTHZ5.js +0 -39
- package/dist/mcp-chunks/runtime-wrapper-ZZPAFQE4.js +0 -14
|
@@ -1,431 +0,0 @@
|
|
|
1
|
-
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
readJsonFile,
|
|
4
|
-
withFileLock,
|
|
5
|
-
writeJsonFile
|
|
6
|
-
} from "./chunk-ADINDBOF.js";
|
|
7
|
-
import {
|
|
8
|
-
mcporterDir
|
|
9
|
-
} from "./chunk-TGJOZDKG.js";
|
|
10
|
-
|
|
11
|
-
// node_modules/.pnpm/mcporter@0.13.7/node_modules/mcporter/dist/oauth-vault.js
|
|
12
|
-
import crypto from "node:crypto";
|
|
13
|
-
import path from "node:path";
|
|
14
|
-
|
|
15
|
-
// node_modules/.pnpm/mcporter@0.13.7/node_modules/mcporter/dist/oauth-credential-validation.js
|
|
16
|
-
function isRecord(value) {
|
|
17
|
-
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
18
|
-
}
|
|
19
|
-
function isOptionalString(record, key) {
|
|
20
|
-
return record[key] === void 0 || typeof record[key] === "string";
|
|
21
|
-
}
|
|
22
|
-
function isOptionalFiniteNumber(record, key) {
|
|
23
|
-
return record[key] === void 0 || typeof record[key] === "number" && Number.isFinite(record[key]);
|
|
24
|
-
}
|
|
25
|
-
function isStoredOAuthTokens(value) {
|
|
26
|
-
if (!isRecord(value))
|
|
27
|
-
return false;
|
|
28
|
-
return typeof value.access_token === "string" && value.access_token.length > 0 && typeof value.token_type === "string" && value.token_type.length > 0 && isOptionalString(value, "refresh_token") && isOptionalString(value, "scope") && isOptionalString(value, "issuer") && isOptionalFiniteNumber(value, "expires_in") && isOptionalFiniteNumber(value, "expires_at") && isOptionalFiniteNumber(value, "expiresAt");
|
|
29
|
-
}
|
|
30
|
-
function isStoredOAuthClientInformation(value) {
|
|
31
|
-
if (!isRecord(value))
|
|
32
|
-
return false;
|
|
33
|
-
return isOptionalString(value, "issuer");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// node_modules/.pnpm/mcporter@0.13.7/node_modules/mcporter/dist/oauth-token-generation.js
|
|
37
|
-
import { randomUUID } from "node:crypto";
|
|
38
|
-
import { isDeepStrictEqual } from "node:util";
|
|
39
|
-
var TOKEN_GENERATION_FIELD = "__mcporter_generation";
|
|
40
|
-
var CLIENT_GENERATION_FIELD = "__mcporter_client_generation";
|
|
41
|
-
function tokenGenerationOf(tokens) {
|
|
42
|
-
const generation = tokens[TOKEN_GENERATION_FIELD];
|
|
43
|
-
return typeof generation === "string" && generation.length > 0 ? generation : void 0;
|
|
44
|
-
}
|
|
45
|
-
function clientGenerationOf(info) {
|
|
46
|
-
const generation = info[CLIENT_GENERATION_FIELD];
|
|
47
|
-
return typeof generation === "string" && generation.length > 0 ? generation : void 0;
|
|
48
|
-
}
|
|
49
|
-
function withoutTokenGeneration(tokens) {
|
|
50
|
-
const copy = { ...tokens };
|
|
51
|
-
delete copy[TOKEN_GENERATION_FIELD];
|
|
52
|
-
return copy;
|
|
53
|
-
}
|
|
54
|
-
function withoutClientGeneration(info) {
|
|
55
|
-
const copy = { ...info };
|
|
56
|
-
delete copy[CLIENT_GENERATION_FIELD];
|
|
57
|
-
return copy;
|
|
58
|
-
}
|
|
59
|
-
function withOAuthTokenGeneration(tokens) {
|
|
60
|
-
const generation = tokenGenerationOf(tokens) ?? randomUUID();
|
|
61
|
-
return { ...withoutTokenGeneration(tokens), [TOKEN_GENERATION_FIELD]: generation };
|
|
62
|
-
}
|
|
63
|
-
function withHiddenOAuthTokenGeneration(tokens) {
|
|
64
|
-
const generation = tokenGenerationOf(tokens);
|
|
65
|
-
if (!generation) {
|
|
66
|
-
return tokens;
|
|
67
|
-
}
|
|
68
|
-
const copy = withoutTokenGeneration(tokens);
|
|
69
|
-
Object.defineProperty(copy, TOKEN_GENERATION_FIELD, { value: generation, enumerable: false });
|
|
70
|
-
return copy;
|
|
71
|
-
}
|
|
72
|
-
function withOAuthClientGeneration(info) {
|
|
73
|
-
const generation = clientGenerationOf(info) ?? randomUUID();
|
|
74
|
-
const copy = { ...withoutClientGeneration(info) };
|
|
75
|
-
copy[CLIENT_GENERATION_FIELD] = generation;
|
|
76
|
-
return copy;
|
|
77
|
-
}
|
|
78
|
-
function withHiddenOAuthClientGeneration(info) {
|
|
79
|
-
const generation = clientGenerationOf(info);
|
|
80
|
-
if (!generation) {
|
|
81
|
-
return info;
|
|
82
|
-
}
|
|
83
|
-
const copy = withoutClientGeneration(info);
|
|
84
|
-
Object.defineProperty(copy, CLIENT_GENERATION_FIELD, { value: generation, enumerable: false });
|
|
85
|
-
return copy;
|
|
86
|
-
}
|
|
87
|
-
function sameOAuthTokenGeneration(current, expected) {
|
|
88
|
-
if (!current) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
const currentGeneration = tokenGenerationOf(current);
|
|
92
|
-
const expectedGeneration = tokenGenerationOf(expected);
|
|
93
|
-
if (currentGeneration || expectedGeneration) {
|
|
94
|
-
return currentGeneration !== void 0 && currentGeneration === expectedGeneration && sameOAuthTokenValue(current, expected);
|
|
95
|
-
}
|
|
96
|
-
return isDeepStrictEqual(current, expected);
|
|
97
|
-
}
|
|
98
|
-
function sameOAuthTokenValue(left, right) {
|
|
99
|
-
return isDeepStrictEqual(withoutTokenGeneration(left), withoutTokenGeneration(right));
|
|
100
|
-
}
|
|
101
|
-
function sameOAuthClientGeneration(current, expected) {
|
|
102
|
-
if (!current) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
const currentGeneration = clientGenerationOf(current);
|
|
106
|
-
const expectedGeneration = clientGenerationOf(expected);
|
|
107
|
-
if (currentGeneration || expectedGeneration) {
|
|
108
|
-
return currentGeneration !== void 0 && currentGeneration === expectedGeneration && sameOAuthClientValue(current, expected);
|
|
109
|
-
}
|
|
110
|
-
return isDeepStrictEqual(current, expected);
|
|
111
|
-
}
|
|
112
|
-
function sameOAuthClientValue(left, right) {
|
|
113
|
-
return isDeepStrictEqual(withoutClientGeneration(left), withoutClientGeneration(right));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// node_modules/.pnpm/mcporter@0.13.7/node_modules/mcporter/dist/oauth-vault.js
|
|
117
|
-
function getOAuthVaultPath() {
|
|
118
|
-
return path.join(mcporterDir("data"), "credentials.json");
|
|
119
|
-
}
|
|
120
|
-
async function readVaultState() {
|
|
121
|
-
try {
|
|
122
|
-
const existing = await readJsonFile(getOAuthVaultPath());
|
|
123
|
-
if (existing && (existing.version === 1 || existing.version === 2) && existing.entries && typeof existing.entries === "object") {
|
|
124
|
-
return {
|
|
125
|
-
vault: { ...existing, version: 2 },
|
|
126
|
-
needsRepair: existing.version !== 2
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
if (existing !== void 0) {
|
|
130
|
-
return { vault: emptyVault(), needsRepair: true };
|
|
131
|
-
}
|
|
132
|
-
} catch (error) {
|
|
133
|
-
if (!(error instanceof SyntaxError)) {
|
|
134
|
-
throw error;
|
|
135
|
-
}
|
|
136
|
-
return { vault: emptyVault(), needsRepair: true };
|
|
137
|
-
}
|
|
138
|
-
return { vault: emptyVault(), needsRepair: false };
|
|
139
|
-
}
|
|
140
|
-
async function readVault() {
|
|
141
|
-
return (await readVaultState()).vault;
|
|
142
|
-
}
|
|
143
|
-
function emptyVault() {
|
|
144
|
-
return { version: 2, entries: {} };
|
|
145
|
-
}
|
|
146
|
-
async function writeVault(contents) {
|
|
147
|
-
await writeJsonFile(getOAuthVaultPath(), contents);
|
|
148
|
-
}
|
|
149
|
-
function vaultKeyForDefinition(definition) {
|
|
150
|
-
const descriptor = {
|
|
151
|
-
name: definition.name,
|
|
152
|
-
url: definition.command.kind === "http" ? definition.command.url.toString() : null,
|
|
153
|
-
command: definition.command.kind === "stdio" ? { command: definition.command.command, args: definition.command.args ?? [] } : null
|
|
154
|
-
};
|
|
155
|
-
const hash = crypto.createHash("sha256").update(JSON.stringify(descriptor)).digest("hex").slice(0, 16);
|
|
156
|
-
return `${definition.name}|${hash}`;
|
|
157
|
-
}
|
|
158
|
-
async function reconcileVaultServerUrl(definition) {
|
|
159
|
-
if (definition.command.kind !== "http") {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
const serverUrl = definition.command.url.toString();
|
|
163
|
-
await withFileLock(getOAuthVaultPath(), async () => {
|
|
164
|
-
const { vault, needsRepair } = await readVaultState();
|
|
165
|
-
const serverUrls = stringRecord(vault.serverUrls);
|
|
166
|
-
const previousUrl = serverUrls[definition.name];
|
|
167
|
-
const namedEntryUrls = Object.values(vault.entries).filter((entry) => isVaultEntry(entry) && entry.serverName === definition.name).flatMap((entry) => typeof entry.serverUrl === "string" ? [entry.serverUrl] : []);
|
|
168
|
-
const urlChanged = previousUrl !== void 0 && previousUrl !== serverUrl || namedEntryUrls.some((url) => url !== serverUrl);
|
|
169
|
-
if (urlChanged) {
|
|
170
|
-
const invalidatedUrls = new Set([serverUrl, previousUrl, ...namedEntryUrls].filter((url) => url !== void 0));
|
|
171
|
-
for (const [key, entry] of Object.entries(vault.entries)) {
|
|
172
|
-
if (isVaultEntry(entry) && (entry.serverName === definition.name || isLegacyOAuthRenameCandidate(definition, entry) && entry.serverUrl !== void 0 && invalidatedUrls.has(entry.serverUrl))) {
|
|
173
|
-
delete vault.entries[key];
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (previousUrl === serverUrl && !urlChanged && !needsRepair) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
vault.serverUrls = { ...serverUrls, [definition.name]: serverUrl };
|
|
181
|
-
await writeVault(vault);
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
function stringRecord(value) {
|
|
185
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
186
|
-
return {};
|
|
187
|
-
}
|
|
188
|
-
return Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string"));
|
|
189
|
-
}
|
|
190
|
-
async function vaultCredentialKeys(definition) {
|
|
191
|
-
const key = vaultKeyForDefinition(definition);
|
|
192
|
-
if (definition.command.kind !== "http") {
|
|
193
|
-
return [key];
|
|
194
|
-
}
|
|
195
|
-
const vault = await readVault();
|
|
196
|
-
return [.../* @__PURE__ */ new Set([key, ...legacyOAuthRenameKeys(vault, definition, key)])];
|
|
197
|
-
}
|
|
198
|
-
async function loadVaultEntryForRecovery(definition) {
|
|
199
|
-
const vault = await readVault();
|
|
200
|
-
const key = vaultKeyForDefinition(definition);
|
|
201
|
-
const resolved = resolveVaultEntry(vault, definition);
|
|
202
|
-
const tokenSnapshots = /* @__PURE__ */ new Map();
|
|
203
|
-
const clientSnapshots = /* @__PURE__ */ new Map();
|
|
204
|
-
for (const targetKey of [key, ...legacyOAuthRenameKeys(vault, definition, key)]) {
|
|
205
|
-
const candidate = isVaultEntry(vault.entries[targetKey]) ? vault.entries[targetKey] : void 0;
|
|
206
|
-
if (candidate?.tokens && resolved?.tokens && sameOAuthTokenValue(candidate.tokens, resolved.tokens)) {
|
|
207
|
-
tokenSnapshots.set(targetKey, candidate.tokens);
|
|
208
|
-
}
|
|
209
|
-
if (candidate?.clientInfo && resolved?.clientInfo && sameOAuthClientValue(candidate.clientInfo, resolved.clientInfo)) {
|
|
210
|
-
clientSnapshots.set(targetKey, candidate.clientInfo);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
return {
|
|
214
|
-
entry: externalVaultEntry(resolved),
|
|
215
|
-
tokenSnapshots,
|
|
216
|
-
clientSnapshots
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
function resolveVaultEntry(vault, definition) {
|
|
220
|
-
const key = vaultKeyForDefinition(definition);
|
|
221
|
-
const exact = isVaultEntry(vault.entries[key]) ? vault.entries[key] : void 0;
|
|
222
|
-
const fallback = findSameUrlCredentials(vault, definition, key, exact);
|
|
223
|
-
if (!fallback.tokens && !fallback.clientInfo) {
|
|
224
|
-
return exact;
|
|
225
|
-
}
|
|
226
|
-
if (!exact) {
|
|
227
|
-
return {
|
|
228
|
-
serverName: definition.name,
|
|
229
|
-
serverUrl: definition.command.kind === "http" ? definition.command.url.toString() : void 0,
|
|
230
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
231
|
-
tokens: fallback.tokens,
|
|
232
|
-
clientInfo: fallback.clientInfo
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
return {
|
|
236
|
-
...exact,
|
|
237
|
-
tokens: exact.tokens ?? fallback.tokens,
|
|
238
|
-
clientInfo: exact.clientInfo ?? (exact.tokens ? void 0 : fallback.clientInfo)
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
function externalVaultEntry(entry) {
|
|
242
|
-
if (!entry) {
|
|
243
|
-
return entry;
|
|
244
|
-
}
|
|
245
|
-
const { tokens, clientInfo, ...metadata } = entry;
|
|
246
|
-
return {
|
|
247
|
-
...metadata,
|
|
248
|
-
...isStoredOAuthTokens(tokens) ? { tokens: withHiddenOAuthTokenGeneration(tokens) } : {},
|
|
249
|
-
...isStoredOAuthClientInformation(clientInfo) ? { clientInfo: withHiddenOAuthClientGeneration(clientInfo) } : {}
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
function findSameUrlCredentials(vault, definition, exactKey, exact) {
|
|
253
|
-
if (definition.command.kind !== "http") {
|
|
254
|
-
return { sourceKeys: [] };
|
|
255
|
-
}
|
|
256
|
-
const serverUrl = definition.command.url.toString();
|
|
257
|
-
const candidates = Object.entries(vault.entries).filter(([key, entry]) => key !== exactKey && isVaultEntry(entry) && entry.serverUrl === serverUrl && isLegacyOAuthRenameCandidate(definition, entry) && (entry.tokens || entry.clientInfo)).map(([key, entry]) => ({ key, entry })).toSorted((a, b) => Date.parse(b.entry.updatedAt) - Date.parse(a.entry.updatedAt));
|
|
258
|
-
const requiredClientId = definition.oauthClientId ?? clientIdFromEntry(exact);
|
|
259
|
-
if (requiredClientId) {
|
|
260
|
-
const tokenSource = candidates.find(({ entry }) => (entry.tokens || entry.clientInfo) && clientIdFromEntry(entry) === requiredClientId);
|
|
261
|
-
return {
|
|
262
|
-
tokens: tokenSource?.entry.tokens,
|
|
263
|
-
clientInfo: exact?.clientInfo ? void 0 : tokenSource?.entry.clientInfo,
|
|
264
|
-
sourceKeys: tokenSource ? [tokenSource.key] : []
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
const source = candidates.find(({ entry }) => entry.clientInfo && clientIdFromEntry(entry));
|
|
268
|
-
return {
|
|
269
|
-
tokens: source?.entry.tokens,
|
|
270
|
-
clientInfo: source?.entry.clientInfo,
|
|
271
|
-
sourceKeys: source ? [source.key] : []
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
function isLegacyOAuthRenameCandidate(definition, entry) {
|
|
275
|
-
return entry.serverName === `${definition.name}-oauth`;
|
|
276
|
-
}
|
|
277
|
-
function legacyOAuthRenameKeys(vault, definition, exactKey) {
|
|
278
|
-
if (definition.command.kind !== "http") {
|
|
279
|
-
return [];
|
|
280
|
-
}
|
|
281
|
-
const serverUrl = definition.command.url.toString();
|
|
282
|
-
return Object.entries(vault.entries).filter(([key, entry]) => key !== exactKey && isVaultEntry(entry) && entry.serverUrl === serverUrl && isLegacyOAuthRenameCandidate(definition, entry)).map(([key]) => key);
|
|
283
|
-
}
|
|
284
|
-
function isVaultEntry(entry) {
|
|
285
|
-
return Boolean(entry && typeof entry === "object" && typeof entry.serverName === "string" && typeof entry.updatedAt === "string");
|
|
286
|
-
}
|
|
287
|
-
function clientIdFromEntry(entry) {
|
|
288
|
-
const clientId = entry?.clientInfo?.client_id;
|
|
289
|
-
return typeof clientId === "string" && clientId.length > 0 ? clientId : void 0;
|
|
290
|
-
}
|
|
291
|
-
async function saveVaultEntry(definition, patch) {
|
|
292
|
-
await withFileLock(getOAuthVaultPath(), async () => {
|
|
293
|
-
const vault = await readVault();
|
|
294
|
-
const key = vaultKeyForDefinition(definition);
|
|
295
|
-
const existing = isVaultEntry(vault.entries[key]) ? vault.entries[key] : void 0;
|
|
296
|
-
const fallback = findSameUrlCredentials(vault, definition, key, existing);
|
|
297
|
-
const current = existing ?? {
|
|
298
|
-
serverName: definition.name,
|
|
299
|
-
serverUrl: definition.command.kind === "http" ? definition.command.url.toString() : void 0,
|
|
300
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
301
|
-
};
|
|
302
|
-
vault.entries[key] = {
|
|
303
|
-
...current,
|
|
304
|
-
...patch,
|
|
305
|
-
...patch.tokens ? { tokens: withOAuthTokenGeneration(patch.tokens) } : {},
|
|
306
|
-
clientInfo: (patch.clientInfo ? withOAuthClientGeneration(patch.clientInfo) : void 0) ?? current.clientInfo ?? (patch.tokens && !current.tokens ? fallback.clientInfo : void 0),
|
|
307
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
308
|
-
};
|
|
309
|
-
await writeVault(vault);
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
function tokensMatch(tokens, expected) {
|
|
313
|
-
return expected !== void 0 && sameOAuthTokenGeneration(tokens, expected);
|
|
314
|
-
}
|
|
315
|
-
async function clearVaultTokensIfMatching(definition, expectedTokens, expectedClientInfo, tokenSnapshots, clientSnapshots) {
|
|
316
|
-
const key = vaultKeyForDefinition(definition);
|
|
317
|
-
await withFileLock(getOAuthVaultPath(), async () => {
|
|
318
|
-
const { vault, needsRepair } = await readVaultState();
|
|
319
|
-
const exact = isVaultEntry(vault.entries[key]) ? vault.entries[key] : void 0;
|
|
320
|
-
const fallbackKeys = findSameUrlCredentials(vault, definition, key, exact).sourceKeys;
|
|
321
|
-
const targetKeys = tokenSnapshots || clientSnapshots ? [.../* @__PURE__ */ new Set([...tokenSnapshots?.keys() ?? [], ...clientSnapshots?.keys() ?? []])] : [key, ...fallbackKeys];
|
|
322
|
-
let mutated = false;
|
|
323
|
-
for (const targetKey of targetKeys) {
|
|
324
|
-
const entry = isVaultEntry(vault.entries[targetKey]) ? vault.entries[targetKey] : void 0;
|
|
325
|
-
if (!entry) {
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
const updated = { ...entry };
|
|
329
|
-
let entryMutated = false;
|
|
330
|
-
const tokenSnapshot = tokenSnapshots ? tokenSnapshots.get(targetKey) : expectedTokens;
|
|
331
|
-
const clientSnapshot = clientSnapshots ? clientSnapshots.get(targetKey) : expectedClientInfo;
|
|
332
|
-
const ownTokensRejected = tokensMatch(entry.tokens, tokenSnapshot);
|
|
333
|
-
if (ownTokensRejected) {
|
|
334
|
-
delete updated.tokens;
|
|
335
|
-
entryMutated = true;
|
|
336
|
-
}
|
|
337
|
-
if (clientSnapshot && sameOAuthClientGeneration(updated.clientInfo, clientSnapshot)) {
|
|
338
|
-
delete updated.clientInfo;
|
|
339
|
-
entryMutated = true;
|
|
340
|
-
}
|
|
341
|
-
if (!entryMutated) {
|
|
342
|
-
continue;
|
|
343
|
-
}
|
|
344
|
-
updated.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
345
|
-
vault.entries[targetKey] = updated;
|
|
346
|
-
mutated = true;
|
|
347
|
-
}
|
|
348
|
-
if (mutated || needsRepair) {
|
|
349
|
-
await writeVault(vault);
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
async function clearVaultEntry(definition, scope) {
|
|
354
|
-
const key = vaultKeyForDefinition(definition);
|
|
355
|
-
await withFileLock(getOAuthVaultPath(), async () => {
|
|
356
|
-
const { vault, needsRepair } = await readVaultState();
|
|
357
|
-
const existing = isVaultEntry(vault.entries[key]) ? vault.entries[key] : void 0;
|
|
358
|
-
const fallback = findSameUrlCredentials(vault, definition, key, existing);
|
|
359
|
-
const inheritedKeys = scope === "all" ? legacyOAuthRenameKeys(vault, definition, key) : fallback.sourceKeys;
|
|
360
|
-
if (!existing && inheritedKeys.length === 0) {
|
|
361
|
-
if (needsRepair) {
|
|
362
|
-
await writeVault(vault);
|
|
363
|
-
}
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
366
|
-
if (scope === "all") {
|
|
367
|
-
delete vault.entries[key];
|
|
368
|
-
} else if (existing) {
|
|
369
|
-
const updated = { ...existing };
|
|
370
|
-
if (scope === "tokens") {
|
|
371
|
-
delete updated.tokens;
|
|
372
|
-
}
|
|
373
|
-
if (scope === "client") {
|
|
374
|
-
delete updated.clientInfo;
|
|
375
|
-
}
|
|
376
|
-
if (scope === "verifier") {
|
|
377
|
-
delete updated.codeVerifier;
|
|
378
|
-
}
|
|
379
|
-
if (scope === "state") {
|
|
380
|
-
delete updated.state;
|
|
381
|
-
}
|
|
382
|
-
if (scope === "discovery") {
|
|
383
|
-
delete updated.discoveryState;
|
|
384
|
-
delete updated.authorizationServerUrl;
|
|
385
|
-
delete updated.resourceUrl;
|
|
386
|
-
}
|
|
387
|
-
updated.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
388
|
-
vault.entries[key] = updated;
|
|
389
|
-
}
|
|
390
|
-
for (const fallbackKey of inheritedKeys) {
|
|
391
|
-
const inherited = vault.entries[fallbackKey];
|
|
392
|
-
if (!inherited) {
|
|
393
|
-
continue;
|
|
394
|
-
}
|
|
395
|
-
if (scope === "all") {
|
|
396
|
-
delete vault.entries[fallbackKey];
|
|
397
|
-
continue;
|
|
398
|
-
}
|
|
399
|
-
const updated = { ...inherited };
|
|
400
|
-
if (scope === "tokens") {
|
|
401
|
-
delete updated.tokens;
|
|
402
|
-
}
|
|
403
|
-
if (scope === "client") {
|
|
404
|
-
delete updated.clientInfo;
|
|
405
|
-
}
|
|
406
|
-
updated.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
407
|
-
vault.entries[fallbackKey] = updated;
|
|
408
|
-
}
|
|
409
|
-
await writeVault(vault);
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
export {
|
|
414
|
-
isStoredOAuthTokens,
|
|
415
|
-
isStoredOAuthClientInformation,
|
|
416
|
-
withOAuthTokenGeneration,
|
|
417
|
-
withHiddenOAuthTokenGeneration,
|
|
418
|
-
withOAuthClientGeneration,
|
|
419
|
-
withHiddenOAuthClientGeneration,
|
|
420
|
-
sameOAuthTokenGeneration,
|
|
421
|
-
sameOAuthTokenValue,
|
|
422
|
-
sameOAuthClientGeneration,
|
|
423
|
-
sameOAuthClientValue,
|
|
424
|
-
getOAuthVaultPath,
|
|
425
|
-
reconcileVaultServerUrl,
|
|
426
|
-
vaultCredentialKeys,
|
|
427
|
-
loadVaultEntryForRecovery,
|
|
428
|
-
saveVaultEntry,
|
|
429
|
-
clearVaultTokensIfMatching,
|
|
430
|
-
clearVaultEntry
|
|
431
|
-
};
|