@yartsun/chat-widget-types 1.0.2 → 1.0.5
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 +214 -115
- package/dist/config.types.d.ts +111 -44
- package/dist/config.types.d.ts.map +1 -1
- package/dist/config.types.js +2 -67
- package/dist/config.types.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/migration/commands.d.ts +59 -0
- package/dist/migration/commands.d.ts.map +1 -0
- package/dist/migration/commands.js +286 -0
- package/dist/migration/commands.js.map +1 -0
- package/dist/migration/examples.d.ts +198 -0
- package/dist/migration/examples.d.ts.map +1 -0
- package/dist/migration/examples.js +439 -0
- package/dist/migration/examples.js.map +1 -0
- package/dist/migration/facade.d.ts +85 -0
- package/dist/migration/facade.d.ts.map +1 -0
- package/dist/migration/facade.js +168 -0
- package/dist/migration/facade.js.map +1 -0
- package/dist/migration/migrator.d.ts +49 -0
- package/dist/migration/migrator.d.ts.map +1 -0
- package/dist/migration/migrator.js +245 -0
- package/dist/migration/migrator.js.map +1 -0
- package/dist/migration/strategies.d.ts +85 -0
- package/dist/migration/strategies.d.ts.map +1 -0
- package/dist/migration/strategies.js +217 -0
- package/dist/migration/strategies.js.map +1 -0
- package/dist/migration/types.d.ts +196 -0
- package/dist/migration/types.d.ts.map +1 -0
- package/dist/migration/types.js +5 -0
- package/dist/migration/types.js.map +1 -0
- package/dist/utils.d.ts +1 -11
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +3 -127
- package/dist/utils.js.map +1 -1
- package/package.json +13 -4
- package/src/config.types.ts +132 -118
- package/src/index.ts +26 -0
- package/src/migration/commands.ts +314 -0
- package/src/migration/examples.ts +471 -0
- package/src/migration/facade.ts +196 -0
- package/src/migration/migrator.ts +361 -0
- package/src/migration/strategies.ts +249 -0
- package/src/migration/types.ts +182 -0
- package/src/utils.ts +3 -143
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Типы для системы миграции конфигураций виджета чата
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { WidgetConfig } from '../config.types'
|
|
6
|
+
|
|
7
|
+
/** Версии конфигурации */
|
|
8
|
+
export type ConfigVersion = '1.0' | '2.0' | '3.0'
|
|
9
|
+
|
|
10
|
+
/** Результат миграции */
|
|
11
|
+
export interface MigrationResult<T = WidgetConfig> {
|
|
12
|
+
success: boolean
|
|
13
|
+
data?: T
|
|
14
|
+
errors: string[]
|
|
15
|
+
warnings: string[]
|
|
16
|
+
fromVersion: ConfigVersion
|
|
17
|
+
toVersion: ConfigVersion
|
|
18
|
+
appliedStrategies: string[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Контекст миграции */
|
|
22
|
+
export interface MigrationContext {
|
|
23
|
+
fromVersion: ConfigVersion
|
|
24
|
+
toVersion: ConfigVersion
|
|
25
|
+
config: any
|
|
26
|
+
options?: MigrationOptions
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Опции миграции */
|
|
30
|
+
export interface MigrationOptions {
|
|
31
|
+
/** Строгий режим - останавливаться на ошибках */
|
|
32
|
+
strict?: boolean
|
|
33
|
+
/** Сохранять неизвестные поля */
|
|
34
|
+
preserveUnknown?: boolean
|
|
35
|
+
/** Логировать процесс миграции */
|
|
36
|
+
verbose?: boolean
|
|
37
|
+
/** Применить только определенные стратегии */
|
|
38
|
+
onlyStrategies?: string[]
|
|
39
|
+
/** Исключить определенные стратегии */
|
|
40
|
+
excludeStrategies?: string[]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Абстрактная стратегия миграции */
|
|
44
|
+
export interface MigrationStrategy {
|
|
45
|
+
/** Уникальное имя стратегии */
|
|
46
|
+
name: string
|
|
47
|
+
/** Описание что делает стратегия */
|
|
48
|
+
description: string
|
|
49
|
+
/** Версии для которых применяется */
|
|
50
|
+
appliesTo: {
|
|
51
|
+
from: ConfigVersion
|
|
52
|
+
to: ConfigVersion
|
|
53
|
+
}
|
|
54
|
+
/** Проверка применимости стратегии */
|
|
55
|
+
canApply(context: MigrationContext): boolean
|
|
56
|
+
/** Применение стратегии */
|
|
57
|
+
apply(context: MigrationContext): MigrationStepResult
|
|
58
|
+
/** Откат стратегии (если возможен) */
|
|
59
|
+
rollback?(context: MigrationContext): MigrationStepResult
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Результат шага миграции */
|
|
63
|
+
export interface MigrationStepResult {
|
|
64
|
+
success: boolean
|
|
65
|
+
data?: any
|
|
66
|
+
errors: string[]
|
|
67
|
+
warnings: string[]
|
|
68
|
+
modified: boolean
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Команда миграции */
|
|
72
|
+
export interface MigrationCommand {
|
|
73
|
+
/** Имя команды */
|
|
74
|
+
name: string
|
|
75
|
+
/** Описание команды */
|
|
76
|
+
description: string
|
|
77
|
+
/** Выполнить команду */
|
|
78
|
+
execute(config: any, options?: any): MigrationStepResult
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Детектор версии конфигурации */
|
|
82
|
+
export interface VersionDetector {
|
|
83
|
+
/** Определить версию конфигурации */
|
|
84
|
+
detect(config: any): ConfigVersion | null
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Валидатор конфигурации */
|
|
88
|
+
export interface ConfigValidator {
|
|
89
|
+
/** Валидировать конфигурацию для версии */
|
|
90
|
+
validate(config: any, version: ConfigVersion): {
|
|
91
|
+
isValid: boolean
|
|
92
|
+
errors: string[]
|
|
93
|
+
warnings: string[]
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Схема конфигурации для конкретной версии */
|
|
98
|
+
export interface ConfigSchema {
|
|
99
|
+
version: ConfigVersion
|
|
100
|
+
schema: any // JSON Schema или подобное
|
|
101
|
+
required: string[]
|
|
102
|
+
optional: string[]
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Отчет о миграции */
|
|
106
|
+
export interface MigrationReport {
|
|
107
|
+
timestamp: Date
|
|
108
|
+
fromVersion: ConfigVersion
|
|
109
|
+
toVersion: ConfigVersion
|
|
110
|
+
success: boolean
|
|
111
|
+
duration: number
|
|
112
|
+
appliedStrategies: Array<{
|
|
113
|
+
name: string
|
|
114
|
+
success: boolean
|
|
115
|
+
errors: string[]
|
|
116
|
+
warnings: string[]
|
|
117
|
+
}>
|
|
118
|
+
totalErrors: number
|
|
119
|
+
totalWarnings: number
|
|
120
|
+
summary: string
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Логгер для миграции */
|
|
124
|
+
export interface MigrationLogger {
|
|
125
|
+
info(message: string, context?: any): void
|
|
126
|
+
warn(message: string, context?: any): void
|
|
127
|
+
error(message: string, context?: any): void
|
|
128
|
+
debug(message: string, context?: any): void
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Базовые типы для различных версий конфигурации */
|
|
132
|
+
|
|
133
|
+
/** Конфигурация V1 */
|
|
134
|
+
export interface ConfigV1 {
|
|
135
|
+
settings: {
|
|
136
|
+
widgetTitle: string
|
|
137
|
+
welcomeMessage: string
|
|
138
|
+
bgChat: string
|
|
139
|
+
gapMessageLine: number
|
|
140
|
+
paddingChat: number
|
|
141
|
+
fontFamily: string
|
|
142
|
+
borderRadius: string
|
|
143
|
+
launchView: string
|
|
144
|
+
letterSpacing: number
|
|
145
|
+
logo: string
|
|
146
|
+
fontWeight: number
|
|
147
|
+
}
|
|
148
|
+
sections: {
|
|
149
|
+
top: {
|
|
150
|
+
params: { size: string }
|
|
151
|
+
chipWidgetTitle: { color: string; bgColor: string }
|
|
152
|
+
btnClose: { color: string; bgColor: string }
|
|
153
|
+
}
|
|
154
|
+
inside: {
|
|
155
|
+
params: { size: string }
|
|
156
|
+
messageUser: { color: string; bgColor: string }
|
|
157
|
+
messageBot: { color: string; bgColor: string }
|
|
158
|
+
welcomeMessage: { color: string }
|
|
159
|
+
}
|
|
160
|
+
bottom: {
|
|
161
|
+
params: { size: string }
|
|
162
|
+
inputSend: { color: string; bgColor: string }
|
|
163
|
+
btnSend: { color: string; bgColor: string; type: string }
|
|
164
|
+
activeBtn: { color: string; bgColor: string }
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Конфигурация V2 - расширенная версия */
|
|
170
|
+
export interface ConfigV2 extends WidgetConfig {}
|
|
171
|
+
|
|
172
|
+
/** Маппинг типов конфигурации по версиям */
|
|
173
|
+
export type ConfigByVersion = {
|
|
174
|
+
'1.0': ConfigV1
|
|
175
|
+
'2.0': ConfigV2
|
|
176
|
+
'3.0': WidgetConfig // Для будущих версий
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Фабрика для создания пустых конфигураций */
|
|
180
|
+
export type ConfigFactory = {
|
|
181
|
+
[V in ConfigVersion]: () => ConfigByVersion[V]
|
|
182
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -1,143 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
general: GeneralSettings
|
|
5
|
-
shapes: ShapesSettings
|
|
6
|
-
colors: EmittedColorElement
|
|
7
|
-
font: FontSettings
|
|
8
|
-
} => ({
|
|
9
|
-
// Общие настройки
|
|
10
|
-
general: {
|
|
11
|
-
widgetTitle: config.settings.widgetTitle,
|
|
12
|
-
welcomeMessage: config.settings.welcomeMessage,
|
|
13
|
-
launchView: config.settings.launchView,
|
|
14
|
-
logo: config.settings.logo,
|
|
15
|
-
} as GeneralSettings,
|
|
16
|
-
|
|
17
|
-
// Настройки форм и размеров
|
|
18
|
-
shapes: {
|
|
19
|
-
gapMessageLine: config.settings.gapMessageLine,
|
|
20
|
-
paddingChat: config.settings.paddingChat,
|
|
21
|
-
fontFamily: config.settings.fontFamily,
|
|
22
|
-
borderRadius: config.settings.borderRadius,
|
|
23
|
-
bottomSize: config.sections.bottom.params.size,
|
|
24
|
-
sendButtonType: config.sections.bottom.btnSend.type as BtnType,
|
|
25
|
-
headerSize: config.sections.top.params.size,
|
|
26
|
-
messageSize: config.sections.inside.params.size,
|
|
27
|
-
} as ShapesSettings,
|
|
28
|
-
|
|
29
|
-
// Настройки цветов
|
|
30
|
-
colors: {
|
|
31
|
-
bgChat: { bgColor: config.settings.bgChat },
|
|
32
|
-
welcomeMessage: { color: config.sections.inside?.welcomeMessage?.color || '#fff' },
|
|
33
|
-
chipWidgetTitle: {
|
|
34
|
-
color: config.sections.top.chipWidgetTitle.color,
|
|
35
|
-
bgColor: config.sections.top.chipWidgetTitle.bgColor,
|
|
36
|
-
},
|
|
37
|
-
btnClose: {
|
|
38
|
-
color: config.sections.top.btnClose.color,
|
|
39
|
-
bgColor: config.sections.top.btnClose.bgColor,
|
|
40
|
-
},
|
|
41
|
-
messageUser: {
|
|
42
|
-
color: config.sections.inside.messageUser.color,
|
|
43
|
-
bgColor: config.sections.inside.messageUser.bgColor,
|
|
44
|
-
},
|
|
45
|
-
messageBot: {
|
|
46
|
-
color: config.sections.inside.messageBot.color,
|
|
47
|
-
bgColor: config.sections.inside.messageBot.bgColor,
|
|
48
|
-
},
|
|
49
|
-
inputSend: {
|
|
50
|
-
color: config.sections.bottom.inputSend.color,
|
|
51
|
-
bgColor: config.sections.bottom.inputSend.bgColor,
|
|
52
|
-
},
|
|
53
|
-
btnSend: {
|
|
54
|
-
color: config.sections.bottom.btnSend.color,
|
|
55
|
-
bgColor: config.sections.bottom.btnSend.bgColor,
|
|
56
|
-
},
|
|
57
|
-
activeBtn: {
|
|
58
|
-
color: config.sections.bottom.activeBtn.color,
|
|
59
|
-
bgColor: config.sections.bottom.activeBtn.bgColor,
|
|
60
|
-
},
|
|
61
|
-
} as EmittedColorElement,
|
|
62
|
-
|
|
63
|
-
// Шрифт отдельно
|
|
64
|
-
font: {
|
|
65
|
-
fontFamily: config.settings.fontFamily,
|
|
66
|
-
letterSpacing: config.settings.letterSpacing,
|
|
67
|
-
} as FontSettings,
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Функция для сборки полного конфига из отдельных частей
|
|
73
|
-
*/
|
|
74
|
-
export function buildWidgetConfig(
|
|
75
|
-
general: GeneralSettings,
|
|
76
|
-
shapes: ShapesSettings,
|
|
77
|
-
colors: EmittedColorElement,
|
|
78
|
-
fonts: FontSettings
|
|
79
|
-
): WidgetConfig {
|
|
80
|
-
return {
|
|
81
|
-
settings: {
|
|
82
|
-
widgetTitle: general.widgetTitle,
|
|
83
|
-
welcomeMessage: general.welcomeMessage,
|
|
84
|
-
launchView: general.launchView,
|
|
85
|
-
bgChat: colors.bgChat.bgColor || colors.bgChat.color || DEFAULT_CONFIG.settings.bgChat,
|
|
86
|
-
gapMessageLine: shapes.gapMessageLine,
|
|
87
|
-
paddingChat: shapes.paddingChat,
|
|
88
|
-
borderRadius: shapes.borderRadius,
|
|
89
|
-
fontFamily: fonts.fontFamily,
|
|
90
|
-
letterSpacing: fonts.letterSpacing,
|
|
91
|
-
logo: general.logo,
|
|
92
|
-
},
|
|
93
|
-
sections: {
|
|
94
|
-
top: {
|
|
95
|
-
params: {
|
|
96
|
-
size: shapes.headerSize,
|
|
97
|
-
},
|
|
98
|
-
chipWidgetTitle: {
|
|
99
|
-
color: colors.chipWidgetTitle.color || DEFAULT_CONFIG.sections.top.chipWidgetTitle.color,
|
|
100
|
-
bgColor: colors.chipWidgetTitle.bgColor || DEFAULT_CONFIG.sections.top.chipWidgetTitle.bgColor,
|
|
101
|
-
},
|
|
102
|
-
btnClose: {
|
|
103
|
-
color: colors.btnClose.color || DEFAULT_CONFIG.sections.top.btnClose.color,
|
|
104
|
-
bgColor: colors.btnClose.bgColor || DEFAULT_CONFIG.sections.top.btnClose.bgColor,
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
inside: {
|
|
108
|
-
params: {
|
|
109
|
-
size: shapes.messageSize,
|
|
110
|
-
},
|
|
111
|
-
messageUser: {
|
|
112
|
-
color: colors.messageUser.color || DEFAULT_CONFIG.sections.inside.messageUser.color,
|
|
113
|
-
bgColor: colors.messageUser.bgColor || DEFAULT_CONFIG.sections.inside.messageUser.bgColor,
|
|
114
|
-
},
|
|
115
|
-
messageBot: {
|
|
116
|
-
color: colors.messageBot.color || DEFAULT_CONFIG.sections.inside.messageBot.color,
|
|
117
|
-
bgColor: colors.messageBot.bgColor || DEFAULT_CONFIG.sections.inside.messageBot.bgColor,
|
|
118
|
-
},
|
|
119
|
-
welcomeMessage: {
|
|
120
|
-
color: colors.welcomeMessage.color || DEFAULT_CONFIG.sections.inside.welcomeMessage.color,
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
bottom: {
|
|
124
|
-
params: {
|
|
125
|
-
size: shapes.bottomSize,
|
|
126
|
-
},
|
|
127
|
-
inputSend: {
|
|
128
|
-
color: colors.inputSend.color || DEFAULT_CONFIG.sections.bottom.inputSend.color,
|
|
129
|
-
bgColor: colors.inputSend.bgColor || DEFAULT_CONFIG.sections.bottom.inputSend.bgColor,
|
|
130
|
-
},
|
|
131
|
-
btnSend: {
|
|
132
|
-
color: colors.btnSend.color || DEFAULT_CONFIG.sections.bottom.btnSend.color,
|
|
133
|
-
bgColor: colors.btnSend.bgColor || DEFAULT_CONFIG.sections.bottom.btnSend.bgColor,
|
|
134
|
-
type: shapes.sendButtonType,
|
|
135
|
-
},
|
|
136
|
-
activeBtn: {
|
|
137
|
-
color: colors.activeBtn.color || DEFAULT_CONFIG.sections.bottom.activeBtn.color,
|
|
138
|
-
bgColor: colors.activeBtn.bgColor || DEFAULT_CONFIG.sections.bottom.activeBtn.bgColor,
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
}
|
|
143
|
-
}
|
|
1
|
+
export const getIcon = (icon: string) => {
|
|
2
|
+
return icon
|
|
3
|
+
}
|