crossroom 0.0.0-stage → 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 +111 -2
- package/dist/LICENSE +209 -0
- package/dist/THIRD-PARTY-NOTICES.md +842 -0
- package/dist/chunk-5TLKYAI3.mjs +66 -0
- package/dist/chunk-7CTZAMHT.mjs +24392 -0
- package/dist/chunk-EIMFGA2U.mjs +10 -0
- package/dist/chunk-GWFVXAVQ.mjs +5315 -0
- package/dist/chunk-J4QPGWFS.mjs +424 -0
- package/dist/chunk-KJTOBYEN.mjs +157 -0
- package/dist/chunk-NAX7L4WR.mjs +60 -0
- package/dist/chunk-NXBBMDR5.mjs +20 -0
- package/dist/chunk-O3GNP4DR.mjs +20245 -0
- package/dist/chunk-P7MSGDOB.mjs +47 -0
- package/dist/chunk-PN2OQIQ5.mjs +157 -0
- package/dist/chunk-UYXRRLXZ.mjs +98 -0
- package/dist/chunk-ZJ3UBXDU.mjs +37368 -0
- package/dist/cli-DIMNWMDE.mjs +121 -0
- package/dist/client-VOJ62D5R.mjs +17086 -0
- package/dist/client-version-2BE42C46.mjs +30 -0
- package/dist/crossroom.mjs +30 -0
- package/dist/discovery-EZAQSANW.mjs +1148 -0
- package/dist/instance-5LWNFMHX.mjs +10 -0
- package/dist/keep-in-account-MEAE6BNO.mjs +147 -0
- package/dist/local-agent-JSROJL7Y.mjs +18 -0
- package/dist/memory-notes-7U7YO23S.mjs +55 -0
- package/dist/node-CRLXXXMX.mjs +2258 -0
- package/dist/node-LUE5WS4G.mjs +20 -0
- package/dist/relay-call-DKXVPYE4.mjs +33 -0
- package/dist/sdk-P6RTMO2C.mjs +49 -0
- package/dist/wait-DMXS3HDV.mjs +21 -0
- package/package.json +53 -4
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createRequire as __parleyRequire } from 'node:module'; const require = __parleyRequire(import.meta.url);
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
+
}) : x)(function(x) {
|
|
11
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
15
|
+
try {
|
|
16
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
17
|
+
} catch (e) {
|
|
18
|
+
throw mod = 0, e;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var __export = (target, all) => {
|
|
22
|
+
for (var name in all)
|
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
|
+
};
|
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
|
+
for (let key of __getOwnPropNames(from))
|
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
34
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
35
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
36
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
37
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
38
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
39
|
+
mod
|
|
40
|
+
));
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
__require,
|
|
44
|
+
__commonJS,
|
|
45
|
+
__export,
|
|
46
|
+
__toESM
|
|
47
|
+
};
|
|
@@ -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
|
+
};
|