crossroom 0.2.0 → 0.3.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 +23 -1
- package/dist/THIRD-PARTY-NOTICES.md +535 -0
- package/dist/chunk-7CTZAMHT.mjs +24392 -0
- package/dist/{chunk-27AE3JXP.mjs → chunk-GWFVXAVQ.mjs} +882 -69
- package/dist/{chunk-KYENX3H2.mjs → chunk-J4QPGWFS.mjs} +6 -6
- package/dist/chunk-KJTOBYEN.mjs +157 -0
- package/dist/{chunk-7TMIKS73.mjs → chunk-NAX7L4WR.mjs} +1 -1
- package/dist/chunk-NXBBMDR5.mjs +20 -0
- package/dist/{chunk-B22BPJRW.mjs → chunk-O3GNP4DR.mjs} +6 -1
- package/dist/chunk-PN2OQIQ5.mjs +157 -0
- package/dist/chunk-UYXRRLXZ.mjs +98 -0
- package/dist/{client-W2UXM3DQ.mjs → chunk-ZJ3UBXDU.mjs} +30752 -44003
- package/dist/{cli-CLTH3KTD.mjs → cli-DIMNWMDE.mjs} +14 -2
- package/dist/client-VOJ62D5R.mjs +17086 -0
- package/dist/{client-version-4NABXCVX.mjs → client-version-2BE42C46.mjs} +13 -1
- package/dist/crossroom.mjs +1 -1
- package/dist/{discovery-H337C4SR.mjs → discovery-EZAQSANW.mjs} +1 -1
- package/dist/{keep-in-account-TEFSINNC.mjs → keep-in-account-MEAE6BNO.mjs} +10 -8
- package/dist/{local-agent-LIALQD2F.mjs → local-agent-JSROJL7Y.mjs} +3 -3
- package/dist/{memory-notes-I2YVP6WP.mjs → memory-notes-7U7YO23S.mjs} +3 -3
- package/dist/node-CRLXXXMX.mjs +2258 -0
- package/dist/node-LUE5WS4G.mjs +20 -0
- package/dist/{relay-call-BPLNQ7JZ.mjs → relay-call-DKXVPYE4.mjs} +5 -4
- package/dist/sdk-P6RTMO2C.mjs +49 -0
- package/dist/wait-DMXS3HDV.mjs +21 -0
- package/package.json +6 -1
- package/dist/chunk-IU22ASGZ.mjs +0 -82
- package/dist/chunk-IX24JXWC.mjs +0 -219
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { createRequire as __parleyRequire } from 'node:module'; const require = __parleyRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
insideLocation,
|
|
4
|
+
sameLocation
|
|
5
|
+
} from "./chunk-5TLKYAI3.mjs";
|
|
2
6
|
import {
|
|
3
7
|
LOCAL_COPY_HEADER,
|
|
4
8
|
dataDir,
|
|
5
9
|
savedRooms,
|
|
6
10
|
searchItems,
|
|
7
11
|
searchTerms
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import {
|
|
10
|
-
insideLocation,
|
|
11
|
-
sameLocation
|
|
12
|
-
} from "./chunk-5TLKYAI3.mjs";
|
|
12
|
+
} from "./chunk-GWFVXAVQ.mjs";
|
|
13
13
|
import {
|
|
14
14
|
oneLine,
|
|
15
15
|
slotLetter
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-O3GNP4DR.mjs";
|
|
17
17
|
|
|
18
18
|
// src/commands/memory-notes.ts
|
|
19
19
|
import { randomBytes } from "node:crypto";
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { createRequire as __parleyRequire } from 'node:module'; const require = __parleyRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/client-version.ts
|
|
4
|
+
import { mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
var CHECK_EVERY_MS = 24 * 60 * 60 * 1e3;
|
|
7
|
+
var CHECK_TIMEOUT_MS = 2e3;
|
|
8
|
+
var RETRY_AFTER_FAILURE_MS = 60 * 60 * 1e3;
|
|
9
|
+
var noted = /* @__PURE__ */ new Set();
|
|
10
|
+
function noteInstance(base) {
|
|
11
|
+
try {
|
|
12
|
+
noted.add(new URL(base).origin);
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
var notedInstances = () => [...noted];
|
|
17
|
+
var VERSION_SHAPE = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
|
|
18
|
+
function versionParts(v) {
|
|
19
|
+
const m = VERSION_SHAPE.exec(v.trim());
|
|
20
|
+
return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
|
|
21
|
+
}
|
|
22
|
+
function isPrerelease(v) {
|
|
23
|
+
return Boolean(VERSION_SHAPE.exec(v.trim())?.[4]);
|
|
24
|
+
}
|
|
25
|
+
function olderThan(have, min) {
|
|
26
|
+
const a = versionParts(have);
|
|
27
|
+
const b = versionParts(min);
|
|
28
|
+
if (!a || !b) return false;
|
|
29
|
+
for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] < b[i];
|
|
30
|
+
return isPrerelease(have) && !isPrerelease(min);
|
|
31
|
+
}
|
|
32
|
+
function realScript(script) {
|
|
33
|
+
if (!script) return null;
|
|
34
|
+
try {
|
|
35
|
+
return realpathSync(script).replace(/\\/g, "/");
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function checkoutOf(real) {
|
|
41
|
+
if (real.includes("/node_modules/")) return null;
|
|
42
|
+
const pkgDir = path.dirname(path.dirname(real));
|
|
43
|
+
if (path.basename(path.dirname(real)) !== "dist") return null;
|
|
44
|
+
try {
|
|
45
|
+
const pkg = JSON.parse(readFileSync(path.join(pkgDir, "package.json"), "utf8"));
|
|
46
|
+
if (pkg.name !== "crossroom" || !statSync(path.join(pkgDir, "src")).isDirectory()) return null;
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return { pkgDir, root: path.resolve(pkgDir, "..", "..") };
|
|
51
|
+
}
|
|
52
|
+
function installKind(script = process.argv[1]) {
|
|
53
|
+
const real = realScript(script);
|
|
54
|
+
if (!real) return "unknown";
|
|
55
|
+
if (real.includes("/_npx/")) return "npx";
|
|
56
|
+
if (/\/(Cellar|homebrew|linuxbrew)\//i.test(real)) return "brew";
|
|
57
|
+
if (real.includes("/node_modules/crossroom/")) return "npm";
|
|
58
|
+
if (checkoutOf(real)) return "checkout";
|
|
59
|
+
return "unknown";
|
|
60
|
+
}
|
|
61
|
+
function updateHint(version, script = process.argv[1]) {
|
|
62
|
+
const tag = isPrerelease(version) ? "crossroom@beta" : "crossroom";
|
|
63
|
+
switch (installKind(script)) {
|
|
64
|
+
case "npx":
|
|
65
|
+
return `Run the newest with: npx ${isPrerelease(version) ? tag : "crossroom@latest"}`;
|
|
66
|
+
case "brew":
|
|
67
|
+
return "Update with: brew upgrade crossroom";
|
|
68
|
+
case "checkout": {
|
|
69
|
+
const at = checkoutOf(realScript(script) ?? "");
|
|
70
|
+
return `Update the checkout it runs from with git pull, then rebuild: ${rebuildCommand(at?.root ?? "<checkout>")}`;
|
|
71
|
+
}
|
|
72
|
+
default:
|
|
73
|
+
return `Update with: npm install -g ${tag}`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function rebuildCommand(root) {
|
|
77
|
+
return `pnpm -C ${/\s/.test(root) ? `"${root}"` : root} --filter crossroom build`;
|
|
78
|
+
}
|
|
79
|
+
function staleBuild(version, script = process.argv[1]) {
|
|
80
|
+
if (!versionParts(version)) return null;
|
|
81
|
+
const real = realScript(script);
|
|
82
|
+
const at = real ? checkoutOf(real) : null;
|
|
83
|
+
if (!at) return null;
|
|
84
|
+
let source;
|
|
85
|
+
try {
|
|
86
|
+
source = JSON.parse(readFileSync(path.join(at.pkgDir, "package.json"), "utf8")).version;
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
if (typeof source !== "string" || source === version) return null;
|
|
91
|
+
return { built: version, source, rebuild: rebuildCommand(at.root) };
|
|
92
|
+
}
|
|
93
|
+
function staleBuildLine(stale) {
|
|
94
|
+
return `This crossroom was built as ${stale.built}; its checkout is now ${stale.source}. Rebuild it with: ${stale.rebuild}`;
|
|
95
|
+
}
|
|
96
|
+
function readSeen(file) {
|
|
97
|
+
try {
|
|
98
|
+
const v = JSON.parse(readFileSync(file, "utf8"));
|
|
99
|
+
return v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
100
|
+
} catch {
|
|
101
|
+
return {};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function warnIfOutdated(o) {
|
|
105
|
+
if (!noted.size || !versionParts(o.version) || process.env.CROSSROOM_NO_VERSION_CHECK === "1") return;
|
|
106
|
+
const file = path.join(o.dataDir, "client-check.json");
|
|
107
|
+
const now = (o.now ?? Date.now)();
|
|
108
|
+
const seen = readSeen(file);
|
|
109
|
+
let changed = false;
|
|
110
|
+
for (const origin of noted) {
|
|
111
|
+
let entry = seen[origin];
|
|
112
|
+
const stale = !entry?.at || now - entry.at > CHECK_EVERY_MS;
|
|
113
|
+
const resting = typeof entry?.failedAt === "number" && now - entry.failedAt >= 0 && now - entry.failedAt < RETRY_AFTER_FAILURE_MS;
|
|
114
|
+
if (stale && !resting) {
|
|
115
|
+
const min = await readMin(origin, o.fetch ?? fetch);
|
|
116
|
+
entry = min === void 0 ? { at: entry?.at ?? 0, min: entry?.min ?? null, failedAt: now } : { at: now, min };
|
|
117
|
+
seen[origin] = entry;
|
|
118
|
+
changed = true;
|
|
119
|
+
}
|
|
120
|
+
if (entry?.min && olderThan(o.version, entry.min))
|
|
121
|
+
o.say(`This crossroom is ${o.version}; ${new URL(origin).host} supports ${entry.min} and newer. ${updateHint(o.version, o.script)}`);
|
|
122
|
+
}
|
|
123
|
+
if (changed) {
|
|
124
|
+
try {
|
|
125
|
+
mkdirSync(o.dataDir, { recursive: true });
|
|
126
|
+
writeFileSync(file, `${JSON.stringify(seen, null, 2)}
|
|
127
|
+
`);
|
|
128
|
+
} catch {
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function readMin(origin, f) {
|
|
133
|
+
try {
|
|
134
|
+
const res = await f(`${origin}/api/features`, { headers: { accept: "application/json" }, redirect: "error", signal: AbortSignal.timeout(CHECK_TIMEOUT_MS) });
|
|
135
|
+
if (!res.ok) return void 0;
|
|
136
|
+
const body = await res.json();
|
|
137
|
+
const min = body?.client?.min;
|
|
138
|
+
return typeof min === "string" && versionParts(min) ? min : null;
|
|
139
|
+
} catch {
|
|
140
|
+
return void 0;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export {
|
|
145
|
+
CHECK_EVERY_MS,
|
|
146
|
+
RETRY_AFTER_FAILURE_MS,
|
|
147
|
+
noteInstance,
|
|
148
|
+
notedInstances,
|
|
149
|
+
versionParts,
|
|
150
|
+
isPrerelease,
|
|
151
|
+
olderThan,
|
|
152
|
+
installKind,
|
|
153
|
+
updateHint,
|
|
154
|
+
staleBuild,
|
|
155
|
+
staleBuildLine,
|
|
156
|
+
warnIfOutdated
|
|
157
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createRequire as __parleyRequire } from 'node:module'; const require = __parleyRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// ../../node_modules/.pnpm/@anthropic-ai+sdk@1.3.0_zod@4.6.7/node_modules/@anthropic-ai/sdk/internal/node.mjs
|
|
4
|
+
import * as child_process from "node:child_process";
|
|
5
|
+
import * as crypto from "node:crypto";
|
|
6
|
+
import * as fs from "node:fs";
|
|
7
|
+
import * as os from "node:os";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
import * as stream from "node:stream";
|
|
10
|
+
import * as util from "node:util";
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
child_process,
|
|
14
|
+
crypto,
|
|
15
|
+
fs,
|
|
16
|
+
os,
|
|
17
|
+
path,
|
|
18
|
+
stream,
|
|
19
|
+
util
|
|
20
|
+
};
|
|
@@ -54,7 +54,7 @@ function sourceCheckPhrase(c) {
|
|
|
54
54
|
return c.files > 1 ? "the cited files are not in the sender's directory" : "the cited file is not in the sender's directory";
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
var RUNNER_LABELS = { claude: "Claude Code", codex: "Codex", agy: "Antigravity", grok: "Grok" };
|
|
57
|
+
var RUNNER_LABELS = { claude: "Claude Code", codex: "Codex", agy: "Antigravity", grok: "Grok", api: "Crossroom's agent" };
|
|
58
58
|
var SLOT_LETTERS = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"];
|
|
59
59
|
var slotLetter = (slot) => SLOT_LETTERS[slot] ?? String(slot);
|
|
60
60
|
var ROOM_SEATS_LIMIT = SLOT_LETTERS.length;
|
|
@@ -20203,6 +20203,7 @@ export {
|
|
|
20203
20203
|
normalizeParams,
|
|
20204
20204
|
own,
|
|
20205
20205
|
installLazyProp,
|
|
20206
|
+
NEVER,
|
|
20206
20207
|
$constructor,
|
|
20207
20208
|
parse,
|
|
20208
20209
|
parseAsync,
|
|
@@ -20212,9 +20213,11 @@ export {
|
|
|
20212
20213
|
$ZodObject,
|
|
20213
20214
|
toJSONSchema,
|
|
20214
20215
|
string2 as string,
|
|
20216
|
+
url,
|
|
20215
20217
|
number2 as number,
|
|
20216
20218
|
boolean2 as boolean,
|
|
20217
20219
|
_null3 as _null,
|
|
20220
|
+
any,
|
|
20218
20221
|
unknown,
|
|
20219
20222
|
array,
|
|
20220
20223
|
object,
|
|
@@ -20229,7 +20232,9 @@ export {
|
|
|
20229
20232
|
optional,
|
|
20230
20233
|
custom,
|
|
20231
20234
|
preprocess,
|
|
20235
|
+
ZodIssueCode,
|
|
20232
20236
|
iso_exports,
|
|
20237
|
+
coerce_exports,
|
|
20233
20238
|
external_exports,
|
|
20234
20239
|
writeMcpConfigFile,
|
|
20235
20240
|
withMcpConfigFile,
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { createRequire as __parleyRequire } from 'node:module'; const require = __parleyRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
API_TOKEN,
|
|
4
|
+
credentialFor,
|
|
5
|
+
credentialsPath,
|
|
6
|
+
relayOrigin
|
|
7
|
+
} from "./chunk-UYXRRLXZ.mjs";
|
|
8
|
+
import {
|
|
9
|
+
REQUEST_TIMEOUT_MS,
|
|
10
|
+
Usage,
|
|
11
|
+
text,
|
|
12
|
+
unreachableLine
|
|
13
|
+
} from "./chunk-GWFVXAVQ.mjs";
|
|
14
|
+
import {
|
|
15
|
+
DEFAULT_RELAY
|
|
16
|
+
} from "./chunk-EIMFGA2U.mjs";
|
|
17
|
+
import {
|
|
18
|
+
noteInstance
|
|
19
|
+
} from "./chunk-KJTOBYEN.mjs";
|
|
20
|
+
|
|
21
|
+
// src/reach.ts
|
|
22
|
+
var Unreachable = class extends Usage {
|
|
23
|
+
constructor(message, reason) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.reason = reason;
|
|
26
|
+
}
|
|
27
|
+
reason;
|
|
28
|
+
};
|
|
29
|
+
function timed(init, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
30
|
+
const limit = AbortSignal.timeout(timeoutMs);
|
|
31
|
+
return { ...init, signal: init.signal ? AbortSignal.any([init.signal, limit]) : limit };
|
|
32
|
+
}
|
|
33
|
+
async function reach(fetchImpl, url, init, opts = {}) {
|
|
34
|
+
try {
|
|
35
|
+
return await fetchImpl(url, timed(init, opts.timeoutMs));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
if (init.signal?.aborted) throw e;
|
|
38
|
+
const { line, reason } = unreachableLine(url, e, opts);
|
|
39
|
+
throw new Unreachable(line, reason);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/commands/relay-call.ts
|
|
44
|
+
var API_KEY_ENV = "CROSSROOM_API_KEY";
|
|
45
|
+
var URL_ENV = "CROSSROOM_URL";
|
|
46
|
+
var RelayRefused = class extends Usage {
|
|
47
|
+
constructor(message, status) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.status = status;
|
|
50
|
+
}
|
|
51
|
+
status;
|
|
52
|
+
};
|
|
53
|
+
var saidBy = (parsed, status) => typeof parsed?.error === "string" ? parsed.error : `HTTP ${status}`;
|
|
54
|
+
async function send(relay, token, fetchImpl, method, path, body, accept) {
|
|
55
|
+
const res = await reach(fetchImpl, `${relay}${path}`, {
|
|
56
|
+
method,
|
|
57
|
+
headers: { accept, authorization: `Bearer ${token}`, ...body === void 0 ? {} : { "content-type": "application/json" } },
|
|
58
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
59
|
+
redirect: "error"
|
|
60
|
+
});
|
|
61
|
+
return { res, raw: await res.text() };
|
|
62
|
+
}
|
|
63
|
+
function refusal(relay, token, res, parsed) {
|
|
64
|
+
if (res.status === 401)
|
|
65
|
+
return new RelayRefused(
|
|
66
|
+
token === envKey() ? `${relay} does not accept the key in ${API_KEY_ENV}: it was revoked, has expired, or is for another Crossroom (${URL_ENV} names the instance).` : `${relay} no longer knows this machine's sign-in. Run \`crossroom login --relay ${relay}\` again.`,
|
|
67
|
+
401
|
|
68
|
+
);
|
|
69
|
+
if (!res.ok) return new RelayRefused(`${relay} refused: ${saidBy(parsed, res.status)}`, res.status);
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
async function call(relay, token, fetchImpl, method, path, body) {
|
|
73
|
+
const { res, raw } = await send(relay, token, fetchImpl, method, path, body, "application/json");
|
|
74
|
+
let parsed = null;
|
|
75
|
+
try {
|
|
76
|
+
parsed = raw ? JSON.parse(raw) : null;
|
|
77
|
+
} catch {
|
|
78
|
+
parsed = null;
|
|
79
|
+
}
|
|
80
|
+
const refused = refusal(relay, token, res, parsed);
|
|
81
|
+
if (refused) throw refused;
|
|
82
|
+
return parsed;
|
|
83
|
+
}
|
|
84
|
+
async function callText(relay, token, fetchImpl, method, path, accept) {
|
|
85
|
+
const { res, raw } = await send(relay, token, fetchImpl, method, path, void 0, accept);
|
|
86
|
+
let parsed = null;
|
|
87
|
+
if (!res.ok) {
|
|
88
|
+
try {
|
|
89
|
+
parsed = JSON.parse(raw);
|
|
90
|
+
} catch {
|
|
91
|
+
parsed = null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const refused = refusal(relay, token, res, parsed);
|
|
95
|
+
if (refused) throw refused;
|
|
96
|
+
return raw;
|
|
97
|
+
}
|
|
98
|
+
var envKey = (env = process.env) => env[API_KEY_ENV]?.trim() || void 0;
|
|
99
|
+
var hideKeys = (s) => s.replace(/pa_[A-Za-z0-9_-]+/g, "pa_\u2026");
|
|
100
|
+
function instanceFromEnv(raw) {
|
|
101
|
+
const typed = raw.trim();
|
|
102
|
+
const shown = hideKeys(typed);
|
|
103
|
+
let u;
|
|
104
|
+
try {
|
|
105
|
+
u = new URL(typed);
|
|
106
|
+
} catch {
|
|
107
|
+
throw new Usage(`${URL_ENV} must be an instance's address, like ${DEFAULT_RELAY}; got "${shown}".`);
|
|
108
|
+
}
|
|
109
|
+
if (u.pathname !== "/" && u.pathname !== "" || u.search || u.hash)
|
|
110
|
+
throw new Usage(`${URL_ENV} must be an instance's address with no path, like ${DEFAULT_RELAY}; got "${shown}".`);
|
|
111
|
+
try {
|
|
112
|
+
return relayOrigin(u.origin);
|
|
113
|
+
} catch (e) {
|
|
114
|
+
throw new Usage(`${URL_ENV}: ${hideKeys(e.message).replace(/--relay/g, URL_ENV)}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function chosenInstance(args, fallback, env = process.env) {
|
|
118
|
+
const named = text(args.flags.relay) ?? text(args.flags.instance);
|
|
119
|
+
const url = env[URL_ENV]?.trim();
|
|
120
|
+
const base = named !== void 0 ? relayOrigin(named) : url ? instanceFromEnv(url) : relayOrigin(fallback);
|
|
121
|
+
noteInstance(base);
|
|
122
|
+
return base;
|
|
123
|
+
}
|
|
124
|
+
function accountCredential(args, env = process.env) {
|
|
125
|
+
const key = envKey(env);
|
|
126
|
+
if (key !== void 0) {
|
|
127
|
+
if (!API_TOKEN.test(key))
|
|
128
|
+
throw new Usage(`${API_KEY_ENV} is set, but not to a Crossroom API key (a key starts with pa_; make one on your account page). Nothing was sent.`);
|
|
129
|
+
return { relay: chosenInstance(args, DEFAULT_RELAY, env), token: key, via: "env" };
|
|
130
|
+
}
|
|
131
|
+
const relay = chosenInstance(args, DEFAULT_RELAY, env);
|
|
132
|
+
const held = credentialFor(relay);
|
|
133
|
+
return held ? { relay, token: held.token, via: "login" } : null;
|
|
134
|
+
}
|
|
135
|
+
function signedIn(args, env = process.env) {
|
|
136
|
+
const got = accountCredential(args, env);
|
|
137
|
+
if (got) return { relay: got.relay, token: got.token };
|
|
138
|
+
const relay = chosenInstance(args, DEFAULT_RELAY, env);
|
|
139
|
+
throw new Usage(`This machine is not signed in to ${relay}. Run \`crossroom login --relay ${relay}\` first, or set ${API_KEY_ENV} to an API key from your account page.`);
|
|
140
|
+
}
|
|
141
|
+
var credentialWhere = (c) => c.via === "env" ? `the ${API_KEY_ENV} environment variable` : credentialsPath();
|
|
142
|
+
var realFetch = (input, init) => fetch(input, init);
|
|
143
|
+
|
|
144
|
+
export {
|
|
145
|
+
reach,
|
|
146
|
+
API_KEY_ENV,
|
|
147
|
+
URL_ENV,
|
|
148
|
+
RelayRefused,
|
|
149
|
+
call,
|
|
150
|
+
callText,
|
|
151
|
+
instanceFromEnv,
|
|
152
|
+
chosenInstance,
|
|
153
|
+
accountCredential,
|
|
154
|
+
signedIn,
|
|
155
|
+
credentialWhere,
|
|
156
|
+
realFetch
|
|
157
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createRequire as __parleyRequire } from 'node:module'; const require = __parleyRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
Usage,
|
|
4
|
+
dataDir
|
|
5
|
+
} from "./chunk-GWFVXAVQ.mjs";
|
|
6
|
+
import {
|
|
7
|
+
external_exports
|
|
8
|
+
} from "./chunk-O3GNP4DR.mjs";
|
|
9
|
+
import {
|
|
10
|
+
DEFAULT_RELAY
|
|
11
|
+
} from "./chunk-EIMFGA2U.mjs";
|
|
12
|
+
|
|
13
|
+
// ../shared/src/accounts.ts
|
|
14
|
+
var AuthProvider = external_exports.enum(["github", "google", "microsoft"]);
|
|
15
|
+
var PROVIDER_LABELS = { github: "GitHub", google: "Google", microsoft: "Microsoft" };
|
|
16
|
+
var SAME_ORIGIN_PATH = /^\/(?![/\\])[A-Za-z0-9._~!$&'()*+,;=:@%/-]*(?:\?[^#\s]*)?$/;
|
|
17
|
+
var isSameOriginPath = (p) => typeof p === "string" && p.length <= 512 && SAME_ORIGIN_PATH.test(p);
|
|
18
|
+
var AuthStartQuery = external_exports.object({ return: external_exports.string().refine(isSameOriginPath, "return must be a path on this site").optional() }).strict();
|
|
19
|
+
var API_TOKEN = /^pa_[A-Za-z0-9_-]{43}$/;
|
|
20
|
+
var Plan = external_exports.enum(["free"]);
|
|
21
|
+
var RoomVia = external_exports.enum(["browser", "created", "cli"]);
|
|
22
|
+
var AccountRoomsInput = external_exports.object({ rooms: external_exports.array(external_exports.object({ id: external_exports.string().min(1).max(64), owner: external_exports.string().min(1).max(128) }).strict()).max(50) }).strict();
|
|
23
|
+
var CliApproveInput = external_exports.object({ userCode: external_exports.string().regex(/^[A-Z0-9]{4}-[A-Z0-9]{4}$/), confirm: external_exports.boolean().optional() }).strict();
|
|
24
|
+
var CliTokenInput = external_exports.object({ deviceCode: external_exports.string().min(16).max(128) }).strict();
|
|
25
|
+
var API_KEY_LABEL_MAX = 60;
|
|
26
|
+
var API_KEYS_MAX = 20;
|
|
27
|
+
var API_KEYS_FULL = `This account already has ${API_KEYS_MAX} live API keys. Revoke one you no longer use, then make a new one.`;
|
|
28
|
+
var CreateApiTokenInput = external_exports.object({ label: external_exports.string().min(1).max(API_KEY_LABEL_MAX) }).strict();
|
|
29
|
+
|
|
30
|
+
// src/commands/credentials.ts
|
|
31
|
+
import { chmodSync, closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeSync } from "node:fs";
|
|
32
|
+
import path from "node:path";
|
|
33
|
+
var credentialsPath = () => path.join(dataDir(), "credentials.json");
|
|
34
|
+
function isLoopbackHost(hostname) {
|
|
35
|
+
const h = hostname.toLowerCase();
|
|
36
|
+
return h === "localhost" || h === "[::1]" || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(h);
|
|
37
|
+
}
|
|
38
|
+
function relayOrigin(raw) {
|
|
39
|
+
const typed = raw.trim();
|
|
40
|
+
let u;
|
|
41
|
+
try {
|
|
42
|
+
u = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(typed) ? typed : `https://${typed}`);
|
|
43
|
+
} catch {
|
|
44
|
+
throw new Usage(`--relay must be a Crossroom's address, like ${DEFAULT_RELAY}; got "${raw}".`);
|
|
45
|
+
}
|
|
46
|
+
if (u.protocol !== "https:" && u.protocol !== "http:") throw new Usage(`--relay must be an https address, like ${DEFAULT_RELAY}; got "${raw}".`);
|
|
47
|
+
if (u.username || u.password) throw new Usage("--relay must not carry a user name or a password.");
|
|
48
|
+
if (u.protocol === "http:" && !isLoopbackHost(u.hostname))
|
|
49
|
+
throw new Usage(`Not signing in to ${u.origin} over plain http: the token would cross the network unencrypted. Use its https address.`);
|
|
50
|
+
return u.origin;
|
|
51
|
+
}
|
|
52
|
+
var isEntry = (v) => {
|
|
53
|
+
const e = v;
|
|
54
|
+
return !!e && typeof e === "object" && typeof e.token === "string" && API_TOKEN.test(e.token) && typeof e.accountId === "string" && typeof e.createdAt === "string";
|
|
55
|
+
};
|
|
56
|
+
function readCredentials(file = credentialsPath()) {
|
|
57
|
+
if (!existsSync(file)) return {};
|
|
58
|
+
let raw;
|
|
59
|
+
try {
|
|
60
|
+
raw = JSON.parse(readFileSync(file, "utf8"));
|
|
61
|
+
} catch {
|
|
62
|
+
raw = null;
|
|
63
|
+
}
|
|
64
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
65
|
+
throw new Usage(`${file} is not a credentials file Crossroom wrote. Move it aside, then run this again.`);
|
|
66
|
+
const out = {};
|
|
67
|
+
for (const [relay, entry] of Object.entries(raw)) if (isEntry(entry)) out[relay] = { token: entry.token, accountId: entry.accountId, createdAt: entry.createdAt };
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
function writeCredentials(creds, file = credentialsPath()) {
|
|
71
|
+
mkdirSync(path.dirname(file), { recursive: true, mode: 448 });
|
|
72
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
73
|
+
rmSync(tmp, { force: true });
|
|
74
|
+
const fd = openSync(tmp, "wx", 384);
|
|
75
|
+
try {
|
|
76
|
+
writeSync(fd, `${JSON.stringify(creds, null, 2)}
|
|
77
|
+
`);
|
|
78
|
+
} finally {
|
|
79
|
+
closeSync(fd);
|
|
80
|
+
}
|
|
81
|
+
renameSync(tmp, file);
|
|
82
|
+
if (process.platform !== "win32") chmodSync(file, 384);
|
|
83
|
+
}
|
|
84
|
+
function credentialFor(relay, file = credentialsPath()) {
|
|
85
|
+
return readCredentials(file)[relayOrigin(relay)] ?? null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export {
|
|
89
|
+
PROVIDER_LABELS,
|
|
90
|
+
isSameOriginPath,
|
|
91
|
+
API_TOKEN,
|
|
92
|
+
credentialsPath,
|
|
93
|
+
isLoopbackHost,
|
|
94
|
+
relayOrigin,
|
|
95
|
+
readCredentials,
|
|
96
|
+
writeCredentials,
|
|
97
|
+
credentialFor
|
|
98
|
+
};
|