routstrd 0.2.10 → 0.2.12
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/dist/index.js +51 -10
- package/package.json +1 -1
- package/src/cli.ts +50 -1
- package/src/utils/clients.ts +11 -8
package/dist/index.js
CHANGED
|
@@ -15243,10 +15243,7 @@ async function getClientsList() {
|
|
|
15243
15243
|
async function addDaemonClient(name) {
|
|
15244
15244
|
const existingClients = await getClientsList();
|
|
15245
15245
|
const derivedId = name.replace(/\s+/g, "-").toLowerCase();
|
|
15246
|
-
const
|
|
15247
|
-
const suffix = getNpubSuffix2(config);
|
|
15248
|
-
const clientId = suffix ? addSuffixToId(derivedId, suffix) : derivedId;
|
|
15249
|
-
const existing = existingClients.find((c) => c.clientId === clientId);
|
|
15246
|
+
const existing = existingClients.find((c) => c.clientId === derivedId);
|
|
15250
15247
|
if (existing) {
|
|
15251
15248
|
const client = {
|
|
15252
15249
|
id: existing.clientId,
|
|
@@ -15257,9 +15254,12 @@ async function addDaemonClient(name) {
|
|
|
15257
15254
|
};
|
|
15258
15255
|
return { client, created: false };
|
|
15259
15256
|
}
|
|
15257
|
+
const config = await loadConfig();
|
|
15258
|
+
const suffix = getNpubSuffix2(config);
|
|
15259
|
+
const clientId = suffix ? addSuffixToId(derivedId, suffix) : derivedId;
|
|
15260
15260
|
const result = await callDaemon("/clients/add", {
|
|
15261
15261
|
method: "POST",
|
|
15262
|
-
body: { name, id:
|
|
15262
|
+
body: { name, id: clientId }
|
|
15263
15263
|
});
|
|
15264
15264
|
const output4 = result.output;
|
|
15265
15265
|
if (!output4?.client?.apiKey) {
|
|
@@ -15314,6 +15314,7 @@ async function deleteClientAction(id) {
|
|
|
15314
15314
|
async function addClientAction(options) {
|
|
15315
15315
|
await ensureDaemonRunning();
|
|
15316
15316
|
const config = await loadConfig();
|
|
15317
|
+
const suffix = getNpubSuffix2(config);
|
|
15317
15318
|
const integrationKeys = [];
|
|
15318
15319
|
if (options.opencode)
|
|
15319
15320
|
integrationKeys.push("opencode");
|
|
@@ -15339,7 +15340,7 @@ async function addClientAction(options) {
|
|
|
15339
15340
|
await integrationFn(config, client.apiKey, integrationConfig);
|
|
15340
15341
|
console.log(`
|
|
15341
15342
|
${integrationConfig.name}:`);
|
|
15342
|
-
console.log(` Client ID: ${client.id}`);
|
|
15343
|
+
console.log(` Client ID: ${suffix ? removeSuffixFromId(client.id, suffix) : client.id}`);
|
|
15343
15344
|
console.log(` API Key: ${client.apiKey}`);
|
|
15344
15345
|
} catch (error) {
|
|
15345
15346
|
logger.error(`Failed to set up ${integrationConfig.name} integration:`, error);
|
|
@@ -15359,7 +15360,7 @@ async function addClientAction(options) {
|
|
|
15359
15360
|
if (!created) {
|
|
15360
15361
|
console.log(`Client '${options.name}' already exists.`);
|
|
15361
15362
|
console.log(`
|
|
15362
|
-
ID: ${client.id}`);
|
|
15363
|
+
ID: ${suffix ? removeSuffixFromId(client.id, suffix) : client.id}`);
|
|
15363
15364
|
console.log(` Name: ${client.name}`);
|
|
15364
15365
|
console.log(` API Key: ${client.apiKey}`);
|
|
15365
15366
|
return;
|
|
@@ -15368,7 +15369,7 @@ async function addClientAction(options) {
|
|
|
15368
15369
|
console.log(message);
|
|
15369
15370
|
}
|
|
15370
15371
|
console.log(`
|
|
15371
|
-
ID: ${client.id}`);
|
|
15372
|
+
ID: ${suffix ? removeSuffixFromId(client.id, suffix) : client.id}`);
|
|
15372
15373
|
console.log(` Name: ${client.name}`);
|
|
15373
15374
|
console.log(` API Key: ${client.apiKey}`);
|
|
15374
15375
|
console.log(`
|
|
@@ -15557,7 +15558,7 @@ async function isCocodInstalled(cocodPath) {
|
|
|
15557
15558
|
// package.json
|
|
15558
15559
|
var package_default = {
|
|
15559
15560
|
name: "routstrd",
|
|
15560
|
-
version: "0.2.
|
|
15561
|
+
version: "0.2.12",
|
|
15561
15562
|
module: "src/index.ts",
|
|
15562
15563
|
type: "module",
|
|
15563
15564
|
private: false,
|
|
@@ -16075,7 +16076,7 @@ npubsCmd.command("list").description("List configured admin npubs").action(async
|
|
|
16075
16076
|
const data = result.output?.npubs ? result.output : result;
|
|
16076
16077
|
const npubs = data?.npubs ?? [];
|
|
16077
16078
|
if (npubs.length === 0) {
|
|
16078
|
-
console.log("No admin npubs configured.");
|
|
16079
|
+
console.log("No admin npubs configured. Run 'routstrd npubs register' to register yourself as the first admin.");
|
|
16079
16080
|
return;
|
|
16080
16081
|
}
|
|
16081
16082
|
console.log(`Admin npubs (${npubs.length}):`);
|
|
@@ -16092,6 +16093,46 @@ npubsCmd.command("list").description("List configured admin npubs").action(async
|
|
|
16092
16093
|
console.log(` ${userNpub}`);
|
|
16093
16094
|
}
|
|
16094
16095
|
});
|
|
16096
|
+
npubsCmd.command("register").description("Register yourself as the first admin (only when no admins exist)").action(async () => {
|
|
16097
|
+
await ensureDaemonRunning();
|
|
16098
|
+
const config = await loadConfig();
|
|
16099
|
+
const userNpub = getUserNpub(config);
|
|
16100
|
+
if (!userNpub) {
|
|
16101
|
+
console.error("No Nostr identity configured. Run 'routstrd remote <url>' to set one up.");
|
|
16102
|
+
process.exit(1);
|
|
16103
|
+
}
|
|
16104
|
+
const result = await callDaemon("/npubs");
|
|
16105
|
+
if (result.error) {
|
|
16106
|
+
console.log(result.error);
|
|
16107
|
+
process.exit(1);
|
|
16108
|
+
}
|
|
16109
|
+
const data = result.output?.npubs ? result.output : result;
|
|
16110
|
+
const npubs = data?.npubs ?? [];
|
|
16111
|
+
if (npubs.length > 0) {
|
|
16112
|
+
console.log(`Admin npubs already configured (${npubs.length}). Ask your admin to add your npub.
|
|
16113
|
+
Your npub: ${userNpub}`);
|
|
16114
|
+
return;
|
|
16115
|
+
}
|
|
16116
|
+
const normalized = normalizeNostrPubkey(userNpub);
|
|
16117
|
+
if (!normalized) {
|
|
16118
|
+
console.error("Failed to normalize user npub.");
|
|
16119
|
+
process.exit(1);
|
|
16120
|
+
}
|
|
16121
|
+
const addResult = await callDaemon("/npubs", {
|
|
16122
|
+
method: "POST",
|
|
16123
|
+
body: { npub: npubFromPubkey(normalized) }
|
|
16124
|
+
});
|
|
16125
|
+
if (addResult.error) {
|
|
16126
|
+
console.log(addResult.error);
|
|
16127
|
+
process.exit(1);
|
|
16128
|
+
}
|
|
16129
|
+
const output4 = addResult.output;
|
|
16130
|
+
if (output4?.npub) {
|
|
16131
|
+
console.log(`Successfully registered as first admin npub: ${output4.npub}`);
|
|
16132
|
+
} else {
|
|
16133
|
+
console.log(`Successfully registered as first admin npub: ${userNpub}`);
|
|
16134
|
+
}
|
|
16135
|
+
});
|
|
16095
16136
|
npubsCmd.command("add <npub>").description("Add an admin npub (hex pubkey or npub1...)").action(async (npubArg) => {
|
|
16096
16137
|
await ensureDaemonRunning();
|
|
16097
16138
|
const normalized = normalizeNostrPubkey(npubArg);
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -856,7 +856,7 @@ npubsCmd
|
|
|
856
856
|
: result;
|
|
857
857
|
const npubs = (data as { npubs?: string[] } | undefined)?.npubs ?? [];
|
|
858
858
|
if (npubs.length === 0) {
|
|
859
|
-
console.log("No admin npubs configured.");
|
|
859
|
+
console.log("No admin npubs configured. Run 'routstrd npubs register' to register yourself as the first admin.");
|
|
860
860
|
return;
|
|
861
861
|
}
|
|
862
862
|
console.log(`Admin npubs (${npubs.length}):`);
|
|
@@ -875,6 +875,55 @@ npubsCmd
|
|
|
875
875
|
}
|
|
876
876
|
});
|
|
877
877
|
|
|
878
|
+
npubsCmd
|
|
879
|
+
.command("register")
|
|
880
|
+
.description("Register yourself as the first admin (only when no admins exist)")
|
|
881
|
+
.action(async () => {
|
|
882
|
+
await ensureDaemonRunning();
|
|
883
|
+
const config = await loadConfig();
|
|
884
|
+
const userNpub = getUserNpub(config);
|
|
885
|
+
if (!userNpub) {
|
|
886
|
+
console.error(
|
|
887
|
+
"No Nostr identity configured. Run 'routstrd remote <url>' to set one up.",
|
|
888
|
+
);
|
|
889
|
+
process.exit(1);
|
|
890
|
+
}
|
|
891
|
+
const result = await callDaemon("/npubs");
|
|
892
|
+
if (result.error) {
|
|
893
|
+
console.log(result.error);
|
|
894
|
+
process.exit(1);
|
|
895
|
+
}
|
|
896
|
+
const data = (result.output as { npubs?: string[] } | undefined)?.npubs
|
|
897
|
+
? result.output
|
|
898
|
+
: result;
|
|
899
|
+
const npubs = (data as { npubs?: string[] } | undefined)?.npubs ?? [];
|
|
900
|
+
if (npubs.length > 0) {
|
|
901
|
+
console.log(`Admin npubs already configured (${npubs.length}). Ask your admin to add your npub. \n Your npub: ${userNpub}`);
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
const normalized = normalizeNostrPubkey(userNpub);
|
|
905
|
+
if (!normalized) {
|
|
906
|
+
console.error("Failed to normalize user npub.");
|
|
907
|
+
process.exit(1);
|
|
908
|
+
}
|
|
909
|
+
const addResult = await callDaemon("/npubs", {
|
|
910
|
+
method: "POST",
|
|
911
|
+
body: { npub: npubFromPubkey(normalized) },
|
|
912
|
+
});
|
|
913
|
+
if (addResult.error) {
|
|
914
|
+
console.log(addResult.error);
|
|
915
|
+
process.exit(1);
|
|
916
|
+
}
|
|
917
|
+
const output = addResult.output as
|
|
918
|
+
| { npub?: string; added?: boolean; error?: string }
|
|
919
|
+
| undefined;
|
|
920
|
+
if (output?.npub) {
|
|
921
|
+
console.log(`Successfully registered as first admin npub: ${output.npub}`);
|
|
922
|
+
} else {
|
|
923
|
+
console.log(`Successfully registered as first admin npub: ${userNpub}`);
|
|
924
|
+
}
|
|
925
|
+
});
|
|
926
|
+
|
|
878
927
|
npubsCmd
|
|
879
928
|
.command("add <npub>")
|
|
880
929
|
.description("Add an admin npub (hex pubkey or npub1...)")
|
package/src/utils/clients.ts
CHANGED
|
@@ -125,11 +125,8 @@ export async function addDaemonClient(
|
|
|
125
125
|
const existingClients = await getClientsList();
|
|
126
126
|
// Derive id from name by replacing spaces with hyphens
|
|
127
127
|
const derivedId = name.replace(/\s+/g, "-").toLowerCase();
|
|
128
|
-
const
|
|
129
|
-
const suffix = getNpubSuffix(config);
|
|
130
|
-
const clientId = suffix ? addSuffixToId(derivedId, suffix) : derivedId;
|
|
128
|
+
const existing = existingClients.find((c) => c.clientId === derivedId);
|
|
131
129
|
|
|
132
|
-
const existing = existingClients.find((c) => c.clientId === clientId);
|
|
133
130
|
|
|
134
131
|
if (existing) {
|
|
135
132
|
const client: DaemonClient = {
|
|
@@ -142,9 +139,14 @@ export async function addDaemonClient(
|
|
|
142
139
|
return { client, created: false };
|
|
143
140
|
}
|
|
144
141
|
|
|
142
|
+
const config = await loadConfig();
|
|
143
|
+
const suffix = getNpubSuffix(config);
|
|
144
|
+
const clientId = suffix ? addSuffixToId(derivedId, suffix) : derivedId;
|
|
145
|
+
|
|
146
|
+
|
|
145
147
|
const result = await callDaemon("/clients/add", {
|
|
146
148
|
method: "POST",
|
|
147
|
-
body: { name, id:
|
|
149
|
+
body: { name, id: clientId },
|
|
148
150
|
});
|
|
149
151
|
|
|
150
152
|
|
|
@@ -231,6 +233,7 @@ export interface AddClientOptions {
|
|
|
231
233
|
export async function addClientAction(options: AddClientOptions): Promise<void> {
|
|
232
234
|
await ensureDaemonRunning();
|
|
233
235
|
const config = await loadConfig();
|
|
236
|
+
const suffix = getNpubSuffix(config);
|
|
234
237
|
|
|
235
238
|
const integrationKeys: string[] = [];
|
|
236
239
|
if (options.opencode) integrationKeys.push("opencode");
|
|
@@ -256,7 +259,7 @@ export async function addClientAction(options: AddClientOptions): Promise<void>
|
|
|
256
259
|
await integrationFn(config, client.apiKey, integrationConfig);
|
|
257
260
|
|
|
258
261
|
console.log(`\n ${integrationConfig.name}:`);
|
|
259
|
-
console.log(` Client ID: ${client.id}`);
|
|
262
|
+
console.log(` Client ID: ${suffix ? removeSuffixFromId(client.id, suffix) : client.id}`);
|
|
260
263
|
console.log(` API Key: ${client.apiKey}`);
|
|
261
264
|
} catch (error) {
|
|
262
265
|
logger.error(
|
|
@@ -283,7 +286,7 @@ export async function addClientAction(options: AddClientOptions): Promise<void>
|
|
|
283
286
|
|
|
284
287
|
if (!created) {
|
|
285
288
|
console.log(`Client '${options.name}' already exists.`);
|
|
286
|
-
console.log(`\n ID: ${client.id}`);
|
|
289
|
+
console.log(`\n ID: ${suffix ? removeSuffixFromId(client.id, suffix) : client.id}`);
|
|
287
290
|
console.log(` Name: ${client.name}`);
|
|
288
291
|
console.log(` API Key: ${client.apiKey}`);
|
|
289
292
|
return;
|
|
@@ -292,7 +295,7 @@ export async function addClientAction(options: AddClientOptions): Promise<void>
|
|
|
292
295
|
if (message) {
|
|
293
296
|
console.log(message);
|
|
294
297
|
}
|
|
295
|
-
console.log(`\n ID: ${client.id}`);
|
|
298
|
+
console.log(`\n ID: ${suffix ? removeSuffixFromId(client.id, suffix) : client.id}`);
|
|
296
299
|
console.log(` Name: ${client.name}`);
|
|
297
300
|
console.log(` API Key: ${client.apiKey}`);
|
|
298
301
|
console.log(`\n Access Routstr at: ${getDaemonBaseUrl(config)}/v1`);
|