Skip to main content

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);
Signature
class SettingsStoreService implements OnModuleInit {
constructor(connection: TransactionalConnection, moduleRef: ModuleRef, configService: ConfigService)
onModuleInit() => ;
register(registration: SettingsStoreRegistration) => void;
get(ctx: RequestContext, key: string) => Promise<T | undefined>;
get(key: string, ctx: RequestContext) => Promise<T | undefined>;
get(keyOrCtx: string | RequestContext, ctxOrKey: RequestContext | string) => Promise<T | undefined>;
getMany(ctx: RequestContext, keys: string[]) => Promise<Record<string, JsonCompatible<any>>>;
getMany(keys: string[], ctx: RequestContext) => Promise<Record<string, JsonCompatible<any>>>;
getMany(keysOrCtx: string[] | RequestContext, ctxOrKeys: RequestContext | string[]) => Promise<Record<string, JsonCompatible<any>>>;
set(ctx: RequestContext, key: string, value: T) => Promise<SetSettingsStoreValueResult>;
set(key: string, value: T, ctx: RequestContext) => Promise<SetSettingsStoreValueResult>;
set(keyOrCtx: string | RequestContext, keyOrValue: string | T, ctxOrValue: RequestContext | T) => Promise<SetSettingsStoreValueResult>;
setMany(ctx: RequestContext, values: Record<string, JsonCompatible<any>>) => Promise<SetSettingsStoreValueResult[]>;
setMany(values: Record<string, JsonCompatible<any>>, ctx: RequestContext) => Promise<SetSettingsStoreValueResult[]>;
setMany(valuesOrCtx: Record<string, JsonCompatible<any>> | RequestContext, ctxOrValues: RequestContext | Record<string, JsonCompatible<any>>) => 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>;
hasPermission(ctx: RequestContext, key: string) => boolean;
isReadonly(key: string) => boolean;
}
  • Implements: OnModuleInit

constructor

method
(connection: TransactionalConnection, moduleRef: ModuleRef, configService: ConfigService) => SettingsStoreService

onModuleInit

method
() =>

register

method
(registration: SettingsStoreRegistration) => void

Register settings store fields. This is typically called during application bootstrap when processing the VendureConfig.

get

method
(ctx: RequestContext, key: string) => Promise<T | undefined>

Get a value for the specified key. The value is automatically scoped according to the field's scope configuration.

get

method
(key: string, ctx: RequestContext) => Promise<T | undefined>

get

method
(keyOrCtx: string | RequestContext, ctxOrKey: RequestContext | string) => Promise<T | undefined>

getMany

method
(ctx: RequestContext, keys: string[]) => Promise<Record<string, JsonCompatible<any>>>

Get multiple values efficiently. Each key is scoped according to its individual field configuration.

getMany

method
(keys: string[], ctx: RequestContext) => Promise<Record<string, JsonCompatible<any>>>

getMany

method
(keysOrCtx: string[] | RequestContext, ctxOrKeys: RequestContext | string[]) => Promise<Record<string, JsonCompatible<any>>>

set

method
(ctx: RequestContext, key: string, value: T) => 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.

set

method
(key: string, value: T, ctx: RequestContext) => Promise<SetSettingsStoreValueResult>

set

method
(keyOrCtx: string | RequestContext, keyOrValue: string | T, ctxOrValue: RequestContext | T) => Promise<SetSettingsStoreValueResult>

setMany

method
(ctx: RequestContext, values: Record<string, JsonCompatible<any>>) => 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.

setMany

method
(values: Record<string, JsonCompatible<any>>, ctx: RequestContext) => Promise<SetSettingsStoreValueResult[]>

setMany

method
(valuesOrCtx: Record<string, JsonCompatible<any>> | RequestContext, ctxOrValues: RequestContext | Record<string, JsonCompatible<any>>) => Promise<SetSettingsStoreValueResult[]>

getFieldDefinition

method
(key: string) => SettingsStoreFieldConfig | undefined

Get the field configuration for a key.

validateValue

method
(key: string, value: any, ctx: RequestContext) => Promise<string | void>

Validate a value against its field definition.

findOrphanedEntries

Find orphaned settings store entries that no longer have corresponding field definitions.

cleanupOrphanedEntries

Clean up orphaned settings store entries from the database.

hasPermission

method
(ctx: RequestContext, key: string) => boolean

Check if the current user has permission to access a field. This is not called internally in the get and set methods, so should be used by any methods which are exposing these methods via the GraphQL APIs.

isReadonly

method
(key: string) => boolean

Returns true if the settings field has the readonly: true configuration.