diff --git a/src/utils/clients.ts b/src/utils/clients.ts index 1216dc4..d3da304 100644 --- a/src/utils/clients.ts +++ b/src/utils/clients.ts @@ -121,12 +121,15 @@ export async function getClientsList(): Promise { export async function addDaemonClient( name: string, - clientId?: string, ): Promise<{ message?: string; client: DaemonClient; created: boolean }> { const existingClients = await getClientsList(); - const existing = clientId - ? existingClients.find((c) => c.clientId === clientId) - : existingClients.find((c) => c.name === name); + // Derive id from name by replacing spaces with hyphens + const derivedId = name.replace(/\s+/g, "-").toLowerCase(); + const config = await loadConfig(); + const suffix = getNpubSuffix(config); + const clientId = suffix ? addSuffixToId(derivedId, suffix) : derivedId; + + const existing = existingClients.find((c) => c.clientId === clientId); if (existing) { const client: DaemonClient = { @@ -139,9 +142,6 @@ export async function addDaemonClient( return { client, created: false }; } - // Derive id from name by replacing spaces with hyphens - const derivedId = name.replace(/\s+/g, "-").toLowerCase(); - const result = await callDaemon("/clients/add", { method: "POST", body: { name, id: derivedId }, @@ -246,8 +246,7 @@ export async function addClientAction(options: AddClientOptions): Promise try { const { client, created } = await addDaemonClient( - integrationConfig.name, - integrationConfig.clientId, + integrationConfig.name ); if (created) { logger.log(`Created new API key for ${integrationConfig.name}`);