# NatsConfigStore API

Config store backed by a NATS JetStream key-value bucket.

---
Canonical: /handbook/api/classes/_purista_nats-config-store.NatsConfigStore/
Source: nats-config-store/src/NatsConfigStore.impl.ts
Format: Markdown for agents
---

Config store backed by a NATS JetStream key-value bucket.

Package: `@purista/nats-config-store`

## Signature

```typescript
class NatsConfigStore
```

## Examples

```typescript
const store = new NatsConfigStore({
  servers: 'nats://localhost:4222',
  keyValueStoreName: 'purista-config-store',
})

await store.setConfig('tenant.acme.prod.app.features', { checkout: true })
const config = await store.getConfig('tenant.acme.prod.app.features')
await store.destroy()
```

## Members

### Constructors

- `new constructor(config?: { cacheTtl: number; enableCache: boolean; enableGet: boolean; enableRemove: boolean; enableSet: boolean; keyValueStoreName: string; ... })` — Creates a NATS JetStream-backed config store.

### Properties

- `cache: ConfigStoreCacheMap` — Optional local cache used by store implementations that opt in.
- `config: { cacheTtl: number; enableCache: boolean; enableGet: boolean; enableRemove: boolean; enableSet: boolean; keyValueStoreName: string; ... }` — Store configuration including operation toggles and cache settings.
- `connection: NatsConnection | undefined` — Active NATS connection, created lazily by `getStore`.
- `kv: KV | undefined` — Cached JetStream key-value bucket handle.
- `logger: Logger` — Child logger scoped to the store name.
- `name: string` — Store name used in logs and diagnostics.
- `sc: Codec<unknown>` — JSON codec used to encode and decode values in the key-value bucket.

### Methods

- `destroy(): Promise<void>` — Drains and closes the NATS connection and clears cached handles.
- `getConfig<ConfigNames>(...configNames: ConfigNames): Promise<ObjectWithKeysFromStringArray<ConfigNames>>` — Returns the values for given config properties.
- `getConfigImpl<ConfigNames>(...stateNames: ConfigNames): Promise<ObjectWithKeysFromStringArray<ConfigNames>>` — This method must be overwritten by actual store implementation.
- `getStore(): Promise<KV>` — Returns a healthy JetStream key-value bucket handle.
- `removeConfig(configName: string): Promise<void>` — Removes the config item given by config name.
- `removeConfigImpl(stateName: string): Promise<void>` — This method must be overwritten by actual store implementation.
- `setConfig(configName: string, configValue: unknown): Promise<void>` — Sets a config value.
- `setConfigImpl(stateName: string, stateValue: unknown): Promise<void>` — This method must be overwritten by actual store implementation.
