@mbc-cqrs-serverless/ui-setting 0.1.49-beta.0 → 0.1.50-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -1
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/index.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -2,9 +2,201 @@
|
|
|
2
2
|
|
|
3
3
|
# MBC CQRS serverless framework UI Setting package
|
|
4
4
|
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
The UI Setting package manages user interface configuration and preferences in the MBC CQRS Serverless framework. It provides:
|
|
8
|
+
|
|
9
|
+
- User interface configuration management
|
|
10
|
+
- Theme and layout settings
|
|
11
|
+
- User preferences storage
|
|
12
|
+
- Multi-tenant UI customization
|
|
13
|
+
- Dynamic UI configuration updates
|
|
14
|
+
- Settings synchronization
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @mbc-cqrs-serverless/ui-setting
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Basic Setup
|
|
25
|
+
|
|
26
|
+
1. Import and configure the UI Setting module:
|
|
27
|
+
```typescript
|
|
28
|
+
import { UiSettingModule } from '@mbc-cqrs-serverless/ui-setting';
|
|
29
|
+
import { Module } from '@nestjs/common';
|
|
30
|
+
|
|
31
|
+
@Module({
|
|
32
|
+
imports: [
|
|
33
|
+
UiSettingModule.forRoot({
|
|
34
|
+
tableName: 'ui-settings',
|
|
35
|
+
region: 'ap-northeast-1',
|
|
36
|
+
}),
|
|
37
|
+
],
|
|
38
|
+
})
|
|
39
|
+
export class AppModule {}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Managing Settings
|
|
43
|
+
|
|
44
|
+
1. Define settings schema:
|
|
45
|
+
```typescript
|
|
46
|
+
import { SettingSchema } from '@mbc-cqrs-serverless/ui-setting';
|
|
47
|
+
|
|
48
|
+
const themeSettings: SettingSchema = {
|
|
49
|
+
name: 'theme',
|
|
50
|
+
properties: {
|
|
51
|
+
mode: { type: 'string', enum: ['light', 'dark'] },
|
|
52
|
+
primaryColor: { type: 'string' },
|
|
53
|
+
fontSize: { type: 'number' },
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
2. Use the settings service:
|
|
59
|
+
```typescript
|
|
60
|
+
import { SettingService } from '@mbc-cqrs-serverless/ui-setting';
|
|
61
|
+
|
|
62
|
+
@Injectable()
|
|
63
|
+
export class ThemeService {
|
|
64
|
+
constructor(
|
|
65
|
+
private readonly settingService: SettingService
|
|
66
|
+
) {}
|
|
67
|
+
|
|
68
|
+
async getUserTheme(userId: string): Promise<ThemeSettings> {
|
|
69
|
+
return this.settingService.getUserSettings(userId, 'theme');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async updateUserTheme(
|
|
73
|
+
userId: string,
|
|
74
|
+
theme: ThemeSettings
|
|
75
|
+
): Promise<void> {
|
|
76
|
+
await this.settingService.updateUserSettings(
|
|
77
|
+
userId,
|
|
78
|
+
'theme',
|
|
79
|
+
theme
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Multi-tenant Configuration
|
|
86
|
+
|
|
87
|
+
1. Manage tenant-level settings:
|
|
88
|
+
```typescript
|
|
89
|
+
@Injectable()
|
|
90
|
+
export class TenantConfigService {
|
|
91
|
+
constructor(
|
|
92
|
+
private readonly settingService: SettingService
|
|
93
|
+
) {}
|
|
94
|
+
|
|
95
|
+
@UseTenant()
|
|
96
|
+
async getTenantLayout(
|
|
97
|
+
@TenantContext() tenantId: string
|
|
98
|
+
): Promise<LayoutSettings> {
|
|
99
|
+
return this.settingService.getTenantSettings(
|
|
100
|
+
tenantId,
|
|
101
|
+
'layout'
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Dynamic Updates
|
|
108
|
+
|
|
109
|
+
1. Listen for setting changes:
|
|
110
|
+
```typescript
|
|
111
|
+
import { SettingUpdateEvent } from '@mbc-cqrs-serverless/ui-setting';
|
|
112
|
+
|
|
113
|
+
@EventsHandler(SettingUpdateEvent)
|
|
114
|
+
export class SettingUpdateHandler implements IEventHandler<SettingUpdateEvent> {
|
|
115
|
+
async handle(event: SettingUpdateEvent): Promise<void> {
|
|
116
|
+
// Handle setting update
|
|
117
|
+
if (event.settingType === 'theme') {
|
|
118
|
+
await this.notifyThemeChange(event.userId);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### User Preferences
|
|
125
|
+
|
|
126
|
+
1. Manage user preferences:
|
|
127
|
+
```typescript
|
|
128
|
+
@Injectable()
|
|
129
|
+
export class PreferenceService {
|
|
130
|
+
constructor(
|
|
131
|
+
private readonly settingService: SettingService
|
|
132
|
+
) {}
|
|
133
|
+
|
|
134
|
+
async getUserPreferences(userId: string): Promise<UserPreferences> {
|
|
135
|
+
const [theme, layout, notifications] = await Promise.all([
|
|
136
|
+
this.settingService.getUserSettings(userId, 'theme'),
|
|
137
|
+
this.settingService.getUserSettings(userId, 'layout'),
|
|
138
|
+
this.settingService.getUserSettings(userId, 'notifications'),
|
|
139
|
+
]);
|
|
140
|
+
|
|
141
|
+
return { theme, layout, notifications };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Layout Management
|
|
147
|
+
|
|
148
|
+
1. Configure layout settings:
|
|
149
|
+
```typescript
|
|
150
|
+
@Injectable()
|
|
151
|
+
export class LayoutService {
|
|
152
|
+
constructor(
|
|
153
|
+
private readonly settingService: SettingService
|
|
154
|
+
) {}
|
|
155
|
+
|
|
156
|
+
async updateLayout(
|
|
157
|
+
userId: string,
|
|
158
|
+
layout: LayoutConfig
|
|
159
|
+
): Promise<void> {
|
|
160
|
+
await this.settingService.updateUserSettings(
|
|
161
|
+
userId,
|
|
162
|
+
'layout',
|
|
163
|
+
{
|
|
164
|
+
sidebar: layout.sidebar,
|
|
165
|
+
toolbar: layout.toolbar,
|
|
166
|
+
content: layout.content,
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Settings Synchronization
|
|
174
|
+
|
|
175
|
+
1. Implement real-time updates:
|
|
176
|
+
```typescript
|
|
177
|
+
@WebSocketGateway()
|
|
178
|
+
export class SettingGateway {
|
|
179
|
+
@SubscribeMessage('syncSettings')
|
|
180
|
+
async handleSync(
|
|
181
|
+
client: Socket,
|
|
182
|
+
userId: string
|
|
183
|
+
): Promise<void> {
|
|
184
|
+
const settings = await this.settingService.getAllUserSettings(
|
|
185
|
+
userId
|
|
186
|
+
);
|
|
187
|
+
client.emit('settingsUpdate', settings);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
5
192
|
## Documentation
|
|
6
193
|
|
|
7
|
-
Visit https://mbc-cqrs-serverless.mbc-net.com/ to view the full documentation
|
|
194
|
+
Visit https://mbc-cqrs-serverless.mbc-net.com/ to view the full documentation, including:
|
|
195
|
+
- Configuration options
|
|
196
|
+
- Theme customization
|
|
197
|
+
- Layout management
|
|
198
|
+
- User preferences
|
|
199
|
+
- API reference
|
|
8
200
|
|
|
9
201
|
## License
|
|
10
202
|
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const MASTER_PK_PREFIX = "MASTER";
|
|
2
|
-
export declare const SETTING_SK_PREFIX = "
|
|
2
|
+
export declare const SETTING_SK_PREFIX = "MASTER_SETTING";
|
|
3
3
|
export declare function generateSettingPk(tenantCode: string): string;
|
|
4
4
|
export declare function generateSettingSk(code: string): string;
|
|
5
5
|
export declare function generateDataSettingSk(settingCode: string, code: string): string;
|
package/dist/helpers/index.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.parseDataSettingSk = parseDataSettingSk;
|
|
|
8
8
|
exports.parsePk = parsePk;
|
|
9
9
|
const core_1 = require("@mbc-cqrs-serverless/core");
|
|
10
10
|
exports.MASTER_PK_PREFIX = 'MASTER';
|
|
11
|
-
exports.SETTING_SK_PREFIX = '
|
|
11
|
+
exports.SETTING_SK_PREFIX = 'MASTER_SETTING';
|
|
12
12
|
function generateSettingPk(tenantCode) {
|
|
13
13
|
return `${exports.MASTER_PK_PREFIX}${core_1.KEY_SEPARATOR}${tenantCode}`;
|
|
14
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbc-cqrs-serverless/ui-setting",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.50-beta.0",
|
|
4
4
|
"description": "Setting master data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mbc",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"fargate",
|
|
16
16
|
"step-functions",
|
|
17
17
|
"sqs",
|
|
18
|
-
"
|
|
18
|
+
"typescript"
|
|
19
19
|
],
|
|
20
20
|
"main": "./dist/index.js",
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@mbc-cqrs-serverless/core": "^0.1.
|
|
44
|
+
"@mbc-cqrs-serverless/core": "^0.1.50-beta.0"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "d61475400eb1b00a1c427769875d2f056e48c73c"
|
|
47
47
|
}
|