@selfcommunity/react-core 0.4.50 → 0.4.51-alpha.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/lib/cjs/components/provider/SCUserProvider/index.js +4 -4
- package/lib/cjs/constants/Integrations.d.ts +8 -0
- package/lib/cjs/constants/Integrations.js +12 -0
- package/lib/cjs/types/context.d.ts +19 -0
- package/lib/cjs/utils/errors.d.ts +3 -0
- package/lib/cjs/utils/errors.js +6 -0
- package/lib/cjs/utils/hooks/useIsomorphicLayoutEffect.js +2 -1
- package/lib/cjs/utils/notification.js +1 -1
- package/lib/cjs/utils/validator.d.ts +65 -28
- package/lib/cjs/utils/validator.js +108 -29
- package/lib/esm/components/provider/SCUserProvider/index.js +5 -5
- package/lib/esm/constants/Integrations.d.ts +8 -0
- package/lib/esm/constants/Integrations.js +9 -0
- package/lib/esm/types/context.d.ts +19 -0
- package/lib/esm/utils/errors.d.ts +3 -0
- package/lib/esm/utils/errors.js +6 -0
- package/lib/esm/utils/hooks/useIsomorphicLayoutEffect.js +2 -1
- package/lib/esm/utils/notification.js +2 -2
- package/lib/esm/utils/validator.d.ts +65 -28
- package/lib/esm/utils/validator.js +104 -28
- package/lib/umd/react-core.js +1 -1
- package/package.json +6 -6
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { SCNotificationsMobileNativePushMessagingType, SCNotificationsType, SCNotificationsWebPushMessagingType, SCNotificationsWebSocketType, SCSettingsType } from '../types/context';
|
|
1
|
+
import { SCIntegrationsOpenAIType, SCIntegrationsType, SCNotificationsMobileNativePushMessagingType, SCNotificationsType, SCNotificationsWebPushMessagingType, SCNotificationsWebSocketType, SCSettingsType } from '../types/context';
|
|
2
2
|
import { ValidationResult } from './errors';
|
|
3
3
|
import { SCLocaleType } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* Validate session option
|
|
6
|
-
* @param
|
|
6
|
+
* @param v
|
|
7
7
|
* @return {}
|
|
8
8
|
*/
|
|
9
9
|
export declare function validateSession(v: Record<string, any>): {
|
|
@@ -14,6 +14,7 @@ export declare function validateSession(v: Record<string, any>): {
|
|
|
14
14
|
/**
|
|
15
15
|
* Validate session type
|
|
16
16
|
* @param value
|
|
17
|
+
* @param session
|
|
17
18
|
* @return {}
|
|
18
19
|
*/
|
|
19
20
|
export declare const validateSessionType: (value: any, session: any) => {
|
|
@@ -24,6 +25,7 @@ export declare const validateSessionType: (value: any, session: any) => {
|
|
|
24
25
|
/**
|
|
25
26
|
* Validate session client id
|
|
26
27
|
* @param value
|
|
28
|
+
* @param session
|
|
27
29
|
* @return {}
|
|
28
30
|
*/
|
|
29
31
|
export declare const validateSessionClientId: (value: any, session: any) => {
|
|
@@ -34,6 +36,7 @@ export declare const validateSessionClientId: (value: any, session: any) => {
|
|
|
34
36
|
/**
|
|
35
37
|
* Validate session auth token
|
|
36
38
|
* @param value
|
|
39
|
+
* @param session
|
|
37
40
|
* @return {}
|
|
38
41
|
*/
|
|
39
42
|
export declare const validateSessionAuthTokenOption: (value: any, session: any) => {
|
|
@@ -55,6 +58,7 @@ export declare const validateHandleRefreshToken: (value: any, session: any) => {
|
|
|
55
58
|
/**
|
|
56
59
|
* Validate handleLogout option
|
|
57
60
|
* @param value
|
|
61
|
+
* @param session
|
|
58
62
|
* @return {}
|
|
59
63
|
*/
|
|
60
64
|
export declare const validateHandleLogout: (value: any, session: any) => {
|
|
@@ -64,7 +68,7 @@ export declare const validateHandleLogout: (value: any, session: any) => {
|
|
|
64
68
|
};
|
|
65
69
|
/**
|
|
66
70
|
* Validate notifications option
|
|
67
|
-
* @param
|
|
71
|
+
* @param v
|
|
68
72
|
* @return {}
|
|
69
73
|
*/
|
|
70
74
|
export declare function validateNotifications(v: SCNotificationsType): {
|
|
@@ -74,8 +78,7 @@ export declare function validateNotifications(v: SCNotificationsType): {
|
|
|
74
78
|
};
|
|
75
79
|
/**
|
|
76
80
|
* Validate webSocket
|
|
77
|
-
* @param
|
|
78
|
-
* @param {}
|
|
81
|
+
* @param v
|
|
79
82
|
*/
|
|
80
83
|
export declare const validateWebSocket: (v: any) => {
|
|
81
84
|
errors: any[];
|
|
@@ -91,9 +94,8 @@ export declare const validateWebSocket: (v: any) => {
|
|
|
91
94
|
/**
|
|
92
95
|
* Validate default disableToastMessage (webSocket)
|
|
93
96
|
* @param value
|
|
94
|
-
* @param {}
|
|
95
97
|
*/
|
|
96
|
-
export declare const validateWebSocketDisableToastMessage: (value: any
|
|
98
|
+
export declare const validateWebSocketDisableToastMessage: (value: any) => {
|
|
97
99
|
errors: any[];
|
|
98
100
|
warnings: any[];
|
|
99
101
|
value: any;
|
|
@@ -101,17 +103,15 @@ export declare const validateWebSocketDisableToastMessage: (value: any, notifica
|
|
|
101
103
|
/**
|
|
102
104
|
* Validate default secure (webSocket)
|
|
103
105
|
* @param value
|
|
104
|
-
* @param {}
|
|
105
106
|
*/
|
|
106
|
-
export declare const validateWebSocketSecure: (value: any
|
|
107
|
+
export declare const validateWebSocketSecure: (value: any) => {
|
|
107
108
|
errors: any[];
|
|
108
109
|
warnings: any[];
|
|
109
110
|
value: any;
|
|
110
111
|
};
|
|
111
112
|
/**
|
|
112
113
|
* Validate webPushMessaging
|
|
113
|
-
* @param
|
|
114
|
-
* @param {}
|
|
114
|
+
* @param v
|
|
115
115
|
*/
|
|
116
116
|
export declare const validateWebPushMessaging: (v: any) => {
|
|
117
117
|
errors: any[];
|
|
@@ -127,9 +127,8 @@ export declare const validateWebPushMessaging: (v: any) => {
|
|
|
127
127
|
/**
|
|
128
128
|
* Validate default disableToastMessage (webPushMessaging)
|
|
129
129
|
* @param value
|
|
130
|
-
* @param {}
|
|
131
130
|
*/
|
|
132
|
-
export declare const validateWebPushMessagingDisableToastMessage: (value: any
|
|
131
|
+
export declare const validateWebPushMessagingDisableToastMessage: (value: any) => {
|
|
133
132
|
errors: any[];
|
|
134
133
|
warnings: any[];
|
|
135
134
|
value: any;
|
|
@@ -137,17 +136,15 @@ export declare const validateWebPushMessagingDisableToastMessage: (value: any, n
|
|
|
137
136
|
/**
|
|
138
137
|
* Validate default applicationServerKey (webPushMessaging)
|
|
139
138
|
* @param value
|
|
140
|
-
* @param {}
|
|
141
139
|
*/
|
|
142
|
-
export declare const validateWebPushMessagingApplicationServerKey: (value: any
|
|
140
|
+
export declare const validateWebPushMessagingApplicationServerKey: (value: any) => {
|
|
143
141
|
errors: any[];
|
|
144
142
|
warnings: any[];
|
|
145
143
|
value: any;
|
|
146
144
|
};
|
|
147
145
|
/**
|
|
148
146
|
* Validate mobile native
|
|
149
|
-
* @param
|
|
150
|
-
* @param {}
|
|
147
|
+
* @param v
|
|
151
148
|
*/
|
|
152
149
|
export declare const validateMobileNativePushMessaging: (v: any) => {
|
|
153
150
|
errors: any[];
|
|
@@ -163,16 +160,15 @@ export declare const validateMobileNativePushMessaging: (v: any) => {
|
|
|
163
160
|
/**
|
|
164
161
|
* Validate default disable (mobileNativePushMessaging)
|
|
165
162
|
* @param value
|
|
166
|
-
* @param {}
|
|
167
163
|
*/
|
|
168
|
-
export declare const validateMobileNativePushMessagingDisable: (value: any
|
|
164
|
+
export declare const validateMobileNativePushMessagingDisable: (value: any) => {
|
|
169
165
|
errors: any[];
|
|
170
166
|
warnings: any[];
|
|
171
167
|
value: any;
|
|
172
168
|
};
|
|
173
169
|
/**
|
|
174
170
|
* Validate portal option
|
|
175
|
-
* @param
|
|
171
|
+
* @param value
|
|
176
172
|
* @return {}
|
|
177
173
|
*/
|
|
178
174
|
export declare const validatePortal: (value: any) => {
|
|
@@ -183,7 +179,7 @@ export declare const validatePortal: (value: any) => {
|
|
|
183
179
|
/**
|
|
184
180
|
* Validate default locale
|
|
185
181
|
* @param value
|
|
186
|
-
* @param
|
|
182
|
+
* @param locale
|
|
187
183
|
*/
|
|
188
184
|
export declare const validateLocaleDefault: (value: any, locale: any) => {
|
|
189
185
|
errors: any[];
|
|
@@ -193,7 +189,6 @@ export declare const validateLocaleDefault: (value: any, locale: any) => {
|
|
|
193
189
|
/**
|
|
194
190
|
* Validate default locale
|
|
195
191
|
* @param value
|
|
196
|
-
* @param {}
|
|
197
192
|
*/
|
|
198
193
|
export declare const validateLocaleMessages: (value: any) => {
|
|
199
194
|
errors: any[];
|
|
@@ -202,7 +197,7 @@ export declare const validateLocaleMessages: (value: any) => {
|
|
|
202
197
|
};
|
|
203
198
|
/**
|
|
204
199
|
* Validate locale option
|
|
205
|
-
* @param
|
|
200
|
+
* @param v
|
|
206
201
|
* @return {}
|
|
207
202
|
*/
|
|
208
203
|
export declare const validateLocale: (v: any) => {
|
|
@@ -218,7 +213,7 @@ export declare const validateLocale: (v: any) => {
|
|
|
218
213
|
};
|
|
219
214
|
/**
|
|
220
215
|
* Validate router option
|
|
221
|
-
* @param
|
|
216
|
+
* @param value
|
|
222
217
|
* @return {}
|
|
223
218
|
*/
|
|
224
219
|
export declare const validateRouter: (value: any) => {
|
|
@@ -228,7 +223,7 @@ export declare const validateRouter: (value: any) => {
|
|
|
228
223
|
};
|
|
229
224
|
/**
|
|
230
225
|
* Validate theme option
|
|
231
|
-
* @param
|
|
226
|
+
* @param value
|
|
232
227
|
* @return {}
|
|
233
228
|
*/
|
|
234
229
|
export declare const validateTheme: (value: any) => {
|
|
@@ -238,7 +233,7 @@ export declare const validateTheme: (value: any) => {
|
|
|
238
233
|
};
|
|
239
234
|
/**
|
|
240
235
|
* Validate handleAnonymousAction option
|
|
241
|
-
* @param
|
|
236
|
+
* @param v
|
|
242
237
|
* @return {}
|
|
243
238
|
*/
|
|
244
239
|
export declare const validateHandleAnonymousAction: (v: any) => {
|
|
@@ -248,7 +243,7 @@ export declare const validateHandleAnonymousAction: (v: any) => {
|
|
|
248
243
|
};
|
|
249
244
|
/**
|
|
250
245
|
* Validate contextProviders option
|
|
251
|
-
* @param
|
|
246
|
+
* @param value
|
|
252
247
|
* @return [...contextProviders]
|
|
253
248
|
*/
|
|
254
249
|
export declare const validateContextProviders: (value: any) => {
|
|
@@ -304,6 +299,45 @@ export declare function validateVote(v: Record<string, any>): {
|
|
|
304
299
|
warnings: any[];
|
|
305
300
|
value: Record<string, any>;
|
|
306
301
|
};
|
|
302
|
+
/**
|
|
303
|
+
* Validate integrations option
|
|
304
|
+
* @param v
|
|
305
|
+
* @return {}
|
|
306
|
+
*/
|
|
307
|
+
export declare function validateIntegrations(v: SCIntegrationsType): {
|
|
308
|
+
errors: any[];
|
|
309
|
+
warnings: any[];
|
|
310
|
+
value: {
|
|
311
|
+
openai: {
|
|
312
|
+
secretKey: any;
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* Validate OpenAI Option
|
|
318
|
+
* @param v
|
|
319
|
+
*/
|
|
320
|
+
export declare const validateOpenAI: (v: any) => {
|
|
321
|
+
errors: any[];
|
|
322
|
+
warnings: any[];
|
|
323
|
+
v: any;
|
|
324
|
+
value?: undefined;
|
|
325
|
+
} | {
|
|
326
|
+
errors: any[];
|
|
327
|
+
warnings: any[];
|
|
328
|
+
value: SCIntegrationsOpenAIType;
|
|
329
|
+
v?: undefined;
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* Validate OpenAI secret key option
|
|
333
|
+
* @param value
|
|
334
|
+
* @return {}
|
|
335
|
+
*/
|
|
336
|
+
export declare const validateOpenAISecretKey: (value: any) => {
|
|
337
|
+
errors: any[];
|
|
338
|
+
warnings: any[];
|
|
339
|
+
value: any;
|
|
340
|
+
};
|
|
307
341
|
/**
|
|
308
342
|
* Valid options
|
|
309
343
|
* @type {{}}
|
|
@@ -317,12 +351,15 @@ export declare const notificationsWebPushMessagingOptions: Record<string, any>;
|
|
|
317
351
|
export declare const notificationsMobileNativePushMessagingOptions: Record<string, any>;
|
|
318
352
|
export declare const preferencesOptions: Record<string, any>;
|
|
319
353
|
export declare const voteOptions: Record<string, any>;
|
|
354
|
+
export declare const integrationsOptions: Record<string, any>;
|
|
355
|
+
export declare const integrationsOpenAIOptions: Record<string, any>;
|
|
320
356
|
export declare const validOptions: {
|
|
321
357
|
[x: string]: any;
|
|
322
358
|
};
|
|
323
359
|
/**
|
|
324
360
|
* Validate all options by type
|
|
325
|
-
* @param
|
|
361
|
+
* @param values
|
|
362
|
+
* @param schemaOptions
|
|
326
363
|
* @return {options hydrated}
|
|
327
364
|
*/
|
|
328
365
|
export declare const validateOptions: (values: SCSettingsType, schemaOptions: Record<string, any>) => {
|
|
@@ -11,9 +11,10 @@ import * as Actions from '../constants/Actions';
|
|
|
11
11
|
import * as Preferences from '../constants/Preferences';
|
|
12
12
|
import * as Features from '../constants/Features';
|
|
13
13
|
import * as Vote from '../constants/Vote';
|
|
14
|
+
import * as Integrations from '../constants/Integrations';
|
|
14
15
|
/**
|
|
15
16
|
* Validate session option
|
|
16
|
-
* @param
|
|
17
|
+
* @param v
|
|
17
18
|
* @return {}
|
|
18
19
|
*/
|
|
19
20
|
export function validateSession(v) {
|
|
@@ -38,6 +39,7 @@ export function validateSession(v) {
|
|
|
38
39
|
/**
|
|
39
40
|
* Validate session type
|
|
40
41
|
* @param value
|
|
42
|
+
* @param session
|
|
41
43
|
* @return {}
|
|
42
44
|
*/
|
|
43
45
|
export const validateSessionType = (value, session) => {
|
|
@@ -51,6 +53,7 @@ export const validateSessionType = (value, session) => {
|
|
|
51
53
|
/**
|
|
52
54
|
* Validate session client id
|
|
53
55
|
* @param value
|
|
56
|
+
* @param session
|
|
54
57
|
* @return {}
|
|
55
58
|
*/
|
|
56
59
|
export const validateSessionClientId = (value, session) => {
|
|
@@ -68,6 +71,7 @@ export const validateSessionClientId = (value, session) => {
|
|
|
68
71
|
/**
|
|
69
72
|
* Validate session auth token
|
|
70
73
|
* @param value
|
|
74
|
+
* @param session
|
|
71
75
|
* @return {}
|
|
72
76
|
*/
|
|
73
77
|
export const validateSessionAuthTokenOption = (value, session) => {
|
|
@@ -104,6 +108,7 @@ export const validateHandleRefreshToken = (value, session) => {
|
|
|
104
108
|
/**
|
|
105
109
|
* Validate handleLogout option
|
|
106
110
|
* @param value
|
|
111
|
+
* @param session
|
|
107
112
|
* @return {}
|
|
108
113
|
*/
|
|
109
114
|
export const validateHandleLogout = (value, session) => {
|
|
@@ -116,7 +121,7 @@ export const validateHandleLogout = (value, session) => {
|
|
|
116
121
|
};
|
|
117
122
|
/**
|
|
118
123
|
* Validate notifications option
|
|
119
|
-
* @param
|
|
124
|
+
* @param v
|
|
120
125
|
* @return {}
|
|
121
126
|
*/
|
|
122
127
|
export function validateNotifications(v) {
|
|
@@ -135,12 +140,11 @@ export function validateNotifications(v) {
|
|
|
135
140
|
obj[key] = res.value;
|
|
136
141
|
return obj;
|
|
137
142
|
}, {});
|
|
138
|
-
return { errors, warnings, value: Object.assign(Object.assign({}, Notifications.DEFAULT_NOTIFICATIONS),
|
|
143
|
+
return { errors, warnings, value: Object.assign(Object.assign({}, Notifications.DEFAULT_NOTIFICATIONS), value) };
|
|
139
144
|
}
|
|
140
145
|
/**
|
|
141
146
|
* Validate webSocket
|
|
142
|
-
* @param
|
|
143
|
-
* @param {}
|
|
147
|
+
* @param v
|
|
144
148
|
*/
|
|
145
149
|
export const validateWebSocket = (v) => {
|
|
146
150
|
const errors = [];
|
|
@@ -164,9 +168,8 @@ export const validateWebSocket = (v) => {
|
|
|
164
168
|
/**
|
|
165
169
|
* Validate default disableToastMessage (webSocket)
|
|
166
170
|
* @param value
|
|
167
|
-
* @param {}
|
|
168
171
|
*/
|
|
169
|
-
export const validateWebSocketDisableToastMessage = (value
|
|
172
|
+
export const validateWebSocketDisableToastMessage = (value) => {
|
|
170
173
|
const errors = [];
|
|
171
174
|
const warnings = [];
|
|
172
175
|
if (value) {
|
|
@@ -186,9 +189,8 @@ export const validateWebSocketDisableToastMessage = (value, notifications) => {
|
|
|
186
189
|
/**
|
|
187
190
|
* Validate default secure (webSocket)
|
|
188
191
|
* @param value
|
|
189
|
-
* @param {}
|
|
190
192
|
*/
|
|
191
|
-
export const validateWebSocketSecure = (value
|
|
193
|
+
export const validateWebSocketSecure = (value) => {
|
|
192
194
|
const errors = [];
|
|
193
195
|
const warnings = [];
|
|
194
196
|
if (value) {
|
|
@@ -207,8 +209,7 @@ export const validateWebSocketSecure = (value, notifications) => {
|
|
|
207
209
|
};
|
|
208
210
|
/**
|
|
209
211
|
* Validate webPushMessaging
|
|
210
|
-
* @param
|
|
211
|
-
* @param {}
|
|
212
|
+
* @param v
|
|
212
213
|
*/
|
|
213
214
|
export const validateWebPushMessaging = (v) => {
|
|
214
215
|
const errors = [];
|
|
@@ -232,9 +233,8 @@ export const validateWebPushMessaging = (v) => {
|
|
|
232
233
|
/**
|
|
233
234
|
* Validate default disableToastMessage (webPushMessaging)
|
|
234
235
|
* @param value
|
|
235
|
-
* @param {}
|
|
236
236
|
*/
|
|
237
|
-
export const validateWebPushMessagingDisableToastMessage = (value
|
|
237
|
+
export const validateWebPushMessagingDisableToastMessage = (value) => {
|
|
238
238
|
const errors = [];
|
|
239
239
|
const warnings = [];
|
|
240
240
|
if (value !== undefined) {
|
|
@@ -254,9 +254,8 @@ export const validateWebPushMessagingDisableToastMessage = (value, notifications
|
|
|
254
254
|
/**
|
|
255
255
|
* Validate default applicationServerKey (webPushMessaging)
|
|
256
256
|
* @param value
|
|
257
|
-
* @param {}
|
|
258
257
|
*/
|
|
259
|
-
export const validateWebPushMessagingApplicationServerKey = (value
|
|
258
|
+
export const validateWebPushMessagingApplicationServerKey = (value) => {
|
|
260
259
|
const errors = [];
|
|
261
260
|
const warnings = [];
|
|
262
261
|
if (value) {
|
|
@@ -268,8 +267,7 @@ export const validateWebPushMessagingApplicationServerKey = (value, notification
|
|
|
268
267
|
};
|
|
269
268
|
/**
|
|
270
269
|
* Validate mobile native
|
|
271
|
-
* @param
|
|
272
|
-
* @param {}
|
|
270
|
+
* @param v
|
|
273
271
|
*/
|
|
274
272
|
export const validateMobileNativePushMessaging = (v) => {
|
|
275
273
|
const errors = [];
|
|
@@ -293,9 +291,8 @@ export const validateMobileNativePushMessaging = (v) => {
|
|
|
293
291
|
/**
|
|
294
292
|
* Validate default disable (mobileNativePushMessaging)
|
|
295
293
|
* @param value
|
|
296
|
-
* @param {}
|
|
297
294
|
*/
|
|
298
|
-
export const validateMobileNativePushMessagingDisable = (value
|
|
295
|
+
export const validateMobileNativePushMessagingDisable = (value) => {
|
|
299
296
|
const errors = [];
|
|
300
297
|
const warnings = [];
|
|
301
298
|
if (value !== undefined) {
|
|
@@ -314,7 +311,7 @@ export const validateMobileNativePushMessagingDisable = (value, notifications) =
|
|
|
314
311
|
};
|
|
315
312
|
/**
|
|
316
313
|
* Validate portal option
|
|
317
|
-
* @param
|
|
314
|
+
* @param value
|
|
318
315
|
* @return {}
|
|
319
316
|
*/
|
|
320
317
|
export const validatePortal = (value) => {
|
|
@@ -328,7 +325,7 @@ export const validatePortal = (value) => {
|
|
|
328
325
|
/**
|
|
329
326
|
* Validate default locale
|
|
330
327
|
* @param value
|
|
331
|
-
* @param
|
|
328
|
+
* @param locale
|
|
332
329
|
*/
|
|
333
330
|
export const validateLocaleDefault = (value, locale) => {
|
|
334
331
|
const errors = [];
|
|
@@ -346,7 +343,6 @@ export const validateLocaleDefault = (value, locale) => {
|
|
|
346
343
|
/**
|
|
347
344
|
* Validate default locale
|
|
348
345
|
* @param value
|
|
349
|
-
* @param {}
|
|
350
346
|
*/
|
|
351
347
|
export const validateLocaleMessages = (value) => {
|
|
352
348
|
const errors = [];
|
|
@@ -358,7 +354,7 @@ export const validateLocaleMessages = (value) => {
|
|
|
358
354
|
};
|
|
359
355
|
/**
|
|
360
356
|
* Validate locale option
|
|
361
|
-
* @param
|
|
357
|
+
* @param v
|
|
362
358
|
* @return {}
|
|
363
359
|
*/
|
|
364
360
|
export const validateLocale = (v) => {
|
|
@@ -382,7 +378,7 @@ export const validateLocale = (v) => {
|
|
|
382
378
|
};
|
|
383
379
|
/**
|
|
384
380
|
* Validate router option
|
|
385
|
-
* @param
|
|
381
|
+
* @param value
|
|
386
382
|
* @return {}
|
|
387
383
|
*/
|
|
388
384
|
export const validateRouter = (value) => {
|
|
@@ -405,7 +401,7 @@ export const validateRouter = (value) => {
|
|
|
405
401
|
};
|
|
406
402
|
/**
|
|
407
403
|
* Validate theme option
|
|
408
|
-
* @param
|
|
404
|
+
* @param value
|
|
409
405
|
* @return {}
|
|
410
406
|
*/
|
|
411
407
|
export const validateTheme = (value) => {
|
|
@@ -418,7 +414,7 @@ export const validateTheme = (value) => {
|
|
|
418
414
|
};
|
|
419
415
|
/**
|
|
420
416
|
* Validate handleAnonymousAction option
|
|
421
|
-
* @param
|
|
417
|
+
* @param v
|
|
422
418
|
* @return {}
|
|
423
419
|
*/
|
|
424
420
|
export const validateHandleAnonymousAction = (v) => {
|
|
@@ -443,7 +439,7 @@ export const validateHandleAnonymousAction = (v) => {
|
|
|
443
439
|
};
|
|
444
440
|
/**
|
|
445
441
|
* Validate contextProviders option
|
|
446
|
-
* @param
|
|
442
|
+
* @param value
|
|
447
443
|
* @return [...contextProviders]
|
|
448
444
|
*/
|
|
449
445
|
export const validateContextProviders = (value) => {
|
|
@@ -585,6 +581,66 @@ export function validateVote(v) {
|
|
|
585
581
|
}
|
|
586
582
|
return { errors, warnings, value: defaultValue };
|
|
587
583
|
}
|
|
584
|
+
/**
|
|
585
|
+
* Validate integrations option
|
|
586
|
+
* @param v
|
|
587
|
+
* @return {}
|
|
588
|
+
*/
|
|
589
|
+
export function validateIntegrations(v) {
|
|
590
|
+
const errors = [];
|
|
591
|
+
const warnings = [];
|
|
592
|
+
if (!v || !isObject(v)) {
|
|
593
|
+
return { errors, warnings, value: Integrations.DEFAULT_INTEGRATIONS_OPTION };
|
|
594
|
+
}
|
|
595
|
+
const _options = Object.keys(integrationsOptions);
|
|
596
|
+
const value = Object.keys(v)
|
|
597
|
+
.filter((key) => _options.includes(key))
|
|
598
|
+
.reduce((obj, key) => {
|
|
599
|
+
const res = integrationsOptions[key].validator(v[key], v);
|
|
600
|
+
res.errors.map((error) => errors.push(error));
|
|
601
|
+
res.warnings.map((warning) => warnings.push(warning));
|
|
602
|
+
obj[key] = res.value;
|
|
603
|
+
return obj;
|
|
604
|
+
}, {});
|
|
605
|
+
return { errors, warnings, value: Object.assign(Object.assign({}, Integrations.DEFAULT_INTEGRATIONS_OPTION), value) };
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Validate OpenAI Option
|
|
609
|
+
* @param v
|
|
610
|
+
*/
|
|
611
|
+
export const validateOpenAI = (v) => {
|
|
612
|
+
console.log(v);
|
|
613
|
+
const errors = [];
|
|
614
|
+
const warnings = [];
|
|
615
|
+
if (v && !isObject(v)) {
|
|
616
|
+
errors.push(ValidationError.ERROR_INVALID_INTEGRATIONS_OPENAI);
|
|
617
|
+
return { errors, warnings, v };
|
|
618
|
+
}
|
|
619
|
+
const _options = Object.keys(integrationsOpenAIOptions);
|
|
620
|
+
const value = Object.keys(v)
|
|
621
|
+
.filter((key) => _options.includes(key))
|
|
622
|
+
.reduce((obj, key) => {
|
|
623
|
+
const res = integrationsOpenAIOptions[key].validator(v[key], v);
|
|
624
|
+
res.errors.map((error) => errors.push(error));
|
|
625
|
+
res.warnings.map((warning) => warnings.push(warning));
|
|
626
|
+
obj[key] = res.value;
|
|
627
|
+
return obj;
|
|
628
|
+
}, {});
|
|
629
|
+
return { errors, warnings, value };
|
|
630
|
+
};
|
|
631
|
+
/**
|
|
632
|
+
* Validate OpenAI secret key option
|
|
633
|
+
* @param value
|
|
634
|
+
* @return {}
|
|
635
|
+
*/
|
|
636
|
+
export const validateOpenAISecretKey = (value) => {
|
|
637
|
+
const errors = [];
|
|
638
|
+
const warnings = [];
|
|
639
|
+
if (!value || !isString(value)) {
|
|
640
|
+
errors.push(ValidationError.ERROR_INVALID_INTEGRATIONS_OPENAI_SECRETKEY);
|
|
641
|
+
}
|
|
642
|
+
return { errors, warnings, value };
|
|
643
|
+
};
|
|
588
644
|
/**
|
|
589
645
|
* Components Widget
|
|
590
646
|
*/
|
|
@@ -628,6 +684,10 @@ const VoteOption = {
|
|
|
628
684
|
name: Vote.VOTE_OPTION,
|
|
629
685
|
validator: validateVote,
|
|
630
686
|
};
|
|
687
|
+
const IntegrationsOption = {
|
|
688
|
+
name: Integrations.INTEGRATIONS_OPTION,
|
|
689
|
+
validator: validateIntegrations,
|
|
690
|
+
};
|
|
631
691
|
/**
|
|
632
692
|
* Session options
|
|
633
693
|
*/
|
|
@@ -703,6 +763,14 @@ const ReactionsOption = {
|
|
|
703
763
|
name: Vote.VOTE_REACTIONS_OPTION,
|
|
704
764
|
validator: validateReactions,
|
|
705
765
|
};
|
|
766
|
+
const IntegrationOpenAIOption = {
|
|
767
|
+
name: Integrations.INTEGRATIONS_OPENAI_OPTION,
|
|
768
|
+
validator: validateOpenAI,
|
|
769
|
+
};
|
|
770
|
+
const IntegrationOpenAISecretKeyOption = {
|
|
771
|
+
name: Integrations.INTEGRATIONS_OPENAI_SECRETKEY_OPTION,
|
|
772
|
+
validator: validateOpenAISecretKey,
|
|
773
|
+
};
|
|
706
774
|
/**
|
|
707
775
|
* Valid options
|
|
708
776
|
* @type {{}}
|
|
@@ -718,6 +786,7 @@ export const settingsOptions = {
|
|
|
718
786
|
[ContextProvidersOption.name]: ContextProvidersOption,
|
|
719
787
|
[PreferencesOption.name]: PreferencesOption,
|
|
720
788
|
[VoteOption.name]: VoteOption,
|
|
789
|
+
[IntegrationsOption.name]: IntegrationsOption,
|
|
721
790
|
};
|
|
722
791
|
export const sessionOptions = {
|
|
723
792
|
[SessionTypeOption.name]: SessionTypeOption,
|
|
@@ -753,10 +822,17 @@ export const preferencesOptions = {
|
|
|
753
822
|
export const voteOptions = {
|
|
754
823
|
[ReactionsOption.name]: ReactionsOption,
|
|
755
824
|
};
|
|
825
|
+
export const integrationsOptions = {
|
|
826
|
+
[IntegrationOpenAIOption.name]: IntegrationOpenAIOption,
|
|
827
|
+
};
|
|
828
|
+
export const integrationsOpenAIOptions = {
|
|
829
|
+
[IntegrationOpenAISecretKeyOption.name]: IntegrationOpenAISecretKeyOption,
|
|
830
|
+
};
|
|
756
831
|
export const validOptions = Object.assign({}, settingsOptions);
|
|
757
832
|
/**
|
|
758
833
|
* Validate all options by type
|
|
759
|
-
* @param
|
|
834
|
+
* @param values
|
|
835
|
+
* @param schemaOptions
|
|
760
836
|
* @return {options hydrated}
|
|
761
837
|
*/
|
|
762
838
|
export const validateOptions = (values, schemaOptions) => {
|