import { AzureService, ServiceResult } from './base-service.js';
import { CacheKeys } from '../lib/cache.js';
interface AppConfigStore {
name: string;
resourceGroup: string;
location: string;
endpoint: string;
sku: { name: string };
}
interface KeyValue {
key: string;
value: string;
label: string;
contentType: string;
locked: boolean;
lastModified: string;
}
export class AppConfigService extends AzureService {
readonly serviceName = 'App Configuration';
readonly cliPrefix = 'appconfig';
async list(resourceGroup?: string): Promise<ServiceResult<AppConfigStore[]>> {
const cacheKey = CacheKeys.service('appconfig', 'stores', resourceGroup ?? '');
return this.cachedExecute(cacheKey, async () => {
const opts: Record<string, string> = {};
if (resourceGroup) opts['resource-group'] = resourceGroup;
const result = await this.execute('list', opts);
return this.toResult<AppConfigStore[]>(result);
});
}
async getStore(storeName: string, resourceGroup: string): Promise<ServiceResult> {
const result = await this.execute('show', {
'name': storeName,
'resource-group': resourceGroup
});
return this.toResult(result);
}
async listKeyValues(storeName: string, label?: string): Promise<ServiceResult<KeyValue[]>> {
const cacheKey = CacheKeys.service('appconfig', 'kv', storeName, label ?? '');
return this.cachedExecute(cacheKey, async () => {
const opts: Record<string, string> = { 'name': storeName };
if (label) opts['label'] = label;
const result = await this.execute('kv list', opts);
return this.toResult<KeyValue[]>(result);
});
}
async getKeyValue(storeName: string, key: string, label?: string): Promise<ServiceResult> {
const opts: Record<string, string> = { 'name': storeName, 'key': key };
if (label) opts['label'] = label;
const result = await this.execute('kv show', opts);
return this.toResult(result);
}
async setKeyValue(storeName: string, key: string, value: string, label?: string): Promise<ServiceResult> {
const opts: Record<string, string> = { 'name': storeName, 'key': key, 'value': value, 'yes': '' };
if (label) opts['label'] = label;
const result = await this.execute('kv set', opts);
return this.toResult(result);
}
async lockKeyValue(storeName: string, key: string, label?: string): Promise<ServiceResult> {
const opts: Record<string, string> = { 'name': storeName, 'key': key, 'yes': '' };
if (label) opts['label'] = label;
const result = await this.execute('kv lock', opts);
return this.toResult(result);
}
async unlockKeyValue(storeName: string, key: string, label?: string): Promise<ServiceResult> {
const opts: Record<string, string> = { 'name': storeName, 'key': key, 'yes': '' };
if (label) opts['label'] = label;
const result = await this.execute('kv unlock', opts);
return this.toResult(result);
}
}