Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/plugins/plugin-auth/src/auth-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
SysUser, SysSession, SysAccount, SysVerification,
SysOrganization, SysMember, SysInvitation,
SysTeam, SysTeamMember,
SysApiKey, SysTwoFactor,
SysApiKey, SysTwoFactor, SysUserPreference,
} from './objects/index.js';

/**
Expand Down Expand Up @@ -107,7 +107,7 @@ export class AuthPlugin implements Plugin {
SysUser, SysSession, SysAccount, SysVerification,
SysOrganization, SysMember, SysInvitation,
SysTeam, SysTeamMember,
SysApiKey, SysTwoFactor,
SysApiKey, SysTwoFactor, SysUserPreference,
],
});

Expand Down
1 change: 1 addition & 0 deletions packages/plugins/plugin-auth/src/objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export { SysTeamMember } from './sys-team-member.object.js';
// ── Additional Auth Objects ────────────────────────────────────────────────
export { SysApiKey } from './sys-api-key.object.js';
export { SysTwoFactor } from './sys-two-factor.object.js';
export { SysUserPreference } from './sys-user-preference.object.js';

// ── Backward Compatibility (deprecated) ────────────────────────────────────
/** @deprecated Use `SysUser` instead */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.

import { ObjectSchema, Field } from '@objectstack/spec/data';

/**
* sys_user_preference — System User Preference Object
*
* Per-user key-value preferences for storing UI state, settings, and personalization.
* Supports the User Preferences layer in the Config Resolution hierarchy
* (Runtime > User Preferences > Tenant > Env).
*
* Common use cases:
* - UI preferences: theme, locale, timezone, sidebar state
* - Feature flags: plugin.ai.auto_save, plugin.dev.debug_mode
* - User-specific settings: default_view, notifications_enabled
*
* @namespace sys
*/
export const SysUserPreference = ObjectSchema.create({
namespace: 'sys',
name: 'user_preference',
label: 'User Preference',
pluralLabel: 'User Preferences',
icon: 'settings',
isSystem: true,
description: 'Per-user key-value preferences (theme, locale, etc.)',
titleFormat: '{key}',
compactLayout: ['user_id', 'key'],

fields: {
id: Field.text({
label: 'Preference ID',
required: true,
readonly: true,
}),

created_at: Field.datetime({
label: 'Created At',
defaultValue: 'NOW()',
readonly: true,
}),

updated_at: Field.datetime({
label: 'Updated At',
defaultValue: 'NOW()',
readonly: true,
}),

user_id: Field.text({
label: 'User ID',
required: true,
maxLength: 255,
description: 'Owner user of this preference',
}),

key: Field.text({
label: 'Key',
required: true,
maxLength: 255,
description: 'Preference key (e.g., theme, locale, plugin.ai.auto_save)',
}),

value: Field.json({
label: 'Value',
description: 'Preference value (any JSON-serializable type)',
}),
},

indexes: [
{ fields: ['user_id', 'key'], unique: true },
{ fields: ['user_id'], unique: false },
],

enable: {
trackHistory: false,
searchable: false,
apiEnabled: true,
apiMethods: ['get', 'list', 'create', 'update', 'delete'],
trash: false,
mru: false,
},
});
2 changes: 2 additions & 0 deletions packages/spec/src/system/constants/system-names.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('SystemObjectName', () => {
expect(SystemObjectName.TEAM_MEMBER).toBe('sys_team_member');
expect(SystemObjectName.API_KEY).toBe('sys_api_key');
expect(SystemObjectName.TWO_FACTOR).toBe('sys_two_factor');
expect(SystemObjectName.USER_PREFERENCE).toBe('sys_user_preference');
expect(SystemObjectName.ROLE).toBe('sys_role');
expect(SystemObjectName.PERMISSION_SET).toBe('sys_permission_set');
expect(SystemObjectName.AUDIT_LOG).toBe('sys_audit_log');
Expand Down Expand Up @@ -54,6 +55,7 @@ describe('SystemObjectName', () => {
expect(keys).toContain('TEAM_MEMBER');
expect(keys).toContain('API_KEY');
expect(keys).toContain('TWO_FACTOR');
expect(keys).toContain('USER_PREFERENCE');
expect(keys).toContain('ROLE');
expect(keys).toContain('PERMISSION_SET');
expect(keys).toContain('AUDIT_LOG');
Expand Down
2 changes: 2 additions & 0 deletions packages/spec/src/system/constants/system-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export const SystemObjectName = {
API_KEY: 'sys_api_key',
/** Authentication: two-factor authentication credentials */
TWO_FACTOR: 'sys_two_factor',
/** Authentication: user preferences (theme, locale, etc.) */
USER_PREFERENCE: 'sys_user_preference',
/** Security: role definition for RBAC */
ROLE: 'sys_role',
/** Security: permission set grouping */
Expand Down
Loading