@selfcommunity/react-core 0.4.55 → 0.5.0-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/SCAlertMessagesProvider/index.js +3 -4
- package/lib/cjs/components/provider/SCContextProvider/index.js +6 -5
- package/lib/cjs/components/provider/SCLocaleProvider/index.js +4 -6
- package/lib/cjs/components/provider/SCNotificationProvider/index.js +3 -2
- package/lib/cjs/components/provider/SCPreferencesProvider/index.js +18 -3
- package/lib/cjs/components/provider/SCRoutingProvider/index.js +3 -2
- package/lib/cjs/components/provider/SCThemeProvider/index.js +4 -5
- package/lib/cjs/components/provider/SCUserProvider/index.js +9 -2
- package/lib/cjs/components/provider/SCVoteProvider/index.js +3 -3
- package/lib/cjs/components/router/index.js +3 -2
- package/lib/cjs/constants/Cache.d.ts +11 -0
- package/lib/cjs/constants/Cache.js +15 -2
- package/lib/cjs/constants/Integrations.d.ts +5 -0
- package/lib/cjs/constants/Integrations.js +6 -1
- package/lib/cjs/constants/Preferences.d.ts +3 -0
- package/lib/cjs/constants/Preferences.js +8 -2
- package/lib/cjs/constants/Routes.d.ts +5 -0
- package/lib/cjs/constants/Routes.js +11 -1
- package/lib/cjs/hooks/useSCFetchEvent.d.ts +22 -0
- package/lib/cjs/hooks/useSCFetchEvent.js +87 -0
- package/lib/cjs/hooks/useSCFetchEvents.d.ts +22 -0
- package/lib/cjs/hooks/useSCFetchEvents.js +83 -0
- package/lib/cjs/hooks/useSCSubscribedEventsManager.d.ts +38 -0
- package/lib/cjs/hooks/useSCSubscribedEventsManager.js +297 -0
- package/lib/cjs/hooks/useSCWebPushMessaging.js +3 -4
- package/lib/cjs/index.d.ts +8 -3
- package/lib/cjs/index.js +13 -3
- package/lib/cjs/types/context.d.ts +71 -2
- package/lib/cjs/types/index.d.ts +2 -2
- package/lib/cjs/utils/errors.d.ts +2 -0
- package/lib/cjs/utils/errors.js +4 -0
- package/lib/cjs/utils/event.d.ts +8 -0
- package/lib/cjs/utils/event.js +29 -0
- package/lib/cjs/utils/user.d.ts +7 -0
- package/lib/cjs/utils/user.js +11 -1
- package/lib/cjs/utils/validator.d.ts +30 -1
- package/lib/cjs/utils/validator.js +52 -1
- package/lib/esm/components/provider/SCAlertMessagesProvider/index.js +3 -3
- package/lib/esm/components/provider/SCContextProvider/index.js +6 -5
- package/lib/esm/components/provider/SCLocaleProvider/index.js +4 -5
- package/lib/esm/components/provider/SCNotificationProvider/index.js +3 -2
- package/lib/esm/components/provider/SCPreferencesProvider/index.js +18 -2
- package/lib/esm/components/provider/SCRoutingProvider/index.js +3 -2
- package/lib/esm/components/provider/SCThemeProvider/index.js +4 -5
- package/lib/esm/components/provider/SCUserProvider/index.js +9 -2
- package/lib/esm/components/provider/SCVoteProvider/index.js +3 -2
- package/lib/esm/components/router/index.js +3 -2
- package/lib/esm/constants/Cache.d.ts +11 -0
- package/lib/esm/constants/Cache.js +11 -0
- package/lib/esm/constants/Integrations.d.ts +5 -0
- package/lib/esm/constants/Integrations.js +5 -0
- package/lib/esm/constants/Preferences.d.ts +3 -0
- package/lib/esm/constants/Preferences.js +6 -0
- package/lib/esm/constants/Routes.d.ts +5 -0
- package/lib/esm/constants/Routes.js +10 -0
- package/lib/esm/hooks/useSCFetchEvent.d.ts +22 -0
- package/lib/esm/hooks/useSCFetchEvent.js +84 -0
- package/lib/esm/hooks/useSCFetchEvents.d.ts +22 -0
- package/lib/esm/hooks/useSCFetchEvents.js +81 -0
- package/lib/esm/hooks/useSCSubscribedEventsManager.d.ts +38 -0
- package/lib/esm/hooks/useSCSubscribedEventsManager.js +293 -0
- package/lib/esm/hooks/useSCWebPushMessaging.js +3 -4
- package/lib/esm/index.d.ts +8 -3
- package/lib/esm/index.js +7 -2
- package/lib/esm/types/context.d.ts +71 -2
- package/lib/esm/types/index.d.ts +2 -2
- package/lib/esm/utils/errors.d.ts +2 -0
- package/lib/esm/utils/errors.js +4 -0
- package/lib/esm/utils/event.d.ts +8 -0
- package/lib/esm/utils/event.js +25 -0
- package/lib/esm/utils/user.d.ts +7 -0
- package/lib/esm/utils/user.js +9 -0
- package/lib/esm/utils/validator.d.ts +30 -1
- package/lib/esm/utils/validator.js +49 -0
- package/lib/umd/react-core.js +1 -1
- package/package.json +6 -6
package/lib/esm/index.js
CHANGED
|
@@ -58,6 +58,8 @@ import useSCFetchUserBlockedBy from './hooks/useSCFetchUserBlockedBy';
|
|
|
58
58
|
import useSCUserIsBlocked from './hooks/useSCUserIsBlocked';
|
|
59
59
|
import useSCFetchGroup from './hooks/useSCFetchGroup';
|
|
60
60
|
import useSCFetchGroups from './hooks/useSCFetchGroups';
|
|
61
|
+
import useSCFetchEvent from './hooks/useSCFetchEvent';
|
|
62
|
+
import useSCFetchEvents from './hooks/useSCFetchEvents';
|
|
61
63
|
/**
|
|
62
64
|
* Routing component
|
|
63
65
|
*/
|
|
@@ -68,13 +70,16 @@ import * as SCRoutes from './constants/Routes';
|
|
|
68
70
|
* User, hooks (useIsComponentMountedRef)
|
|
69
71
|
*/
|
|
70
72
|
import * as UserUtils from './utils/user';
|
|
73
|
+
import getTheme from './themes/theme';
|
|
71
74
|
import { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect } from './utils/hooks';
|
|
75
|
+
import { getEventStatus } from './utils/event';
|
|
72
76
|
/**
|
|
73
77
|
* Constants:
|
|
74
|
-
* Locale
|
|
78
|
+
* Locale, Preferences
|
|
75
79
|
*/
|
|
76
80
|
import * as Locale from './constants/Locale';
|
|
81
|
+
import * as Preferences from './constants/Preferences';
|
|
77
82
|
/**
|
|
78
83
|
* List all exports
|
|
79
84
|
*/
|
|
80
|
-
export { SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, Locale, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, };
|
|
85
|
+
export { SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { SCAuthTokenType, SCIncubatorType, SCCategoryType, SCUserType, SCUserSettingsType, SCReactionType, SCGroupType } from '@selfcommunity/types';
|
|
2
|
+
import { SCAuthTokenType, SCIncubatorType, SCCategoryType, SCUserType, SCUserSettingsType, SCReactionType, SCGroupType, SCEventType } from '@selfcommunity/types';
|
|
3
3
|
import { SCThemeType } from './theme';
|
|
4
4
|
/**
|
|
5
5
|
* Interface SCSettingsType
|
|
@@ -37,6 +37,10 @@ export interface SCSettingsType {
|
|
|
37
37
|
* Object conf of notification.
|
|
38
38
|
*/
|
|
39
39
|
notifications?: SCNotificationsType;
|
|
40
|
+
/**
|
|
41
|
+
* Integrations conf
|
|
42
|
+
*/
|
|
43
|
+
integrations?: SCIntegrationsType;
|
|
40
44
|
/**
|
|
41
45
|
* Callback to handle anonymous action
|
|
42
46
|
* Ex. an anonymous user attempt to post a comment
|
|
@@ -143,6 +147,7 @@ export interface SCUserContextType {
|
|
|
143
147
|
incubators?: SCSubscribedIncubatorsManagerType;
|
|
144
148
|
blockedUsers?: SCBlockedUsersManagerType;
|
|
145
149
|
groups?: SCSubscribedGroupsManagerType;
|
|
150
|
+
events?: SCSubscribedEventsManagerType;
|
|
146
151
|
};
|
|
147
152
|
}
|
|
148
153
|
export interface SCSettingsManagerType {
|
|
@@ -249,6 +254,44 @@ export interface SCFollowedCategoriesManagerType {
|
|
|
249
254
|
*/
|
|
250
255
|
emptyCache?: () => void;
|
|
251
256
|
}
|
|
257
|
+
export interface SCSubscribedEventsManagerType {
|
|
258
|
+
/**
|
|
259
|
+
* List of all events ids followed by the authenticated user
|
|
260
|
+
*/
|
|
261
|
+
events: number[];
|
|
262
|
+
/**
|
|
263
|
+
* List of all events in loading state
|
|
264
|
+
*/
|
|
265
|
+
loading: number[];
|
|
266
|
+
/**
|
|
267
|
+
* List of current events in loading state
|
|
268
|
+
*/
|
|
269
|
+
isLoading: (event: SCEventType) => boolean;
|
|
270
|
+
/**
|
|
271
|
+
* Handle user subscription to an event
|
|
272
|
+
*/
|
|
273
|
+
subscribe?: (event: SCEventType, userId?: number) => Promise<any>;
|
|
274
|
+
/**
|
|
275
|
+
* Handle user going to an event
|
|
276
|
+
*/
|
|
277
|
+
toggleEventAttendance?: (event: SCEventType, userId?: number) => Promise<any>;
|
|
278
|
+
/**
|
|
279
|
+
* Handle user not going to an event
|
|
280
|
+
*/
|
|
281
|
+
toggleEventNonattendance?: (event: SCEventType, userId?: number) => Promise<any>;
|
|
282
|
+
/**
|
|
283
|
+
* Handles a user subscription status to an event, caching data
|
|
284
|
+
*/
|
|
285
|
+
subscriptionStatus?: (event: SCEventType) => string;
|
|
286
|
+
/**
|
|
287
|
+
* Refresh groups
|
|
288
|
+
*/
|
|
289
|
+
refresh?: () => void;
|
|
290
|
+
/**
|
|
291
|
+
* Empty cache to revalidate all groups
|
|
292
|
+
*/
|
|
293
|
+
emptyCache?: () => void;
|
|
294
|
+
}
|
|
252
295
|
export interface SCSubscribedGroupsManagerType {
|
|
253
296
|
/**
|
|
254
297
|
* List of all groups ids followed by the authenticated user
|
|
@@ -444,6 +487,18 @@ export interface SCPreferencesContextType {
|
|
|
444
487
|
* List of all community enabled features
|
|
445
488
|
*/
|
|
446
489
|
features: string[];
|
|
490
|
+
/**
|
|
491
|
+
* Set prefrerences
|
|
492
|
+
*/
|
|
493
|
+
setPreferences: (preferences: Record<string, any>) => void;
|
|
494
|
+
/**
|
|
495
|
+
* Set features
|
|
496
|
+
*/
|
|
497
|
+
setFeatures: (features: string[]) => void;
|
|
498
|
+
/**
|
|
499
|
+
* Force refresh
|
|
500
|
+
*/
|
|
501
|
+
refresh: () => void;
|
|
447
502
|
}
|
|
448
503
|
/**
|
|
449
504
|
* Interface SCVoteContextType
|
|
@@ -628,9 +683,13 @@ export interface SCIntegrationsType {
|
|
|
628
683
|
* OpenAI
|
|
629
684
|
*/
|
|
630
685
|
openai?: SCIntegrationsOpenAIType;
|
|
686
|
+
/**
|
|
687
|
+
* Geocoding
|
|
688
|
+
*/
|
|
689
|
+
geocoding?: SCGeocodingType;
|
|
631
690
|
}
|
|
632
691
|
/**
|
|
633
|
-
* Interface
|
|
692
|
+
* Interface SCIntegrationsOpenAIType
|
|
634
693
|
*/
|
|
635
694
|
export interface SCIntegrationsOpenAIType {
|
|
636
695
|
/**
|
|
@@ -639,3 +698,13 @@ export interface SCIntegrationsOpenAIType {
|
|
|
639
698
|
*/
|
|
640
699
|
secretKey: string | null;
|
|
641
700
|
}
|
|
701
|
+
/**
|
|
702
|
+
* Interface SCGeocodingType
|
|
703
|
+
*/
|
|
704
|
+
export interface SCGeocodingType {
|
|
705
|
+
/**
|
|
706
|
+
* Set secretKey geocoding service
|
|
707
|
+
* Default: null
|
|
708
|
+
*/
|
|
709
|
+
apiKey: string | null;
|
|
710
|
+
}
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SCUserContextType, SCFollowedManagerType, SCFollowersManagerType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCSubscribedIncubatorsManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCPreferencesContextType, SCNotificationContextType, SCLocaleType, SCVoteType, SCVoteContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCSubscribedGroupsManagerType } from './context';
|
|
1
|
+
import { SCUserContextType, SCFollowedManagerType, SCFollowersManagerType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCSubscribedIncubatorsManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCPreferencesContextType, SCNotificationContextType, SCLocaleType, SCVoteType, SCVoteContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType } from './context';
|
|
2
2
|
import { SCThemeAvatarVariableType, SCThemeUserVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType } from './theme';
|
|
3
|
-
export { SCUserContextType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCVoteType, SCVoteContextType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeUserVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, };
|
|
3
|
+
export { SCUserContextType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCVoteType, SCVoteContextType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeUserVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, };
|
|
@@ -36,6 +36,8 @@ export declare class ValidationError {
|
|
|
36
36
|
static ERROR_INVALID_INTEGRATIONS: number;
|
|
37
37
|
static ERROR_INVALID_INTEGRATIONS_OPENAI: number;
|
|
38
38
|
static ERROR_INVALID_INTEGRATIONS_OPENAI_SECRETKEY: number;
|
|
39
|
+
static ERROR_INVALID_INTEGRATIONS_GEOCODING: number;
|
|
40
|
+
static ERROR_INVALID_INTEGRATIONS_GEOCODING_APIKEY: number;
|
|
39
41
|
static defaultErrorMessageMap: {
|
|
40
42
|
[x: number]: string;
|
|
41
43
|
};
|
package/lib/esm/utils/errors.js
CHANGED
|
@@ -48,6 +48,8 @@ ValidationError.ERROR_INVALID_VOTE_REACTIONS_STRUCTURE = 6002;
|
|
|
48
48
|
ValidationError.ERROR_INVALID_INTEGRATIONS = 6100;
|
|
49
49
|
ValidationError.ERROR_INVALID_INTEGRATIONS_OPENAI = 6101;
|
|
50
50
|
ValidationError.ERROR_INVALID_INTEGRATIONS_OPENAI_SECRETKEY = 6102;
|
|
51
|
+
ValidationError.ERROR_INVALID_INTEGRATIONS_GEOCODING = 6103;
|
|
52
|
+
ValidationError.ERROR_INVALID_INTEGRATIONS_GEOCODING_APIKEY = 6104;
|
|
51
53
|
ValidationError.defaultErrorMessageMap = {
|
|
52
54
|
[ValidationError.ERROR_INVALID_CONF]: 'Invalid or missing library configuration. Check the configuration that is passed to the SCContextProvider.',
|
|
53
55
|
[ValidationError.ERROR_INVALID_SESSION]: 'Invalid session format.',
|
|
@@ -82,6 +84,8 @@ ValidationError.defaultErrorMessageMap = {
|
|
|
82
84
|
[ValidationError.ERROR_INVALID_INTEGRATIONS]: 'Invalid integrations conf.',
|
|
83
85
|
[ValidationError.ERROR_INVALID_INTEGRATIONS_OPENAI]: 'Invalid integrations (openai) option.',
|
|
84
86
|
[ValidationError.ERROR_INVALID_INTEGRATIONS_OPENAI_SECRETKEY]: 'Invalid integrations openai conf: secretKey must be a string value.',
|
|
87
|
+
[ValidationError.ERROR_INVALID_INTEGRATIONS_GEOCODING]: 'Invalid integrations (geocoding) option.',
|
|
88
|
+
[ValidationError.ERROR_INVALID_INTEGRATIONS_GEOCODING_APIKEY]: 'Invalid integrations geocoding conf: apiKey must be a string value.',
|
|
85
89
|
};
|
|
86
90
|
/**
|
|
87
91
|
* Manage Validation Warnings
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SCEventSubscriptionStatusType, SCEventType } from '@selfcommunity/types';
|
|
2
|
+
/**
|
|
3
|
+
* Get event status
|
|
4
|
+
* @returns status or null
|
|
5
|
+
* @param event
|
|
6
|
+
* @param going
|
|
7
|
+
*/
|
|
8
|
+
export declare function getEventStatus(event: SCEventType, going: boolean): SCEventSubscriptionStatusType | null;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SCEventPrivacyType, SCEventSubscriptionStatusType } from '@selfcommunity/types';
|
|
2
|
+
/**
|
|
3
|
+
* Get event status
|
|
4
|
+
* @returns status or null
|
|
5
|
+
* @param event
|
|
6
|
+
* @param going
|
|
7
|
+
*/
|
|
8
|
+
export function getEventStatus(event, going) {
|
|
9
|
+
const { subscription_status: status, privacy } = event;
|
|
10
|
+
if (!status) {
|
|
11
|
+
return privacy === SCEventPrivacyType.PRIVATE ? SCEventSubscriptionStatusType.REQUESTED : SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
12
|
+
}
|
|
13
|
+
switch (status) {
|
|
14
|
+
case SCEventSubscriptionStatusType.INVITED:
|
|
15
|
+
case SCEventSubscriptionStatusType.GOING:
|
|
16
|
+
case SCEventSubscriptionStatusType.NOT_GOING:
|
|
17
|
+
return SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
18
|
+
case SCEventSubscriptionStatusType.SUBSCRIBED:
|
|
19
|
+
return going ? SCEventSubscriptionStatusType.GOING : SCEventSubscriptionStatusType.NOT_GOING;
|
|
20
|
+
case SCEventSubscriptionStatusType.REQUESTED:
|
|
21
|
+
return privacy === SCEventPrivacyType.PRIVATE ? null : SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
22
|
+
default:
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/lib/esm/utils/user.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { SCUserType } from '@selfcommunity/types';
|
|
|
6
6
|
export declare const ADMIN_ROLE = "admin";
|
|
7
7
|
export declare const MODERATOR_ROLE = "moderator";
|
|
8
8
|
export declare const EDITOR_ROLE = "editor";
|
|
9
|
+
export declare const COMMUNITY_CREATOR = 1;
|
|
9
10
|
/**
|
|
10
11
|
* Get user role from roles(set)
|
|
11
12
|
* @param user
|
|
@@ -18,6 +19,12 @@ export declare function getUserRole(user: SCUserType): string | null;
|
|
|
18
19
|
* @returns boolean
|
|
19
20
|
*/
|
|
20
21
|
export declare function isAdmin(user: SCUserType): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Check if user is admin
|
|
24
|
+
* @param user
|
|
25
|
+
* @returns boolean
|
|
26
|
+
*/
|
|
27
|
+
export declare function isCommunityCreator(user: SCUserType): boolean;
|
|
21
28
|
/**
|
|
22
29
|
* Check if user is moderator
|
|
23
30
|
* @param user
|
package/lib/esm/utils/user.js
CHANGED
|
@@ -6,6 +6,7 @@ import { SCUserStatus } from '@selfcommunity/types';
|
|
|
6
6
|
export const ADMIN_ROLE = 'admin';
|
|
7
7
|
export const MODERATOR_ROLE = 'moderator';
|
|
8
8
|
export const EDITOR_ROLE = 'editor';
|
|
9
|
+
export const COMMUNITY_CREATOR = 1;
|
|
9
10
|
/**
|
|
10
11
|
* Get user role from roles(set)
|
|
11
12
|
* @param user
|
|
@@ -34,6 +35,14 @@ export function getUserRole(user) {
|
|
|
34
35
|
export function isAdmin(user) {
|
|
35
36
|
return getUserRole(user) === ADMIN_ROLE;
|
|
36
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if user is admin
|
|
40
|
+
* @param user
|
|
41
|
+
* @returns boolean
|
|
42
|
+
*/
|
|
43
|
+
export function isCommunityCreator(user) {
|
|
44
|
+
return user && user.id === COMMUNITY_CREATOR;
|
|
45
|
+
}
|
|
37
46
|
/**
|
|
38
47
|
* Check if user is moderator
|
|
39
48
|
* @param user
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SCIntegrationsOpenAIType, SCIntegrationsType, SCNotificationsMobileNativePushMessagingType, SCNotificationsType, SCNotificationsWebPushMessagingType, SCNotificationsWebSocketType, SCSettingsType } from '../types/context';
|
|
1
|
+
import { SCGeocodingType, SCIntegrationsOpenAIType, SCIntegrationsType, SCNotificationsMobileNativePushMessagingType, SCNotificationsType, SCNotificationsWebPushMessagingType, SCNotificationsWebSocketType, SCSettingsType } from '../types/context';
|
|
2
2
|
import { ValidationResult } from './errors';
|
|
3
3
|
import { SCLocaleType } from '../types';
|
|
4
4
|
/**
|
|
@@ -320,6 +320,9 @@ export declare function validateIntegrations(v: SCIntegrationsType): {
|
|
|
320
320
|
openai: {
|
|
321
321
|
secretKey: any;
|
|
322
322
|
};
|
|
323
|
+
geocoding: {
|
|
324
|
+
apiKey: any;
|
|
325
|
+
};
|
|
323
326
|
};
|
|
324
327
|
};
|
|
325
328
|
/**
|
|
@@ -337,6 +340,21 @@ export declare const validateOpenAI: (v: any) => {
|
|
|
337
340
|
value: SCIntegrationsOpenAIType;
|
|
338
341
|
v?: undefined;
|
|
339
342
|
};
|
|
343
|
+
/**
|
|
344
|
+
* Validate Geocoding Option
|
|
345
|
+
* @param v
|
|
346
|
+
*/
|
|
347
|
+
export declare const validateGeocoding: (v: any) => {
|
|
348
|
+
errors: any[];
|
|
349
|
+
warnings: any[];
|
|
350
|
+
v: any;
|
|
351
|
+
value?: undefined;
|
|
352
|
+
} | {
|
|
353
|
+
errors: any[];
|
|
354
|
+
warnings: any[];
|
|
355
|
+
value: SCGeocodingType;
|
|
356
|
+
v?: undefined;
|
|
357
|
+
};
|
|
340
358
|
/**
|
|
341
359
|
* Validate OpenAI secret key option
|
|
342
360
|
* @param value
|
|
@@ -347,6 +365,16 @@ export declare const validateOpenAISecretKey: (value: any) => {
|
|
|
347
365
|
warnings: any[];
|
|
348
366
|
value: any;
|
|
349
367
|
};
|
|
368
|
+
/**
|
|
369
|
+
* Validate Geocoding api key option
|
|
370
|
+
* @param value
|
|
371
|
+
* @return {}
|
|
372
|
+
*/
|
|
373
|
+
export declare const validateGeocodingApiKey: (value: any) => {
|
|
374
|
+
errors: any[];
|
|
375
|
+
warnings: any[];
|
|
376
|
+
value: any;
|
|
377
|
+
};
|
|
350
378
|
/**
|
|
351
379
|
* Valid options
|
|
352
380
|
* @type {{}}
|
|
@@ -362,6 +390,7 @@ export declare const preferencesOptions: Record<string, any>;
|
|
|
362
390
|
export declare const voteOptions: Record<string, any>;
|
|
363
391
|
export declare const integrationsOptions: Record<string, any>;
|
|
364
392
|
export declare const integrationsOpenAIOptions: Record<string, any>;
|
|
393
|
+
export declare const integrationsGeocodingOptions: Record<string, any>;
|
|
365
394
|
export declare const validOptions: {
|
|
366
395
|
[x: string]: any;
|
|
367
396
|
};
|
|
@@ -639,6 +639,30 @@ export const validateOpenAI = (v) => {
|
|
|
639
639
|
}, {});
|
|
640
640
|
return { errors, warnings, value };
|
|
641
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
|
+
};
|
|
642
666
|
/**
|
|
643
667
|
* Validate OpenAI secret key option
|
|
644
668
|
* @param value
|
|
@@ -652,6 +676,19 @@ export const validateOpenAISecretKey = (value) => {
|
|
|
652
676
|
}
|
|
653
677
|
return { errors, warnings, value };
|
|
654
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
|
+
};
|
|
655
692
|
/**
|
|
656
693
|
* Components Widget
|
|
657
694
|
*/
|
|
@@ -786,6 +823,14 @@ const IntegrationOpenAISecretKeyOption = {
|
|
|
786
823
|
name: Integrations.INTEGRATIONS_OPENAI_SECRETKEY_OPTION,
|
|
787
824
|
validator: validateOpenAISecretKey,
|
|
788
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
|
+
};
|
|
789
834
|
/**
|
|
790
835
|
* Valid options
|
|
791
836
|
* @type {{}}
|
|
@@ -840,10 +885,14 @@ export const voteOptions = {
|
|
|
840
885
|
};
|
|
841
886
|
export const integrationsOptions = {
|
|
842
887
|
[IntegrationOpenAIOption.name]: IntegrationOpenAIOption,
|
|
888
|
+
[IntegrationGeocodingOption.name]: IntegrationGeocodingOption,
|
|
843
889
|
};
|
|
844
890
|
export const integrationsOpenAIOptions = {
|
|
845
891
|
[IntegrationOpenAISecretKeyOption.name]: IntegrationOpenAISecretKeyOption,
|
|
846
892
|
};
|
|
893
|
+
export const integrationsGeocodingOptions = {
|
|
894
|
+
[IntegrationGeocodingApiKeyOption.name]: IntegrationGeocodingApiKeyOption,
|
|
895
|
+
};
|
|
847
896
|
export const validOptions = Object.assign({}, settingsOptions);
|
|
848
897
|
/**
|
|
849
898
|
* Validate all options by type
|