import { storeJson } from '../fileModels/storeJson' import { actionGroups } from '../actionGroups' import { i18n } from '../i18n' import { sdk } from '../sdk' export const showRegistryApiKeys = sdk.Action.withoutInput( // id 'show-registry-api-keys', // metadata async ({ effects }) => ({ name: i18n('Show Registry API Keys'), description: i18n( 'Display the stored REGISTRY_API_KEY and SUBSD_API_KEY used by registry-server. Returns blanks if Create Registry API Keys has not been run yet.', ), warning: null, allowedStatuses: 'any', group: actionGroups.subspacesRegistry, visibility: 'enabled', }), // run async ({ effects }) => { const [registryApiKey, subsdApiKey] = await Promise.all([ storeJson.read((s) => s.registryApiKey).once(), storeJson.read((s) => s.subsdApiKey).once(), ]) const ready = !!registryApiKey && !!subsdApiKey && registryApiKey.length > 0 && subsdApiKey.length > 0 && registryApiKey !== subsdApiKey return { version: '1', title: i18n('Show Registry API Keys'), message: ready ? i18n( 'Paste SUBSD_API_KEY into subs Settings → Registry Server → Auth Token. Use REGISTRY_API_KEY as the Bearer token for POST /register clients.', ) : i18n( 'No valid registry API keys are stored yet. Run Create Registry API Keys first (both keys must be non-empty and different).', ), result: { type: 'group', value: [ { type: 'single', name: i18n('REGISTRY_API_KEY'), description: i18n( 'Bearer secret for intake/POST /register clients.', ), value: registryApiKey ?? '', masked: true, copyable: true, qr: false, }, { type: 'single', name: i18n('SUBSD_API_KEY'), description: i18n( 'Paste into subs Settings → Registry Server → Auth Token (subs↔registry channel).', ), value: subsdApiKey ?? '', masked: true, copyable: true, qr: false, }, ], }, } }, )