SettingsStoreService
SettingsStoreService
The SettingsStoreService provides a flexible settings storage system with support for scoping, permissions, and validation. It allows plugins and the core system to store and retrieve configuration data with fine-grained control over access and isolation.
Usage
Values are automatically scoped according to their field configuration:
Example
// In a service
const userTheme = await this.settingsStoreService.get('dashboard.theme', ctx);
await this.settingsStoreService.set('dashboard.theme', 'dark', ctx);
// Get multiple values
const settings = await this.settingsStoreService.getMany([
'dashboard.theme',
'dashboard.tableFilters'
], ctx);
class SettingsStoreService implements OnModuleInit {
constructor(connection: TransactionalConnection, moduleRef: ModuleRef, configService: ConfigService)
onModuleInit() => ;
register(registration: SettingsStoreRegistration) => void;
get(key: string, ctx: RequestContext) => Promise<T | undefined>;
getMany(keys: string[], ctx: RequestContext) => Promise<Record<string, JsonCompatible<any>>>;
set(key: string, value: T, ctx: RequestContext) => Promise<SetSettingsStoreValueResult>;
setMany(values: Record<string, JsonCompatible<any>>, ctx: RequestContext) => Promise<SetSettingsStoreValueResult[]>;
getFieldDefinition(key: string) => SettingsStoreFieldConfig | undefined;
validateValue(key: string, value: any, ctx: RequestContext) => Promise<string | void>;
findOrphanedEntries(options: CleanupOrphanedSettingsStoreEntriesOptions = {}) => Promise<OrphanedSettingsStoreEntry[]>;
cleanupOrphanedEntries(options: CleanupOrphanedSettingsStoreEntriesOptions = {}) => Promise<CleanupOrphanedSettingsStoreEntriesResult>;
}
- Implements:
OnModuleInit
constructor
(connection: TransactionalConnection, moduleRef: ModuleRef, configService: ConfigService) => SettingsStoreService
onModuleInit
() =>
register
(registration: SettingsStoreRegistration) => void
Register settings store fields. This is typically called during application bootstrap when processing the VendureConfig.
get
(key: string, ctx: RequestContext) => Promise<T | undefined>
Get a value for the specified key. The value is automatically scoped according to the field's scope configuration.
getMany
(keys: string[], ctx: RequestContext) => Promise<Record<string, JsonCompatible<any>>>
Get multiple values efficiently. Each key is scoped according to its individual field configuration.
set
(key: string, value: T, ctx: RequestContext) => Promise<SetSettingsStoreValueResult>
Set a value for the specified key with structured result feedback. This version returns detailed information about the success or failure of the operation instead of throwing errors.
setMany
(values: Record<string, JsonCompatible<any>>, ctx: RequestContext) => Promise<SetSettingsStoreValueResult[]>
Set multiple values with structured result feedback for each operation. This method will not throw errors but will return detailed results for each key-value pair.
getFieldDefinition
(key: string) => SettingsStoreFieldConfig | undefined
Get the field configuration for a key.
validateValue
(key: string, value: any, ctx: RequestContext) => Promise<string | void>
Validate a value against its field definition.
findOrphanedEntries
(options: CleanupOrphanedSettingsStoreEntriesOptions = {}) => Promise<OrphanedSettingsStoreEntry[]>
Find orphaned settings store entries that no longer have corresponding field definitions.
cleanupOrphanedEntries
(options: CleanupOrphanedSettingsStoreEntriesOptions = {}) => Promise<CleanupOrphanedSettingsStoreEntriesResult>
Clean up orphaned settings store entries from the database.