import { storeJson } from '../fileModels/storeJson' import { actionGroups } from '../actionGroups' import { i18n } from '../i18n' import { sdk } from '../sdk' import { spacedRpcPort } from '../utils' export const showSpacedCredentials = sdk.Action.withoutInput( // id 'show-spaced-credentials', // metadata async ({ effects }) => ({ name: i18n('Show Spaces API Credentials'), description: i18n( 'Display the spaced RPC username and password (SPACED_RPC_USER / SPACED_RPC_PASSWORD) used to authenticate against the Spaces API.', ), warning: null, allowedStatuses: 'any', group: actionGroups.spaced, visibility: 'enabled', }), // run async ({ effects }) => { const spacedAuth = await storeJson.read((s) => s.spacedAuth).once() const username = spacedAuth?.username ?? '' const password = spacedAuth?.password ?? '' const url = spacedAuth ? `http://${spacedAuth.username}:${spacedAuth.password}@127.0.0.1:${spacedRpcPort}` : '' return { version: '1', title: i18n('Show Spaces API Credentials'), message: i18n( 'Use these credentials to authenticate against the spaced JSON-RPC (the Spaces API). The connection URL shown uses the loopback address; for external access, substitute the host StartOS exposes for the Spaces API interface.', ), result: { type: 'group', value: [ { type: 'single', name: i18n('SPACED_RPC_USER'), description: null, value: username, masked: false, copyable: true, qr: false, }, { type: 'single', name: i18n('SPACED_RPC_PASSWORD'), description: null, value: password, masked: true, copyable: true, qr: false, }, { type: 'single', name: i18n('Connection URL'), description: null, value: url, masked: true, copyable: true, qr: false, }, ], }, } }, )