import { storeJson } from '../fileModels/storeJson' import { i18n } from '../i18n' import { sdk } from '../sdk' import { generateRegistryApiKeys } from '../utils' export const createRegistryApiKeys = sdk.Action.withoutInput( // id 'create-registry-api-keys', // metadata async ({ effects }) => ({ name: i18n('Create Registry API Keys'), description: i18n( 'Generate (or rotate) REGISTRY_API_KEY and SUBSD_API_KEY for the embedded registry-server. Both are required and must differ. Put SUBSD_API_KEY in subs Settings → Registry Server → Auth Token. REGISTRY_API_KEY is for intake clients calling POST /register. Saving restarts the service so registry-server picks up the new keys.', ), warning: null, allowedStatuses: 'any', group: null, visibility: 'enabled', }), // run async ({ effects }) => { const { registryApiKey, subsdApiKey } = generateRegistryApiKeys() await storeJson.merge(effects, { registryApiKey, subsdApiKey }) return { version: '1', title: i18n('Success'), message: i18n( 'Registry API keys saved. Paste SUBSD_API_KEY into subs Settings → Registry Server → Auth Token, then click Test. Use REGISTRY_API_KEY as the Bearer token for POST /register clients. The service is restarting so registry-server picks up the new keys.', ), 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, }, ], }, } }, )