@tokenoftrust/cli 6.14.0 → 6.14.1
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/package.json +1 -1
- package/src/open.mjs +7 -3
- package/src/viewer-session.mjs +26 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/cli",
|
|
3
|
-
"version": "6.14.
|
|
3
|
+
"version": "6.14.1",
|
|
4
4
|
"description": "Token of Trust developer CLI — clone a tenant store, run it locally with save→reload, and submit it for preview. Installs the `tot` command.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Token of Trust",
|
package/src/open.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tiny cross-platform helpers for the "and then it just opens" moment:
|
|
3
3
|
* - openBrowser(url) — hand the URL to the OS opener (`$BROWSER`, macOS `open`,
|
|
4
|
-
* Windows `rundll32`, WSL `wslview`/`
|
|
4
|
+
* Windows `rundll32`, WSL `wslview`/`powershell.exe`, Linux `xdg-open`),
|
|
5
5
|
* detached, so `tot` doesn't babysit the browser.
|
|
6
6
|
* - waitForServer(url) — poll until the dev server answers, so we open the tab
|
|
7
7
|
* the instant the site is live (not before, not on a fixed sleep).
|
|
@@ -113,7 +113,9 @@ const cmdEscape = (url) => url.replace(/[\^&|<>()%!"]/g, "^$&");
|
|
|
113
113
|
* 1. `$BROWSER`, when set and resolvable (each `:`-separated entry; `%s` marks
|
|
114
114
|
* where the URL goes, otherwise the URL is the only argument);
|
|
115
115
|
* 2. macOS `open`; Windows `rundll32 url.dll,FileProtocolHandler`;
|
|
116
|
-
* 3. WSL: `wslview`, else `
|
|
116
|
+
* 3. WSL: `wslview`, else `powershell.exe Start-Process` (single-quoted), else
|
|
117
|
+
* `cmd.exe /c start` (escaped); never `explorer.exe`, which opens File Explorer
|
|
118
|
+
* for a long query-string URL;
|
|
117
119
|
* 4. any other Unix: `xdg-open`.
|
|
118
120
|
* @param {string} url
|
|
119
121
|
* @param {{ platform?: string, env?: NodeJS.ProcessEnv, which?: (cmd: string) => string|null, wsl?: boolean }} [opts]
|
|
@@ -142,7 +144,9 @@ export function resolveOpener(url, {
|
|
|
142
144
|
if (platform === "win32") return ["rundll32", ["url.dll,FileProtocolHandler", url]];
|
|
143
145
|
if (wsl) {
|
|
144
146
|
if (which("wslview")) return ["wslview", [url]];
|
|
145
|
-
if (which("
|
|
147
|
+
if (which("powershell.exe")) {
|
|
148
|
+
return ["powershell.exe", ["-NoProfile", "-Command", `Start-Process '${url.replaceAll("'", "''")}'`]];
|
|
149
|
+
}
|
|
146
150
|
if (which("cmd.exe")) return ["cmd.exe", ["/c", "start", '""', cmdEscape(url)]];
|
|
147
151
|
}
|
|
148
152
|
if (which("xdg-open")) return ["xdg-open", [url]];
|
package/src/viewer-session.mjs
CHANGED
|
@@ -69,6 +69,17 @@ function originOf(url) {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/** Backoff before the single retry of a transient `mcp_unreachable`. */
|
|
73
|
+
const MCP_UNREACHABLE_RETRY_MS = 750;
|
|
74
|
+
|
|
75
|
+
/** A response whose body was already read, re-exposed so the caller can read it again. */
|
|
76
|
+
const replayed = (res, body) => ({
|
|
77
|
+
ok: res.ok, status: res.status, headers: res.headers, json: async () => {
|
|
78
|
+
if (body === null) throw new SyntaxError("not json");
|
|
79
|
+
return body;
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
72
83
|
/** Exact identity issuers supported by hosted storefront sessions. */
|
|
73
84
|
export const TOKEN_OF_TRUST_MCP_ORIGINS = Object.freeze(new Set([
|
|
74
85
|
"https://mcp.tokenoftrust.com",
|
|
@@ -125,7 +136,7 @@ export function describeCliSessionRefusal(status, body, signedInMcpUrl) {
|
|
|
125
136
|
*
|
|
126
137
|
* @param {{ tenant:string, env?:NodeJS.ProcessEnv, fetchImpl?:typeof fetch,
|
|
127
138
|
* storefrontUrl?:string|null, resolveDev?:typeof resolveDeveloperSession,
|
|
128
|
-
* verbose?:boolean, log?:(s:string)=>void }} params
|
|
139
|
+
* verbose?:boolean, log?:(s:string)=>void, sleep?:(ms:number)=>Promise<void> }} params
|
|
129
140
|
* @returns {Promise<
|
|
130
141
|
* { ok:true, base:string, identity:{ account:string|null, mcp:string|null },
|
|
131
142
|
* authHeaders:Record<string,string> } |
|
|
@@ -140,6 +151,7 @@ export async function resolveViewerTransport({
|
|
|
140
151
|
resolveDev = resolveDeveloperSession,
|
|
141
152
|
verbose = false,
|
|
142
153
|
log = (s) => console.error(`[verbose] ${s}`),
|
|
154
|
+
sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
143
155
|
}) {
|
|
144
156
|
// --verbose: request URL + HTTP status + the server's error code only — NEVER
|
|
145
157
|
// the bearer token or the minted session cookie.
|
|
@@ -192,7 +204,19 @@ export async function resolveViewerTransport({
|
|
|
192
204
|
return { ok: false, message: "your selected MCP issuer isn't trusted by this store.",
|
|
193
205
|
hint: "report it with `tot feedback`; this command keeps your selected issuer." };
|
|
194
206
|
}
|
|
195
|
-
|
|
207
|
+
let mintedSession = await mintSession(base, dev.token, selectedMcp, fetchImpl, vlog);
|
|
208
|
+
// One bounded retry for a transient `mcp_unreachable` (the store's first call to the
|
|
209
|
+
// MCP right after sign-in can fail on a cold connection). Never for any other code.
|
|
210
|
+
if (mintedSession.ok && (mintedSession.response.status === 502 || mintedSession.response.status === 503)) {
|
|
211
|
+
const first = await readJson(mintedSession.response);
|
|
212
|
+
if (first?.code === "mcp_unreachable") {
|
|
213
|
+
vlog("cli-session mcp_unreachable — retrying once");
|
|
214
|
+
await sleep(MCP_UNREACHABLE_RETRY_MS);
|
|
215
|
+
mintedSession = await mintSession(base, dev.token, selectedMcp, fetchImpl, vlog);
|
|
216
|
+
} else {
|
|
217
|
+
mintedSession = { ok: true, response: { ...replayed(mintedSession.response, first) } };
|
|
218
|
+
}
|
|
219
|
+
}
|
|
196
220
|
if (!mintedSession.ok) return mintedSession.refusal;
|
|
197
221
|
const res = mintedSession.response;
|
|
198
222
|
|