@getcirrus/pds 0.11.0 → 0.13.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 +31 -0
- package/dist/cli.js +522 -101
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +146 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1237,6 +1237,79 @@ var PDSClient = class PDSClient {
|
|
|
1237
1237
|
});
|
|
1238
1238
|
}
|
|
1239
1239
|
/**
|
|
1240
|
+
* Create a new app password
|
|
1241
|
+
*/
|
|
1242
|
+
async createAppPassword(name) {
|
|
1243
|
+
const url = new URL("/xrpc/com.atproto.server.createAppPassword", this.baseUrl);
|
|
1244
|
+
const headers = { "Content-Type": "application/json" };
|
|
1245
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
1246
|
+
const res = await fetch(url.toString(), {
|
|
1247
|
+
method: "POST",
|
|
1248
|
+
headers,
|
|
1249
|
+
body: JSON.stringify({ name })
|
|
1250
|
+
});
|
|
1251
|
+
if (!res.ok) {
|
|
1252
|
+
const errorBody = await res.json().catch(() => ({}));
|
|
1253
|
+
throw new ClientResponseError({
|
|
1254
|
+
status: res.status,
|
|
1255
|
+
headers: res.headers,
|
|
1256
|
+
data: {
|
|
1257
|
+
error: errorBody.error ?? "Unknown",
|
|
1258
|
+
message: errorBody.message
|
|
1259
|
+
}
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
return res.json();
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* List all app passwords
|
|
1266
|
+
*/
|
|
1267
|
+
async listAppPasswords() {
|
|
1268
|
+
const url = new URL("/xrpc/com.atproto.server.listAppPasswords", this.baseUrl);
|
|
1269
|
+
const headers = {};
|
|
1270
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
1271
|
+
const res = await fetch(url.toString(), {
|
|
1272
|
+
method: "GET",
|
|
1273
|
+
headers
|
|
1274
|
+
});
|
|
1275
|
+
if (!res.ok) {
|
|
1276
|
+
const errorBody = await res.json().catch(() => ({}));
|
|
1277
|
+
throw new ClientResponseError({
|
|
1278
|
+
status: res.status,
|
|
1279
|
+
headers: res.headers,
|
|
1280
|
+
data: {
|
|
1281
|
+
error: errorBody.error ?? "Unknown",
|
|
1282
|
+
message: errorBody.message
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
return res.json();
|
|
1287
|
+
}
|
|
1288
|
+
/**
|
|
1289
|
+
* Revoke an app password by name
|
|
1290
|
+
*/
|
|
1291
|
+
async revokeAppPassword(name) {
|
|
1292
|
+
const url = new URL("/xrpc/com.atproto.server.revokeAppPassword", this.baseUrl);
|
|
1293
|
+
const headers = { "Content-Type": "application/json" };
|
|
1294
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
1295
|
+
const res = await fetch(url.toString(), {
|
|
1296
|
+
method: "POST",
|
|
1297
|
+
headers,
|
|
1298
|
+
body: JSON.stringify({ name })
|
|
1299
|
+
});
|
|
1300
|
+
if (!res.ok) {
|
|
1301
|
+
const errorBody = await res.json().catch(() => ({}));
|
|
1302
|
+
throw new ClientResponseError({
|
|
1303
|
+
status: res.status,
|
|
1304
|
+
headers: res.headers,
|
|
1305
|
+
data: {
|
|
1306
|
+
error: errorBody.error ?? "Unknown",
|
|
1307
|
+
message: errorBody.message
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
/**
|
|
1240
1313
|
* Initialize passkey registration
|
|
1241
1314
|
* Returns a URL for the user to visit on their device
|
|
1242
1315
|
*/
|
|
@@ -1539,11 +1612,11 @@ const addCommand = defineCommand({
|
|
|
1539
1612
|
/**
|
|
1540
1613
|
* Format a date as yyyy-mm-dd hh:mm
|
|
1541
1614
|
*/
|
|
1542
|
-
function formatDateTime(isoString) {
|
|
1615
|
+
function formatDateTime$1(isoString) {
|
|
1543
1616
|
const d = new Date(isoString);
|
|
1544
1617
|
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")} ${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`;
|
|
1545
1618
|
}
|
|
1546
|
-
const listCommand = defineCommand({
|
|
1619
|
+
const listCommand$1 = defineCommand({
|
|
1547
1620
|
meta: {
|
|
1548
1621
|
name: "list",
|
|
1549
1622
|
description: "List all registered passkeys"
|
|
@@ -1606,8 +1679,8 @@ const listCommand = defineCommand({
|
|
|
1606
1679
|
p.log.info("");
|
|
1607
1680
|
for (const pk of result.passkeys) {
|
|
1608
1681
|
const name = pk.name || pc.dim("(unnamed)");
|
|
1609
|
-
const created = formatDateTime(pk.createdAt);
|
|
1610
|
-
const lastUsed = pk.lastUsedAt ? formatDateTime(pk.lastUsedAt) : pc.dim("never");
|
|
1682
|
+
const created = formatDateTime$1(pk.createdAt);
|
|
1683
|
+
const lastUsed = pk.lastUsedAt ? formatDateTime$1(pk.lastUsedAt) : pc.dim("never");
|
|
1611
1684
|
const idPreview = pk.id.slice(0, 16) + "...";
|
|
1612
1685
|
console.log(` ${pc.green("●")} ${pc.bold(name)}`);
|
|
1613
1686
|
console.log(` ${pc.dim("ID:")} ${idPreview}`);
|
|
@@ -1755,11 +1828,336 @@ const passkeyCommand = defineCommand({
|
|
|
1755
1828
|
},
|
|
1756
1829
|
subCommands: {
|
|
1757
1830
|
add: addCommand,
|
|
1758
|
-
list: listCommand,
|
|
1831
|
+
list: listCommand$1,
|
|
1759
1832
|
remove: removeCommand
|
|
1760
1833
|
}
|
|
1761
1834
|
});
|
|
1762
1835
|
|
|
1836
|
+
//#endregion
|
|
1837
|
+
//#region src/cli/commands/app-password/create.ts
|
|
1838
|
+
/**
|
|
1839
|
+
* Create app password command
|
|
1840
|
+
*/
|
|
1841
|
+
const createCommand = defineCommand({
|
|
1842
|
+
meta: {
|
|
1843
|
+
name: "create",
|
|
1844
|
+
description: "Create a new app password"
|
|
1845
|
+
},
|
|
1846
|
+
args: {
|
|
1847
|
+
dev: {
|
|
1848
|
+
type: "boolean",
|
|
1849
|
+
description: "Target local development server instead of production",
|
|
1850
|
+
default: false
|
|
1851
|
+
},
|
|
1852
|
+
name: {
|
|
1853
|
+
type: "string",
|
|
1854
|
+
alias: "n",
|
|
1855
|
+
description: "Name for this app password (e.g., 'Graysky', 'Croissant')"
|
|
1856
|
+
}
|
|
1857
|
+
},
|
|
1858
|
+
async run({ args }) {
|
|
1859
|
+
const isDev = args.dev;
|
|
1860
|
+
p.intro("🔑 Create App Password");
|
|
1861
|
+
const vars = getVars();
|
|
1862
|
+
let targetUrl;
|
|
1863
|
+
try {
|
|
1864
|
+
targetUrl = getTargetUrl(isDev, vars.PDS_HOSTNAME);
|
|
1865
|
+
} catch (err) {
|
|
1866
|
+
p.log.error(err instanceof Error ? err.message : "Configuration error");
|
|
1867
|
+
p.log.info("Run 'pds init' first to configure your PDS.");
|
|
1868
|
+
process.exit(1);
|
|
1869
|
+
}
|
|
1870
|
+
const targetDomain = getDomain(targetUrl);
|
|
1871
|
+
const wranglerVars = getVars();
|
|
1872
|
+
const authToken = {
|
|
1873
|
+
...readDevVars(),
|
|
1874
|
+
...wranglerVars
|
|
1875
|
+
}.AUTH_TOKEN;
|
|
1876
|
+
if (!authToken) {
|
|
1877
|
+
p.log.error("No AUTH_TOKEN found. Run 'pds init' first.");
|
|
1878
|
+
p.outro("Cancelled.");
|
|
1879
|
+
process.exit(1);
|
|
1880
|
+
}
|
|
1881
|
+
let passwordName = args.name;
|
|
1882
|
+
if (!passwordName) {
|
|
1883
|
+
const nameInput = await promptText({
|
|
1884
|
+
message: "Name for this app password:",
|
|
1885
|
+
placeholder: "Graysky, Croissant, etc."
|
|
1886
|
+
});
|
|
1887
|
+
if (!nameInput) {
|
|
1888
|
+
p.cancel("Name is required.");
|
|
1889
|
+
process.exit(1);
|
|
1890
|
+
}
|
|
1891
|
+
passwordName = nameInput;
|
|
1892
|
+
}
|
|
1893
|
+
const client = new PDSClient(targetUrl, authToken);
|
|
1894
|
+
const spinner = p.spinner();
|
|
1895
|
+
spinner.start(`Checking PDS at ${targetDomain}...`);
|
|
1896
|
+
if (!await client.healthCheck()) {
|
|
1897
|
+
spinner.stop(`PDS not responding at ${targetDomain}`);
|
|
1898
|
+
p.log.error(`Your PDS isn't responding at ${targetUrl}`);
|
|
1899
|
+
p.outro("Cancelled.");
|
|
1900
|
+
process.exit(1);
|
|
1901
|
+
}
|
|
1902
|
+
spinner.stop(`Connected to ${targetDomain}`);
|
|
1903
|
+
spinner.start("Creating app password...");
|
|
1904
|
+
let result;
|
|
1905
|
+
try {
|
|
1906
|
+
result = await client.createAppPassword(passwordName);
|
|
1907
|
+
spinner.stop("App password created");
|
|
1908
|
+
} catch (err) {
|
|
1909
|
+
spinner.stop("Failed to create app password");
|
|
1910
|
+
let errorMessage = "Could not create app password";
|
|
1911
|
+
if (err instanceof Error) errorMessage = err.message;
|
|
1912
|
+
const errObj = err;
|
|
1913
|
+
if (errObj?.data?.message) errorMessage = errObj.data.message;
|
|
1914
|
+
else if (errObj?.data?.error) errorMessage = errObj.data.error;
|
|
1915
|
+
p.log.error(errorMessage);
|
|
1916
|
+
p.outro("Cancelled.");
|
|
1917
|
+
process.exit(1);
|
|
1918
|
+
}
|
|
1919
|
+
p.log.info("");
|
|
1920
|
+
p.log.success(`App password ${pc.bold(`"${result.name}"`)} created.`);
|
|
1921
|
+
p.log.info("");
|
|
1922
|
+
const copied = await copyToClipboard(result.password);
|
|
1923
|
+
p.note(result.password, "App Password");
|
|
1924
|
+
if (copied) p.log.info(pc.dim("Copied to clipboard."));
|
|
1925
|
+
p.log.warn("This password will not be shown again. Save it now.");
|
|
1926
|
+
const confirmed = await p.confirm({ message: "Have you saved the password?" });
|
|
1927
|
+
if (p.isCancel(confirmed)) {
|
|
1928
|
+
p.outro("Done! (password still visible above)");
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
const linesToClear = 6 + (copied ? 2 : 0) + 2 + 2;
|
|
1932
|
+
process.stdout.write(`\x1b[${linesToClear}A\x1b[0J`);
|
|
1933
|
+
p.note("xxxx-xxxx-xxxx-xxxx", "App Password (hidden)");
|
|
1934
|
+
p.log.info(pc.dim("Password hidden from terminal."));
|
|
1935
|
+
p.outro("Done!");
|
|
1936
|
+
}
|
|
1937
|
+
});
|
|
1938
|
+
|
|
1939
|
+
//#endregion
|
|
1940
|
+
//#region src/cli/commands/app-password/list.ts
|
|
1941
|
+
/**
|
|
1942
|
+
* List app passwords command
|
|
1943
|
+
*/
|
|
1944
|
+
/**
|
|
1945
|
+
* Format a date as yyyy-mm-dd hh:mm
|
|
1946
|
+
*/
|
|
1947
|
+
function formatDateTime(isoString) {
|
|
1948
|
+
const d = new Date(isoString);
|
|
1949
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")} ${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`;
|
|
1950
|
+
}
|
|
1951
|
+
const listCommand = defineCommand({
|
|
1952
|
+
meta: {
|
|
1953
|
+
name: "list",
|
|
1954
|
+
description: "List all app passwords"
|
|
1955
|
+
},
|
|
1956
|
+
args: { dev: {
|
|
1957
|
+
type: "boolean",
|
|
1958
|
+
description: "Target local development server instead of production",
|
|
1959
|
+
default: false
|
|
1960
|
+
} },
|
|
1961
|
+
async run({ args }) {
|
|
1962
|
+
const isDev = args.dev;
|
|
1963
|
+
p.intro("🔑 App Passwords");
|
|
1964
|
+
const vars = getVars();
|
|
1965
|
+
let targetUrl;
|
|
1966
|
+
try {
|
|
1967
|
+
targetUrl = getTargetUrl(isDev, vars.PDS_HOSTNAME);
|
|
1968
|
+
} catch (err) {
|
|
1969
|
+
p.log.error(err instanceof Error ? err.message : "Configuration error");
|
|
1970
|
+
p.log.info("Run 'pds init' first to configure your PDS.");
|
|
1971
|
+
process.exit(1);
|
|
1972
|
+
}
|
|
1973
|
+
const targetDomain = getDomain(targetUrl);
|
|
1974
|
+
const wranglerVars = getVars();
|
|
1975
|
+
const authToken = {
|
|
1976
|
+
...readDevVars(),
|
|
1977
|
+
...wranglerVars
|
|
1978
|
+
}.AUTH_TOKEN;
|
|
1979
|
+
if (!authToken) {
|
|
1980
|
+
p.log.error("No AUTH_TOKEN found. Run 'pds init' first.");
|
|
1981
|
+
p.outro("Cancelled.");
|
|
1982
|
+
process.exit(1);
|
|
1983
|
+
}
|
|
1984
|
+
const client = new PDSClient(targetUrl, authToken);
|
|
1985
|
+
const spinner = p.spinner();
|
|
1986
|
+
spinner.start(`Checking PDS at ${targetDomain}...`);
|
|
1987
|
+
if (!await client.healthCheck()) {
|
|
1988
|
+
spinner.stop(`PDS not responding at ${targetDomain}`);
|
|
1989
|
+
p.log.error(`Your PDS isn't responding at ${targetUrl}`);
|
|
1990
|
+
p.outro("Cancelled.");
|
|
1991
|
+
process.exit(1);
|
|
1992
|
+
}
|
|
1993
|
+
spinner.stop(`Connected to ${targetDomain}`);
|
|
1994
|
+
spinner.start("Fetching app passwords...");
|
|
1995
|
+
let result;
|
|
1996
|
+
try {
|
|
1997
|
+
result = await client.listAppPasswords();
|
|
1998
|
+
spinner.stop("App passwords retrieved");
|
|
1999
|
+
} catch (err) {
|
|
2000
|
+
spinner.stop("Failed to fetch app passwords");
|
|
2001
|
+
p.log.error(err instanceof Error ? err.message : "Could not fetch app passwords");
|
|
2002
|
+
p.outro("Failed.");
|
|
2003
|
+
process.exit(1);
|
|
2004
|
+
}
|
|
2005
|
+
if (result.passwords.length === 0) {
|
|
2006
|
+
p.log.info("No app passwords.");
|
|
2007
|
+
p.log.info(`Run ${pc.cyan("pds app-password create")} to create one.`);
|
|
2008
|
+
} else {
|
|
2009
|
+
p.log.info("");
|
|
2010
|
+
p.log.info(`${pc.bold("App passwords:")}`);
|
|
2011
|
+
p.log.info("");
|
|
2012
|
+
for (const pw of result.passwords) {
|
|
2013
|
+
const created = formatDateTime(pw.createdAt);
|
|
2014
|
+
console.log(` ${pc.green("●")} ${pc.bold(pw.name)}`);
|
|
2015
|
+
console.log(` ${pc.dim("Created:")} ${created}`);
|
|
2016
|
+
console.log("");
|
|
2017
|
+
}
|
|
2018
|
+
p.log.info(pc.dim(`Total: ${result.passwords.length} app password(s)`));
|
|
2019
|
+
}
|
|
2020
|
+
p.outro("Done!");
|
|
2021
|
+
}
|
|
2022
|
+
});
|
|
2023
|
+
|
|
2024
|
+
//#endregion
|
|
2025
|
+
//#region src/cli/commands/app-password/revoke.ts
|
|
2026
|
+
/**
|
|
2027
|
+
* Revoke app password command
|
|
2028
|
+
*/
|
|
2029
|
+
const revokeCommand = defineCommand({
|
|
2030
|
+
meta: {
|
|
2031
|
+
name: "revoke",
|
|
2032
|
+
description: "Revoke an app password"
|
|
2033
|
+
},
|
|
2034
|
+
args: {
|
|
2035
|
+
dev: {
|
|
2036
|
+
type: "boolean",
|
|
2037
|
+
description: "Target local development server instead of production",
|
|
2038
|
+
default: false
|
|
2039
|
+
},
|
|
2040
|
+
name: {
|
|
2041
|
+
type: "string",
|
|
2042
|
+
alias: "n",
|
|
2043
|
+
description: "Name of the app password to revoke"
|
|
2044
|
+
},
|
|
2045
|
+
yes: {
|
|
2046
|
+
type: "boolean",
|
|
2047
|
+
alias: "y",
|
|
2048
|
+
description: "Skip confirmation",
|
|
2049
|
+
default: false
|
|
2050
|
+
}
|
|
2051
|
+
},
|
|
2052
|
+
async run({ args }) {
|
|
2053
|
+
const isDev = args.dev;
|
|
2054
|
+
const skipConfirm = args.yes;
|
|
2055
|
+
p.intro("🔑 Revoke App Password");
|
|
2056
|
+
const vars = getVars();
|
|
2057
|
+
let targetUrl;
|
|
2058
|
+
try {
|
|
2059
|
+
targetUrl = getTargetUrl(isDev, vars.PDS_HOSTNAME);
|
|
2060
|
+
} catch (err) {
|
|
2061
|
+
p.log.error(err instanceof Error ? err.message : "Configuration error");
|
|
2062
|
+
p.log.info("Run 'pds init' first to configure your PDS.");
|
|
2063
|
+
process.exit(1);
|
|
2064
|
+
}
|
|
2065
|
+
const targetDomain = getDomain(targetUrl);
|
|
2066
|
+
const wranglerVars = getVars();
|
|
2067
|
+
const authToken = {
|
|
2068
|
+
...readDevVars(),
|
|
2069
|
+
...wranglerVars
|
|
2070
|
+
}.AUTH_TOKEN;
|
|
2071
|
+
if (!authToken) {
|
|
2072
|
+
p.log.error("No AUTH_TOKEN found. Run 'pds init' first.");
|
|
2073
|
+
p.outro("Cancelled.");
|
|
2074
|
+
process.exit(1);
|
|
2075
|
+
}
|
|
2076
|
+
const client = new PDSClient(targetUrl, authToken);
|
|
2077
|
+
const spinner = p.spinner();
|
|
2078
|
+
spinner.start(`Checking PDS at ${targetDomain}...`);
|
|
2079
|
+
if (!await client.healthCheck()) {
|
|
2080
|
+
spinner.stop(`PDS not responding at ${targetDomain}`);
|
|
2081
|
+
p.log.error(`Your PDS isn't responding at ${targetUrl}`);
|
|
2082
|
+
p.outro("Cancelled.");
|
|
2083
|
+
process.exit(1);
|
|
2084
|
+
}
|
|
2085
|
+
spinner.stop(`Connected to ${targetDomain}`);
|
|
2086
|
+
let passwordName = args.name;
|
|
2087
|
+
if (!passwordName) {
|
|
2088
|
+
spinner.start("Fetching app passwords...");
|
|
2089
|
+
let result;
|
|
2090
|
+
try {
|
|
2091
|
+
result = await client.listAppPasswords();
|
|
2092
|
+
spinner.stop("App passwords retrieved");
|
|
2093
|
+
} catch (err) {
|
|
2094
|
+
spinner.stop("Failed to fetch app passwords");
|
|
2095
|
+
p.log.error(err instanceof Error ? err.message : "Could not fetch app passwords");
|
|
2096
|
+
p.outro("Failed.");
|
|
2097
|
+
process.exit(1);
|
|
2098
|
+
}
|
|
2099
|
+
if (result.passwords.length === 0) {
|
|
2100
|
+
p.log.info("No app passwords to revoke.");
|
|
2101
|
+
p.outro("Done!");
|
|
2102
|
+
return;
|
|
2103
|
+
}
|
|
2104
|
+
const options = result.passwords.map((pw) => ({
|
|
2105
|
+
value: pw.name,
|
|
2106
|
+
label: pw.name,
|
|
2107
|
+
hint: `Created ${new Date(pw.createdAt).toLocaleDateString()}`
|
|
2108
|
+
}));
|
|
2109
|
+
const selected = await p.select({
|
|
2110
|
+
message: "Select app password to revoke:",
|
|
2111
|
+
options
|
|
2112
|
+
});
|
|
2113
|
+
if (p.isCancel(selected)) {
|
|
2114
|
+
p.cancel("Cancelled.");
|
|
2115
|
+
process.exit(0);
|
|
2116
|
+
}
|
|
2117
|
+
passwordName = selected;
|
|
2118
|
+
}
|
|
2119
|
+
if (!skipConfirm) {
|
|
2120
|
+
const confirm = await p.confirm({
|
|
2121
|
+
message: `Revoke app password "${passwordName}"? Any client using it will lose access.`,
|
|
2122
|
+
initialValue: false
|
|
2123
|
+
});
|
|
2124
|
+
if (p.isCancel(confirm) || !confirm) {
|
|
2125
|
+
p.cancel("Cancelled.");
|
|
2126
|
+
process.exit(0);
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
spinner.start("Revoking app password...");
|
|
2130
|
+
try {
|
|
2131
|
+
await client.revokeAppPassword(passwordName);
|
|
2132
|
+
spinner.stop("App password revoked");
|
|
2133
|
+
p.log.success(`App password "${passwordName}" has been revoked.`);
|
|
2134
|
+
} catch (err) {
|
|
2135
|
+
spinner.stop("Failed to revoke app password");
|
|
2136
|
+
p.log.error(err instanceof Error ? err.message : "Could not revoke app password");
|
|
2137
|
+
p.outro("Failed.");
|
|
2138
|
+
process.exit(1);
|
|
2139
|
+
}
|
|
2140
|
+
p.outro("Done!");
|
|
2141
|
+
}
|
|
2142
|
+
});
|
|
2143
|
+
|
|
2144
|
+
//#endregion
|
|
2145
|
+
//#region src/cli/commands/app-password/index.ts
|
|
2146
|
+
/**
|
|
2147
|
+
* App password management commands
|
|
2148
|
+
*/
|
|
2149
|
+
const appPasswordCommand = defineCommand({
|
|
2150
|
+
meta: {
|
|
2151
|
+
name: "app-password",
|
|
2152
|
+
description: "Manage app passwords for third-party client access"
|
|
2153
|
+
},
|
|
2154
|
+
subCommands: {
|
|
2155
|
+
create: createCommand,
|
|
2156
|
+
list: listCommand,
|
|
2157
|
+
revoke: revokeCommand
|
|
2158
|
+
}
|
|
2159
|
+
});
|
|
2160
|
+
|
|
1763
2161
|
//#endregion
|
|
1764
2162
|
//#region src/cli/utils/handle-resolver.ts
|
|
1765
2163
|
/**
|
|
@@ -4204,8 +4602,6 @@ const MAX_EVENTS = 100;
|
|
|
4204
4602
|
function createInitialState() {
|
|
4205
4603
|
return {
|
|
4206
4604
|
collections: [],
|
|
4207
|
-
syncStatus: "checking",
|
|
4208
|
-
relayRev: null,
|
|
4209
4605
|
pdsRev: null,
|
|
4210
4606
|
subscribers: 0,
|
|
4211
4607
|
latestSeq: null,
|
|
@@ -4215,7 +4611,10 @@ function createInitialState() {
|
|
|
4215
4611
|
accountActive: false,
|
|
4216
4612
|
wsConnected: false,
|
|
4217
4613
|
statusMessage: null,
|
|
4218
|
-
statusMessageTimeout: null
|
|
4614
|
+
statusMessageTimeout: null,
|
|
4615
|
+
handleCheck: null,
|
|
4616
|
+
didCheck: null,
|
|
4617
|
+
relayHostStatus: []
|
|
4219
4618
|
};
|
|
4220
4619
|
}
|
|
4221
4620
|
async function fetchRepo(client, did, state, render) {
|
|
@@ -4242,22 +4641,6 @@ async function fetchRepo(client, did, state, render) {
|
|
|
4242
4641
|
render();
|
|
4243
4642
|
} catch {}
|
|
4244
4643
|
}
|
|
4245
|
-
async function fetchRelaySync(did, state, render) {
|
|
4246
|
-
if (!state.pdsRev) return;
|
|
4247
|
-
try {
|
|
4248
|
-
const res = await fetch(`https://bsky.network/xrpc/com.atproto.sync.getLatestCommit?did=${encodeURIComponent(did)}`);
|
|
4249
|
-
if (res.status === 404) state.syncStatus = "unknown";
|
|
4250
|
-
else if (res.ok) {
|
|
4251
|
-
const data = await res.json();
|
|
4252
|
-
state.syncStatus = data.rev === state.pdsRev ? "synced" : "behind";
|
|
4253
|
-
state.relayRev = data.rev;
|
|
4254
|
-
} else state.syncStatus = "error";
|
|
4255
|
-
render();
|
|
4256
|
-
} catch {
|
|
4257
|
-
state.syncStatus = "error";
|
|
4258
|
-
render();
|
|
4259
|
-
}
|
|
4260
|
-
}
|
|
4261
4644
|
async function fetchFirehoseStatus(client, state, render) {
|
|
4262
4645
|
try {
|
|
4263
4646
|
const data = await client.getFirehoseStatus();
|
|
@@ -4289,7 +4672,27 @@ async function fetchAccountStatus(client, state, render) {
|
|
|
4289
4672
|
render();
|
|
4290
4673
|
} catch {}
|
|
4291
4674
|
}
|
|
4292
|
-
function
|
|
4675
|
+
async function fetchIdentityChecks(client, handle, did, pdsHostname, state, render) {
|
|
4676
|
+
try {
|
|
4677
|
+
const [handleResult, didResult] = await Promise.all([checkHandleResolutionDetailed(client, handle, did), checkDidResolution(client, did, pdsHostname)]);
|
|
4678
|
+
state.handleCheck = {
|
|
4679
|
+
ok: handleResult.ok,
|
|
4680
|
+
methods: handleResult.methods
|
|
4681
|
+
};
|
|
4682
|
+
state.didCheck = {
|
|
4683
|
+
ok: didResult.ok,
|
|
4684
|
+
pdsEndpoint: didResult.pdsEndpoint
|
|
4685
|
+
};
|
|
4686
|
+
render();
|
|
4687
|
+
} catch {}
|
|
4688
|
+
}
|
|
4689
|
+
async function fetchRelayHostStatus(client, pdsHostname, state, render) {
|
|
4690
|
+
try {
|
|
4691
|
+
state.relayHostStatus = await client.getAllRelayHostStatus(pdsHostname);
|
|
4692
|
+
render();
|
|
4693
|
+
} catch {}
|
|
4694
|
+
}
|
|
4695
|
+
function connectFirehose(targetUrl, state, render, onCommit) {
|
|
4293
4696
|
let ws = null;
|
|
4294
4697
|
let reconnectTimer = null;
|
|
4295
4698
|
let closed = false;
|
|
@@ -4313,12 +4716,15 @@ function connectFirehose(targetUrl, state, render) {
|
|
|
4313
4716
|
action: "identity",
|
|
4314
4717
|
path: event.handle ?? ""
|
|
4315
4718
|
});
|
|
4316
|
-
else
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4719
|
+
else {
|
|
4720
|
+
for (const op of event.ops) state.events.unshift({
|
|
4721
|
+
time,
|
|
4722
|
+
seq: event.seq,
|
|
4723
|
+
action: op.action,
|
|
4724
|
+
path: op.path
|
|
4725
|
+
});
|
|
4726
|
+
onCommit?.();
|
|
4727
|
+
}
|
|
4322
4728
|
if (state.events.length > MAX_EVENTS) state.events.length = MAX_EVENTS;
|
|
4323
4729
|
render();
|
|
4324
4730
|
};
|
|
@@ -4348,78 +4754,65 @@ function renderDashboard(state, config) {
|
|
|
4348
4754
|
const rows = process.stdout.rows || 24;
|
|
4349
4755
|
const lines = [];
|
|
4350
4756
|
const indent = " ";
|
|
4757
|
+
const accountDot = state.accountActive ? pc.green("●") + " " + pc.green("ACTIVE") : pc.yellow("○") + " " + pc.yellow("INACTIVE");
|
|
4351
4758
|
lines.push("");
|
|
4352
4759
|
lines.push(`${indent}${pc.bold("☁ CIRRUS")} ${pc.dim("·")} ${pc.cyan(config.hostname)} ${pc.dim("·")} ${pc.dim("v" + config.version)}`);
|
|
4353
|
-
lines.push(`${indent} ${pc.white("@" + config.handle)} ${pc.dim("·")} ${pc.dim(config.did)}`);
|
|
4760
|
+
lines.push(`${indent} ${pc.white("@" + config.handle)} ${pc.dim("·")} ${pc.dim(config.did)} ${pc.dim("·")} ${accountDot}`);
|
|
4354
4761
|
lines.push("");
|
|
4355
|
-
const colWidth = Math.floor((cols - 6) /
|
|
4762
|
+
const colWidth = Math.floor((cols - 6) / 2);
|
|
4356
4763
|
const col1 = [pc.dim("REPOSITORY"), ""];
|
|
4357
|
-
if (state.collections.length === 0) col1.push(pc.dim("
|
|
4764
|
+
if (state.collections.length === 0) col1.push(pc.dim("No records"));
|
|
4358
4765
|
else for (const c of state.collections) {
|
|
4359
4766
|
const name = c.friendlyName.padEnd(16);
|
|
4360
4767
|
const count = String(c.count).padStart(5);
|
|
4361
4768
|
const more = c.hasMore ? "+" : " ";
|
|
4362
4769
|
col1.push(`${name} ${pc.bold(count)}${more}`);
|
|
4363
4770
|
}
|
|
4364
|
-
const col2 = [pc.dim("
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4771
|
+
const col2 = [pc.dim("NETWORK"), ""];
|
|
4772
|
+
if (state.handleCheck) {
|
|
4773
|
+
const icon = state.handleCheck.ok ? pc.green("✓") : pc.red("✗");
|
|
4774
|
+
const methods = state.handleCheck.methods.length > 0 ? pc.dim(` ${state.handleCheck.methods.join(" ")}`) : "";
|
|
4775
|
+
col2.push(`${icon} handle${methods}`);
|
|
4776
|
+
} else col2.push(pc.dim("○ handle checking…"));
|
|
4777
|
+
if (state.didCheck) {
|
|
4778
|
+
const icon = state.didCheck.ok ? pc.green("✓") : pc.red("✗");
|
|
4779
|
+
col2.push(`${icon} did document`);
|
|
4780
|
+
} else col2.push(pc.dim("○ did doc checking…"));
|
|
4781
|
+
col2.push("");
|
|
4782
|
+
const relayStatusColors = {
|
|
4783
|
+
active: pc.green,
|
|
4784
|
+
idle: pc.yellow,
|
|
4785
|
+
offline: pc.red,
|
|
4786
|
+
throttled: pc.red,
|
|
4787
|
+
banned: pc.red
|
|
4372
4788
|
};
|
|
4373
|
-
const
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4789
|
+
const relayDotColors = {
|
|
4790
|
+
active: pc.green("●"),
|
|
4791
|
+
idle: pc.yellow("●"),
|
|
4792
|
+
offline: pc.red("●"),
|
|
4793
|
+
throttled: pc.red("●"),
|
|
4794
|
+
banned: pc.red("●")
|
|
4379
4795
|
};
|
|
4380
|
-
const
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4796
|
+
if (state.relayHostStatus.length > 0) for (const relay of state.relayHostStatus) {
|
|
4797
|
+
const name = relay.relay.replace("https://relay1.", "").replace(".bsky.network", "");
|
|
4798
|
+
const colorFn = relayStatusColors[relay.status] ?? pc.dim;
|
|
4799
|
+
const dot = relayDotColors[relay.status] ?? pc.dim("○");
|
|
4800
|
+
col2.push(`${dot} ${name} ${colorFn(relay.status)}`);
|
|
4801
|
+
}
|
|
4802
|
+
else col2.push(pc.dim("○ relay unknown"));
|
|
4803
|
+
col2.push("");
|
|
4384
4804
|
const subDot = state.subscribers > 0 ? pc.green("●") : pc.dim("○");
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
for (const sub of state.subscriberDetails.slice(0, 5)) {
|
|
4390
|
-
const ip = sub.ip ? ` ${shortenIP(sub.ip)}` : "";
|
|
4391
|
-
col3.push(pc.dim(`${relativeTime(sub.connectedAt)} cursor: ${sub.cursor}${ip}`));
|
|
4392
|
-
}
|
|
4805
|
+
col2.push(`${subDot} ${pc.bold(String(state.subscribers))} subscriber${state.subscribers !== 1 ? "s" : ""} ${pc.dim("seq:")} ${state.latestSeq != null ? state.latestSeq : pc.dim("—")}`);
|
|
4806
|
+
if (state.subscriberDetails.length > 0) for (const sub of state.subscriberDetails.slice(0, 3)) {
|
|
4807
|
+
const ip = sub.ip ? shortenIP(sub.ip) : "";
|
|
4808
|
+
col2.push(pc.dim(` ${relativeTime(sub.connectedAt)} cursor: ${sub.cursor} ${ip}`));
|
|
4393
4809
|
}
|
|
4394
|
-
const columnLines = renderColumns([
|
|
4395
|
-
col1,
|
|
4396
|
-
col2,
|
|
4397
|
-
col3
|
|
4398
|
-
], [
|
|
4399
|
-
colWidth,
|
|
4400
|
-
colWidth,
|
|
4401
|
-
colWidth
|
|
4402
|
-
]);
|
|
4810
|
+
const columnLines = renderColumns([col1, col2], [colWidth, colWidth]);
|
|
4403
4811
|
for (const line of columnLines) lines.push(indent + line);
|
|
4404
4812
|
lines.push("");
|
|
4405
4813
|
const remaining = rows - lines.length - 3;
|
|
4406
|
-
const notifHeight = Math.max(3, Math.floor(remaining * .
|
|
4814
|
+
const notifHeight = Math.max(3, Math.floor(remaining * .35));
|
|
4407
4815
|
const eventsHeight = Math.max(3, remaining - notifHeight);
|
|
4408
|
-
const notifSeparator = "─".repeat(Math.max(0, cols - visibleLength(indent + "NOTIFICATIONS ") - 2));
|
|
4409
|
-
lines.push(`${indent}${pc.dim("NOTIFICATIONS " + notifSeparator)}`);
|
|
4410
|
-
if (state.notifications.length === 0) {
|
|
4411
|
-
lines.push(`${indent}${pc.dim("No notifications yet")}`);
|
|
4412
|
-
for (let i = 1; i < notifHeight - 1; i++) lines.push("");
|
|
4413
|
-
} else {
|
|
4414
|
-
const visibleNotifs = state.notifications.slice(0, notifHeight - 1);
|
|
4415
|
-
for (const n of visibleNotifs) {
|
|
4416
|
-
const readDim = n.isRead ? pc.dim : (s) => s;
|
|
4417
|
-
const line = `${indent}${pc.dim(n.time)} ${n.icon} ${readDim(n.author)} ${readDim(pc.dim(n.text))}`;
|
|
4418
|
-
lines.push(truncate(line, cols));
|
|
4419
|
-
}
|
|
4420
|
-
for (let i = visibleNotifs.length; i < notifHeight - 1; i++) lines.push("");
|
|
4421
|
-
}
|
|
4422
|
-
lines.push("");
|
|
4423
4816
|
const wsStatusText = state.wsConnected ? "● connected" : "○ disconnected";
|
|
4424
4817
|
indent + "";
|
|
4425
4818
|
const eventsSuffix = " " + wsStatusText + " ";
|
|
@@ -4438,16 +4831,35 @@ function renderDashboard(state, config) {
|
|
|
4438
4831
|
delete: pc.red,
|
|
4439
4832
|
identity: pc.cyan
|
|
4440
4833
|
}[ev.action] ?? pc.dim;
|
|
4441
|
-
const line = `${indent}${pc.dim(ev.time)} ${pc.dim("#" + String(ev.seq).padStart(4))} ${actionColor(ev.action.toUpperCase().padEnd(
|
|
4834
|
+
const line = `${indent}${pc.dim(ev.time)} ${pc.dim("#" + String(ev.seq).padStart(4))} ${actionColor(ev.action.toUpperCase().padEnd(8))} ${ev.path}`;
|
|
4442
4835
|
lines.push(truncate(line, cols));
|
|
4443
4836
|
}
|
|
4444
4837
|
for (let i = visibleEvents.length; i < eventsHeight - 1; i++) lines.push("");
|
|
4445
4838
|
}
|
|
4839
|
+
const notifSeparator = "─".repeat(Math.max(0, cols - visibleLength(indent + "NOTIFICATIONS ") - 2));
|
|
4840
|
+
lines.push(`${indent}${pc.dim("NOTIFICATIONS " + notifSeparator)}`);
|
|
4841
|
+
if (state.notifications.length === 0) {
|
|
4842
|
+
lines.push(`${indent}${pc.dim("No notifications yet")}`);
|
|
4843
|
+
for (let i = 1; i < notifHeight - 1; i++) lines.push("");
|
|
4844
|
+
} else {
|
|
4845
|
+
const visibleNotifs = state.notifications.slice(0, notifHeight - 1);
|
|
4846
|
+
for (const n of visibleNotifs) {
|
|
4847
|
+
const readDim = n.isRead ? pc.dim : (s) => s;
|
|
4848
|
+
const line = `${indent}${pc.dim(n.time)} ${n.icon} ${readDim(n.author)} ${readDim(pc.dim(n.text))}`;
|
|
4849
|
+
lines.push(truncate(line, cols));
|
|
4850
|
+
}
|
|
4851
|
+
for (let i = visibleNotifs.length; i < notifHeight - 1; i++) lines.push("");
|
|
4852
|
+
}
|
|
4446
4853
|
lines.push("");
|
|
4447
|
-
const
|
|
4448
|
-
|
|
4854
|
+
const keys = [];
|
|
4855
|
+
if (!state.accountActive) keys.push(`${pc.dim("[a]")} activate`);
|
|
4856
|
+
else {
|
|
4857
|
+
keys.push(`${pc.dim("[r]")} crawl`);
|
|
4858
|
+
keys.push(`${pc.dim("[e]")} emit identity`);
|
|
4859
|
+
}
|
|
4860
|
+
keys.push(`${pc.dim("[q]")} quit`);
|
|
4861
|
+
let footer = `${indent}${keys.join(` ${pc.dim("·")} `)}`;
|
|
4449
4862
|
if (state.statusMessage) footer += ` ${pc.yellow(state.statusMessage)}`;
|
|
4450
|
-
else footer += ` ${accountStatus}`;
|
|
4451
4863
|
lines.push(footer);
|
|
4452
4864
|
while (lines.length < rows) lines.push("");
|
|
4453
4865
|
const output = lines.slice(0, rows).map((l) => padRight(l, cols)).join("\n");
|
|
@@ -4490,6 +4902,7 @@ const dashboardCommand = defineCommand({
|
|
|
4490
4902
|
const authToken = config.AUTH_TOKEN;
|
|
4491
4903
|
const handle = config.HANDLE ?? "";
|
|
4492
4904
|
const did = config.DID ?? "";
|
|
4905
|
+
const pdsHostname = config.PDS_HOSTNAME ?? "";
|
|
4493
4906
|
if (!authToken) {
|
|
4494
4907
|
console.error(pc.red("Error:"), "No AUTH_TOKEN found. Run 'pds init' first.");
|
|
4495
4908
|
process.exit(1);
|
|
@@ -4501,7 +4914,7 @@ const dashboardCommand = defineCommand({
|
|
|
4501
4914
|
}
|
|
4502
4915
|
const state = createInitialState();
|
|
4503
4916
|
const dashConfig = {
|
|
4504
|
-
hostname:
|
|
4917
|
+
hostname: pdsHostname || targetUrl,
|
|
4505
4918
|
handle,
|
|
4506
4919
|
did,
|
|
4507
4920
|
version: "0.10.6"
|
|
@@ -4512,9 +4925,11 @@ const dashboardCommand = defineCommand({
|
|
|
4512
4925
|
clearScreen();
|
|
4513
4926
|
const intervals = [];
|
|
4514
4927
|
let firehose = null;
|
|
4928
|
+
let repoRefetchTimer = null;
|
|
4515
4929
|
function cleanup() {
|
|
4516
4930
|
for (const interval of intervals) clearInterval(interval);
|
|
4517
4931
|
if (firehose) firehose.close();
|
|
4932
|
+
if (repoRefetchTimer) clearTimeout(repoRefetchTimer);
|
|
4518
4933
|
if (state.statusMessageTimeout) clearTimeout(state.statusMessageTimeout);
|
|
4519
4934
|
if (process.stdin.isTTY) process.stdin.setRawMode(false);
|
|
4520
4935
|
showCursor();
|
|
@@ -4528,20 +4943,28 @@ const dashboardCommand = defineCommand({
|
|
|
4528
4943
|
cleanup();
|
|
4529
4944
|
process.exit(0);
|
|
4530
4945
|
});
|
|
4946
|
+
const scheduleRepoRefetch = () => {
|
|
4947
|
+
if (repoRefetchTimer) clearTimeout(repoRefetchTimer);
|
|
4948
|
+
repoRefetchTimer = setTimeout(() => {
|
|
4949
|
+
fetchRepo(client, did, state, render);
|
|
4950
|
+
}, 1e3);
|
|
4951
|
+
};
|
|
4531
4952
|
render();
|
|
4532
4953
|
await Promise.all([
|
|
4533
4954
|
fetchRepo(client, did, state, render),
|
|
4534
4955
|
fetchFirehoseStatus(client, state, render),
|
|
4535
4956
|
fetchAccountStatus(client, state, render),
|
|
4536
|
-
fetchNotifications(client, state, render)
|
|
4957
|
+
fetchNotifications(client, state, render),
|
|
4958
|
+
fetchIdentityChecks(client, handle, did, pdsHostname, state, render)
|
|
4537
4959
|
]);
|
|
4538
|
-
await
|
|
4960
|
+
await fetchRelayHostStatus(client, pdsHostname, state, render);
|
|
4539
4961
|
intervals.push(setInterval(() => fetchRepo(client, did, state, render), 3e4));
|
|
4540
|
-
intervals.push(setInterval(() =>
|
|
4962
|
+
intervals.push(setInterval(() => fetchRelayHostStatus(client, pdsHostname, state, render), 5e3));
|
|
4541
4963
|
intervals.push(setInterval(() => fetchFirehoseStatus(client, state, render), 1e4));
|
|
4542
4964
|
intervals.push(setInterval(() => fetchNotifications(client, state, render), 15e3));
|
|
4543
4965
|
intervals.push(setInterval(() => fetchAccountStatus(client, state, render), 3e4));
|
|
4544
|
-
|
|
4966
|
+
intervals.push(setInterval(() => fetchIdentityChecks(client, handle, did, pdsHostname, state, render), 15e3));
|
|
4967
|
+
firehose = connectFirehose(targetUrl, state, render, scheduleRepoRefetch);
|
|
4545
4968
|
process.stdout.on("resize", render);
|
|
4546
4969
|
if (process.stdin.isTTY) {
|
|
4547
4970
|
process.stdin.setRawMode(true);
|
|
@@ -4559,6 +4982,7 @@ const dashboardCommand = defineCommand({
|
|
|
4559
4982
|
process.exit(0);
|
|
4560
4983
|
}
|
|
4561
4984
|
if (key === "a" || key === "A") {
|
|
4985
|
+
if (state.accountActive) return;
|
|
4562
4986
|
if (awaitingActivateConfirm) {
|
|
4563
4987
|
awaitingActivateConfirm = false;
|
|
4564
4988
|
if (activateConfirmTimeout) clearTimeout(activateConfirmTimeout);
|
|
@@ -4566,12 +4990,7 @@ const dashboardCommand = defineCommand({
|
|
|
4566
4990
|
try {
|
|
4567
4991
|
await client.activateAccount();
|
|
4568
4992
|
state.accountActive = true;
|
|
4569
|
-
|
|
4570
|
-
if (pdsHostname && !isDev) await client.requestCrawl(pdsHostname);
|
|
4571
|
-
try {
|
|
4572
|
-
await client.emitIdentity();
|
|
4573
|
-
} catch {}
|
|
4574
|
-
setStatusMessage(state, pc.green("✓ Activated! Crawl requested."), render, 5e3);
|
|
4993
|
+
setStatusMessage(state, pc.green("✓ Account activated"), render, 5e3);
|
|
4575
4994
|
} catch (err) {
|
|
4576
4995
|
setStatusMessage(state, pc.red(`\u2717 ${err instanceof Error ? err.message : "Activation failed"}`), render, 5e3);
|
|
4577
4996
|
}
|
|
@@ -4587,7 +5006,7 @@ const dashboardCommand = defineCommand({
|
|
|
4587
5006
|
return;
|
|
4588
5007
|
}
|
|
4589
5008
|
if (key === "r" || key === "R") {
|
|
4590
|
-
|
|
5009
|
+
if (!state.accountActive) return;
|
|
4591
5010
|
if (!pdsHostname || isDev) {
|
|
4592
5011
|
setStatusMessage(state, pc.yellow("No PDS hostname configured"), render);
|
|
4593
5012
|
return;
|
|
@@ -4597,6 +5016,7 @@ const dashboardCommand = defineCommand({
|
|
|
4597
5016
|
return;
|
|
4598
5017
|
}
|
|
4599
5018
|
if (key === "e" || key === "E") {
|
|
5019
|
+
if (!state.accountActive) return;
|
|
4600
5020
|
setStatusMessage(state, "Emitting identity…", render, 1e4);
|
|
4601
5021
|
try {
|
|
4602
5022
|
const result = await client.emitIdentity();
|
|
@@ -4626,6 +5046,7 @@ runMain(defineCommand({
|
|
|
4626
5046
|
init: initCommand,
|
|
4627
5047
|
secret: secretCommand,
|
|
4628
5048
|
passkey: passkeyCommand,
|
|
5049
|
+
"app-password": appPasswordCommand,
|
|
4629
5050
|
migrate: migrateCommand,
|
|
4630
5051
|
"migrate-token": migrateTokenCommand,
|
|
4631
5052
|
identity: identityCommand,
|