@selfcommunity/react-core 0.4.50-alpha.0 → 0.4.50-event.30

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.
Files changed (46) hide show
  1. package/lib/cjs/components/provider/SCUserProvider/index.js +4 -4
  2. package/lib/cjs/constants/Cache.d.ts +3 -0
  3. package/lib/cjs/constants/Cache.js +6 -2
  4. package/lib/cjs/constants/Integrations.d.ts +13 -0
  5. package/lib/cjs/constants/Integrations.js +17 -0
  6. package/lib/cjs/constants/Notifications.d.ts +2 -1
  7. package/lib/cjs/constants/Notifications.js +4 -3
  8. package/lib/cjs/constants/Preferences.d.ts +3 -0
  9. package/lib/cjs/constants/Preferences.js +8 -2
  10. package/lib/cjs/constants/Routes.d.ts +4 -0
  11. package/lib/cjs/constants/Routes.js +9 -1
  12. package/lib/cjs/hooks/useSCFetchEvent.d.ts +20 -0
  13. package/lib/cjs/hooks/useSCFetchEvent.js +74 -0
  14. package/lib/cjs/index.d.ts +2 -1
  15. package/lib/cjs/index.js +3 -1
  16. package/lib/cjs/types/context.d.ts +37 -0
  17. package/lib/cjs/utils/errors.d.ts +6 -0
  18. package/lib/cjs/utils/errors.js +12 -0
  19. package/lib/cjs/utils/hooks/useIsomorphicLayoutEffect.js +2 -1
  20. package/lib/cjs/utils/notification.js +1 -1
  21. package/lib/cjs/utils/validator.d.ts +103 -28
  22. package/lib/cjs/utils/validator.js +178 -31
  23. package/lib/esm/components/provider/SCUserProvider/index.js +5 -5
  24. package/lib/esm/constants/Cache.d.ts +3 -0
  25. package/lib/esm/constants/Cache.js +3 -0
  26. package/lib/esm/constants/Integrations.d.ts +13 -0
  27. package/lib/esm/constants/Integrations.js +14 -0
  28. package/lib/esm/constants/Notifications.d.ts +2 -1
  29. package/lib/esm/constants/Notifications.js +3 -2
  30. package/lib/esm/constants/Preferences.d.ts +3 -0
  31. package/lib/esm/constants/Preferences.js +6 -0
  32. package/lib/esm/constants/Routes.d.ts +4 -0
  33. package/lib/esm/constants/Routes.js +8 -0
  34. package/lib/esm/hooks/useSCFetchEvent.d.ts +20 -0
  35. package/lib/esm/hooks/useSCFetchEvent.js +71 -0
  36. package/lib/esm/index.d.ts +2 -1
  37. package/lib/esm/index.js +2 -1
  38. package/lib/esm/types/context.d.ts +37 -0
  39. package/lib/esm/utils/errors.d.ts +6 -0
  40. package/lib/esm/utils/errors.js +12 -0
  41. package/lib/esm/utils/hooks/useIsomorphicLayoutEffect.js +2 -1
  42. package/lib/esm/utils/notification.js +2 -2
  43. package/lib/esm/utils/validator.d.ts +103 -28
  44. package/lib/esm/utils/validator.js +171 -30
  45. package/lib/umd/react-core.js +1 -1
  46. package/package.json +6 -6
@@ -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 session
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 notifications
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), v) };
143
+ return { errors, warnings, value: Object.assign(Object.assign({}, Notifications.DEFAULT_NOTIFICATIONS), value) };
139
144
  }
140
145
  /**
141
146
  * Validate webSocket
142
- * @param value
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, notifications) => {
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, notifications) => {
193
+ export const validateWebSocketSecure = (value) => {
192
194
  const errors = [];
193
195
  const warnings = [];
194
196
  if (value) {
@@ -200,15 +202,26 @@ export const validateWebSocketSecure = (value, notifications) => {
200
202
  return {
201
203
  errors,
202
204
  warnings,
203
- value: Notifications.DEFAULT_NOTIFICATIONS[Notifications.NOTIFICATIONS_WEB_SOCKET_OPTION][Notifications.NOTIFICATIONS_SECURE_OPTION],
205
+ value: Notifications.DEFAULT_NOTIFICATIONS[Notifications.NOTIFICATIONS_WEB_SOCKET_OPTION][Notifications.NOTIFICATIONS_WEBSOCKET_SECURE_OPTION],
204
206
  };
205
207
  }
206
208
  return { errors, warnings, value };
207
209
  };
208
210
  /**
209
- * Validate webPushMessaging
211
+ * Validate prefixPath (webSocket)
210
212
  * @param value
211
- * @param {}
213
+ */
214
+ export const validateWebSocketPrefixPath = (value) => {
215
+ const errors = [];
216
+ const warnings = [];
217
+ if (!value || !isString(value)) {
218
+ errors.push(ValidationError.ERROR_INVALID_NOTIFICATIONS_WEBSOCKET_PREFIX_PATH);
219
+ }
220
+ return { errors, warnings, value };
221
+ };
222
+ /**
223
+ * Validate webPushMessaging
224
+ * @param v
212
225
  */
213
226
  export const validateWebPushMessaging = (v) => {
214
227
  const errors = [];
@@ -232,9 +245,8 @@ export const validateWebPushMessaging = (v) => {
232
245
  /**
233
246
  * Validate default disableToastMessage (webPushMessaging)
234
247
  * @param value
235
- * @param {}
236
248
  */
237
- export const validateWebPushMessagingDisableToastMessage = (value, notifications) => {
249
+ export const validateWebPushMessagingDisableToastMessage = (value) => {
238
250
  const errors = [];
239
251
  const warnings = [];
240
252
  if (value !== undefined) {
@@ -254,9 +266,8 @@ export const validateWebPushMessagingDisableToastMessage = (value, notifications
254
266
  /**
255
267
  * Validate default applicationServerKey (webPushMessaging)
256
268
  * @param value
257
- * @param {}
258
269
  */
259
- export const validateWebPushMessagingApplicationServerKey = (value, notifications) => {
270
+ export const validateWebPushMessagingApplicationServerKey = (value) => {
260
271
  const errors = [];
261
272
  const warnings = [];
262
273
  if (value) {
@@ -268,8 +279,7 @@ export const validateWebPushMessagingApplicationServerKey = (value, notification
268
279
  };
269
280
  /**
270
281
  * Validate mobile native
271
- * @param value
272
- * @param {}
282
+ * @param v
273
283
  */
274
284
  export const validateMobileNativePushMessaging = (v) => {
275
285
  const errors = [];
@@ -293,9 +303,8 @@ export const validateMobileNativePushMessaging = (v) => {
293
303
  /**
294
304
  * Validate default disable (mobileNativePushMessaging)
295
305
  * @param value
296
- * @param {}
297
306
  */
298
- export const validateMobileNativePushMessagingDisable = (value, notifications) => {
307
+ export const validateMobileNativePushMessagingDisable = (value) => {
299
308
  const errors = [];
300
309
  const warnings = [];
301
310
  if (value !== undefined) {
@@ -314,7 +323,7 @@ export const validateMobileNativePushMessagingDisable = (value, notifications) =
314
323
  };
315
324
  /**
316
325
  * Validate portal option
317
- * @param portal
326
+ * @param value
318
327
  * @return {}
319
328
  */
320
329
  export const validatePortal = (value) => {
@@ -328,7 +337,7 @@ export const validatePortal = (value) => {
328
337
  /**
329
338
  * Validate default locale
330
339
  * @param value
331
- * @param {}
340
+ * @param locale
332
341
  */
333
342
  export const validateLocaleDefault = (value, locale) => {
334
343
  const errors = [];
@@ -346,7 +355,6 @@ export const validateLocaleDefault = (value, locale) => {
346
355
  /**
347
356
  * Validate default locale
348
357
  * @param value
349
- * @param {}
350
358
  */
351
359
  export const validateLocaleMessages = (value) => {
352
360
  const errors = [];
@@ -358,7 +366,7 @@ export const validateLocaleMessages = (value) => {
358
366
  };
359
367
  /**
360
368
  * Validate locale option
361
- * @param locale
369
+ * @param v
362
370
  * @return {}
363
371
  */
364
372
  export const validateLocale = (v) => {
@@ -382,7 +390,7 @@ export const validateLocale = (v) => {
382
390
  };
383
391
  /**
384
392
  * Validate router option
385
- * @param router
393
+ * @param value
386
394
  * @return {}
387
395
  */
388
396
  export const validateRouter = (value) => {
@@ -405,7 +413,7 @@ export const validateRouter = (value) => {
405
413
  };
406
414
  /**
407
415
  * Validate theme option
408
- * @param theme
416
+ * @param value
409
417
  * @return {}
410
418
  */
411
419
  export const validateTheme = (value) => {
@@ -418,7 +426,7 @@ export const validateTheme = (value) => {
418
426
  };
419
427
  /**
420
428
  * Validate handleAnonymousAction option
421
- * @param handleAnonymousAction
429
+ * @param v
422
430
  * @return {}
423
431
  */
424
432
  export const validateHandleAnonymousAction = (v) => {
@@ -443,7 +451,7 @@ export const validateHandleAnonymousAction = (v) => {
443
451
  };
444
452
  /**
445
453
  * Validate contextProviders option
446
- * @param contextProviders
454
+ * @param value
447
455
  * @return [...contextProviders]
448
456
  */
449
457
  export const validateContextProviders = (value) => {
@@ -585,6 +593,102 @@ export function validateVote(v) {
585
593
  }
586
594
  return { errors, warnings, value: defaultValue };
587
595
  }
596
+ /**
597
+ * Validate integrations option
598
+ * @param v
599
+ * @return {}
600
+ */
601
+ export function validateIntegrations(v) {
602
+ const errors = [];
603
+ const warnings = [];
604
+ if (!v || !isObject(v)) {
605
+ return { errors, warnings, value: Integrations.DEFAULT_INTEGRATIONS_OPTION };
606
+ }
607
+ const _options = Object.keys(integrationsOptions);
608
+ const value = Object.keys(v)
609
+ .filter((key) => _options.includes(key))
610
+ .reduce((obj, key) => {
611
+ const res = integrationsOptions[key].validator(v[key], v);
612
+ res.errors.map((error) => errors.push(error));
613
+ res.warnings.map((warning) => warnings.push(warning));
614
+ obj[key] = res.value;
615
+ return obj;
616
+ }, {});
617
+ return { errors, warnings, value: Object.assign(Object.assign({}, Integrations.DEFAULT_INTEGRATIONS_OPTION), value) };
618
+ }
619
+ /**
620
+ * Validate OpenAI Option
621
+ * @param v
622
+ */
623
+ export const validateOpenAI = (v) => {
624
+ const errors = [];
625
+ const warnings = [];
626
+ if (v && !isObject(v)) {
627
+ errors.push(ValidationError.ERROR_INVALID_INTEGRATIONS_OPENAI);
628
+ return { errors, warnings, v };
629
+ }
630
+ const _options = Object.keys(integrationsOpenAIOptions);
631
+ const value = Object.keys(v)
632
+ .filter((key) => _options.includes(key))
633
+ .reduce((obj, key) => {
634
+ const res = integrationsOpenAIOptions[key].validator(v[key], v);
635
+ res.errors.map((error) => errors.push(error));
636
+ res.warnings.map((warning) => warnings.push(warning));
637
+ obj[key] = res.value;
638
+ return obj;
639
+ }, {});
640
+ return { errors, warnings, value };
641
+ };
642
+ /**
643
+ * Validate Geocoding Option
644
+ * @param v
645
+ */
646
+ export const validateGeocoding = (v) => {
647
+ //console.log(v);
648
+ const errors = [];
649
+ const warnings = [];
650
+ if (v && !isObject(v)) {
651
+ errors.push(ValidationError.ERROR_INVALID_INTEGRATIONS_GEOCODING);
652
+ return { errors, warnings, v };
653
+ }
654
+ const _options = Object.keys(integrationsGeocodingOptions);
655
+ const value = Object.keys(v)
656
+ .filter((key) => _options.includes(key))
657
+ .reduce((obj, key) => {
658
+ const res = integrationsGeocodingOptions[key].validator(v[key], v);
659
+ res.errors.map((error) => errors.push(error));
660
+ res.warnings.map((warning) => warnings.push(warning));
661
+ obj[key] = res.value;
662
+ return obj;
663
+ }, {});
664
+ return { errors, warnings, value };
665
+ };
666
+ /**
667
+ * Validate OpenAI secret key option
668
+ * @param value
669
+ * @return {}
670
+ */
671
+ export const validateOpenAISecretKey = (value) => {
672
+ const errors = [];
673
+ const warnings = [];
674
+ if (!value || !isString(value)) {
675
+ errors.push(ValidationError.ERROR_INVALID_INTEGRATIONS_OPENAI_SECRETKEY);
676
+ }
677
+ return { errors, warnings, value };
678
+ };
679
+ /**
680
+ * Validate Geocoding api key option
681
+ * @param value
682
+ * @return {}
683
+ */
684
+ export const validateGeocodingApiKey = (value) => {
685
+ const errors = [];
686
+ const warnings = [];
687
+ if (!value || !isString(value)) {
688
+ errors.push(ValidationError.ERROR_INVALID_INTEGRATIONS_GEOCODING_APIKEY);
689
+ }
690
+ return { errors, warnings, value };
691
+ };
588
692
  /**
589
693
  * Components Widget
590
694
  */
@@ -628,6 +732,10 @@ const VoteOption = {
628
732
  name: Vote.VOTE_OPTION,
629
733
  validator: validateVote,
630
734
  };
735
+ const IntegrationsOption = {
736
+ name: Integrations.INTEGRATIONS_OPTION,
737
+ validator: validateIntegrations,
738
+ };
631
739
  /**
632
740
  * Session options
633
741
  */
@@ -684,9 +792,13 @@ const NotificationsWebSocketDisableToastMessageOption = {
684
792
  validator: validateWebSocketDisableToastMessage,
685
793
  };
686
794
  const NotificationsWebSocketSecureOption = {
687
- name: Notifications.NOTIFICATIONS_SECURE_OPTION,
795
+ name: Notifications.NOTIFICATIONS_WEBSOCKET_SECURE_OPTION,
688
796
  validator: validateWebSocketSecure,
689
797
  };
798
+ const NotificationsWebSocketPrefixPathOption = {
799
+ name: Notifications.NOTIFICATIONS_WEBSOCKET_PREFIX_PATH_OPTION,
800
+ validator: validateWebSocketPrefixPath,
801
+ };
690
802
  const NotificationsWebPushMessagingDisableToastMessageOption = {
691
803
  name: Notifications.NOTIFICATIONS_DISABLE_TOAST_MESSAGE_OPTION,
692
804
  validator: validateWebPushMessagingDisableToastMessage,
@@ -703,6 +815,22 @@ const ReactionsOption = {
703
815
  name: Vote.VOTE_REACTIONS_OPTION,
704
816
  validator: validateReactions,
705
817
  };
818
+ const IntegrationOpenAIOption = {
819
+ name: Integrations.INTEGRATIONS_OPENAI_OPTION,
820
+ validator: validateOpenAI,
821
+ };
822
+ const IntegrationOpenAISecretKeyOption = {
823
+ name: Integrations.INTEGRATIONS_OPENAI_SECRETKEY_OPTION,
824
+ validator: validateOpenAISecretKey,
825
+ };
826
+ const IntegrationGeocodingOption = {
827
+ name: Integrations.INTEGRATIONS_GEOCODING_OPTION,
828
+ validator: validateGeocoding,
829
+ };
830
+ const IntegrationGeocodingApiKeyOption = {
831
+ name: Integrations.INTEGRATIONS_GEOCODING_APIKEY_OPTION,
832
+ validator: validateGeocodingApiKey,
833
+ };
706
834
  /**
707
835
  * Valid options
708
836
  * @type {{}}
@@ -718,6 +846,7 @@ export const settingsOptions = {
718
846
  [ContextProvidersOption.name]: ContextProvidersOption,
719
847
  [PreferencesOption.name]: PreferencesOption,
720
848
  [VoteOption.name]: VoteOption,
849
+ [IntegrationsOption.name]: IntegrationsOption,
721
850
  };
722
851
  export const sessionOptions = {
723
852
  [SessionTypeOption.name]: SessionTypeOption,
@@ -738,6 +867,7 @@ export const notificationsOptions = {
738
867
  export const notificationsWebSocketOptions = {
739
868
  [NotificationsWebSocketDisableToastMessageOption.name]: NotificationsWebSocketDisableToastMessageOption,
740
869
  [NotificationsWebSocketSecureOption.name]: NotificationsWebSocketSecureOption,
870
+ [NotificationsWebSocketPrefixPathOption.name]: NotificationsWebSocketPrefixPathOption,
741
871
  };
742
872
  export const notificationsWebPushMessagingOptions = {
743
873
  [NotificationsWebPushMessagingDisableToastMessageOption.name]: NotificationsWebPushMessagingDisableToastMessageOption,
@@ -753,10 +883,21 @@ export const preferencesOptions = {
753
883
  export const voteOptions = {
754
884
  [ReactionsOption.name]: ReactionsOption,
755
885
  };
886
+ export const integrationsOptions = {
887
+ [IntegrationOpenAIOption.name]: IntegrationOpenAIOption,
888
+ [IntegrationGeocodingOption.name]: IntegrationGeocodingOption,
889
+ };
890
+ export const integrationsOpenAIOptions = {
891
+ [IntegrationOpenAISecretKeyOption.name]: IntegrationOpenAISecretKeyOption,
892
+ };
893
+ export const integrationsGeocodingOptions = {
894
+ [IntegrationGeocodingApiKeyOption.name]: IntegrationGeocodingApiKeyOption,
895
+ };
756
896
  export const validOptions = Object.assign({}, settingsOptions);
757
897
  /**
758
898
  * Validate all options by type
759
- * @param options
899
+ * @param values
900
+ * @param schemaOptions
760
901
  * @return {options hydrated}
761
902
  */
762
903
  export const validateOptions = (values, schemaOptions) => {