@selfcommunity/react-core 0.6.0-alpha.2 → 0.6.0-alpha.4
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/hooks/useSCFetchEvent.js +7 -3
- package/lib/cjs/hooks/useSCWebSocket.js +3 -1
- package/lib/cjs/utils/validator.d.ts +1 -1
- package/lib/cjs/utils/validator.js +7 -2
- package/lib/esm/hooks/useSCFetchEvent.js +7 -3
- package/lib/esm/hooks/useSCWebSocket.js +3 -1
- package/lib/esm/utils/validator.d.ts +1 -1
- package/lib/esm/utils/validator.js +7 -2
- package/lib/umd/react-core.js +1 -1
- package/package.json +2 -2
|
@@ -19,7 +19,6 @@ const SCUserProvider_1 = require("../components/provider/SCUserProvider");
|
|
|
19
19
|
* @param object.cacheStrategy
|
|
20
20
|
*/
|
|
21
21
|
function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheStrategy = utils_1.CacheStrategies.CACHE_FIRST, }) {
|
|
22
|
-
console.log('Params: ', event, id);
|
|
23
22
|
const __eventId = event ? event.id : id;
|
|
24
23
|
// CONTEXT
|
|
25
24
|
const scUserContext = (0, SCUserProvider_1.useSCUser)();
|
|
@@ -37,9 +36,14 @@ function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheS
|
|
|
37
36
|
authUserId !== null &&
|
|
38
37
|
((e.privacy === types_1.SCEventPrivacyType.PUBLIC && !e.subscription_status) || e.subscription_status === types_1.SCEventSubscriptionStatusType.INVITED)) {
|
|
39
38
|
// Auto subscribe to the event
|
|
40
|
-
api_services_1.EventService.subscribeToEvent(e.id)
|
|
39
|
+
api_services_1.EventService.subscribeToEvent(e.id)
|
|
40
|
+
.then(() => {
|
|
41
41
|
const updatedEvent = Object.assign(Object.assign({}, e), { subscription_status: types_1.SCEventSubscriptionStatusType.SUBSCRIBED });
|
|
42
|
-
|
|
42
|
+
setScEvent(updatedEvent);
|
|
43
|
+
utils_1.LRUCache.set(__eventCacheKey, updatedEvent);
|
|
44
|
+
})
|
|
45
|
+
.catch(() => {
|
|
46
|
+
const updatedEvent = authUserId ? e : (0, utils_1.objectWithoutProperties)(e, ['subscription_status']);
|
|
43
47
|
setScEvent(updatedEvent);
|
|
44
48
|
utils_1.LRUCache.set(__eventCacheKey, updatedEvent);
|
|
45
49
|
});
|
|
@@ -19,7 +19,9 @@ function useSCWebSocket() {
|
|
|
19
19
|
const scUserContext = (0, SCUserProvider_1.useSCUser)();
|
|
20
20
|
const [wsInstance, setWsInstance] = (0, react_1.useState)(null);
|
|
21
21
|
// Websocket uri, prefixPath, protocols and sub-protocols
|
|
22
|
-
const _wsProtocol = scContext.settings.notifications.webSocket.secure
|
|
22
|
+
const _wsProtocol = scContext.settings.notifications.webSocket.secure || !('secure' in scContext.settings.notifications.webSocket)
|
|
23
|
+
? WebSocket_1.WS_PROTOCOL_SECURE
|
|
24
|
+
: WebSocket_1.WS_PROTOCOL_INSECURE;
|
|
23
25
|
const _wsPrefixPath = scContext.settings.notifications.webSocket.prefixPath || WebSocket_1.WS_PREFIX_PATH;
|
|
24
26
|
const _wsUri = `${_wsProtocol}://${new URL(scContext.settings.portal).hostname}/${_wsPrefixPath}/${WebSocket_1.WS_FACILITY_NOTIFY}?subscribe-user`;
|
|
25
27
|
const _wsSubProtocol = scContext.settings.session.authToken && scContext.settings.session.authToken.accessToken
|
|
@@ -107,7 +107,7 @@ export declare const validateWebSocketDisableToastMessage: (value: any) => {
|
|
|
107
107
|
export declare const validateWebSocketSecure: (value: any) => {
|
|
108
108
|
errors: any[];
|
|
109
109
|
warnings: any[];
|
|
110
|
-
value:
|
|
110
|
+
value: any;
|
|
111
111
|
};
|
|
112
112
|
/**
|
|
113
113
|
* Validate prefixPath (webSocket)
|
|
@@ -169,6 +169,7 @@ const validateWebSocket = (v) => {
|
|
|
169
169
|
.filter((key) => _options.includes(key))
|
|
170
170
|
.reduce((obj, key) => {
|
|
171
171
|
const res = exports.notificationsWebSocketOptions[key].validator(v[key], v);
|
|
172
|
+
console.log(key, v, res);
|
|
172
173
|
res.errors.map((error) => errors.push(error));
|
|
173
174
|
res.warnings.map((warning) => warnings.push(warning));
|
|
174
175
|
obj[key] = res.value;
|
|
@@ -206,8 +207,12 @@ exports.validateWebSocketDisableToastMessage = validateWebSocketDisableToastMess
|
|
|
206
207
|
const validateWebSocketSecure = (value) => {
|
|
207
208
|
const errors = [];
|
|
208
209
|
const warnings = [];
|
|
209
|
-
if (
|
|
210
|
-
|
|
210
|
+
if ((value === null || value === void 0 ? void 0 : value.toString()) !== undefined) {
|
|
211
|
+
if (!(typeof value === 'boolean')) {
|
|
212
|
+
errors.push(errors_1.ValidationError.ERROR_INVALID_NOTIFICATIONS_WEBSOCKET_SECURE);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
211
216
|
return {
|
|
212
217
|
errors,
|
|
213
218
|
warnings,
|
|
@@ -17,7 +17,6 @@ import { useSCUser } from '../components/provider/SCUserProvider';
|
|
|
17
17
|
* @param object.cacheStrategy
|
|
18
18
|
*/
|
|
19
19
|
export default function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheStrategy = CacheStrategies.CACHE_FIRST, }) {
|
|
20
|
-
console.log('Params: ', event, id);
|
|
21
20
|
const __eventId = event ? event.id : id;
|
|
22
21
|
// CONTEXT
|
|
23
22
|
const scUserContext = useSCUser();
|
|
@@ -35,9 +34,14 @@ export default function useSCFetchEvent({ id = null, event = null, autoSubscribe
|
|
|
35
34
|
authUserId !== null &&
|
|
36
35
|
((e.privacy === SCEventPrivacyType.PUBLIC && !e.subscription_status) || e.subscription_status === SCEventSubscriptionStatusType.INVITED)) {
|
|
37
36
|
// Auto subscribe to the event
|
|
38
|
-
EventService.subscribeToEvent(e.id)
|
|
37
|
+
EventService.subscribeToEvent(e.id)
|
|
38
|
+
.then(() => {
|
|
39
39
|
const updatedEvent = Object.assign(Object.assign({}, e), { subscription_status: SCEventSubscriptionStatusType.SUBSCRIBED });
|
|
40
|
-
|
|
40
|
+
setScEvent(updatedEvent);
|
|
41
|
+
LRUCache.set(__eventCacheKey, updatedEvent);
|
|
42
|
+
})
|
|
43
|
+
.catch(() => {
|
|
44
|
+
const updatedEvent = authUserId ? e : objectWithoutProperties(e, ['subscription_status']);
|
|
41
45
|
setScEvent(updatedEvent);
|
|
42
46
|
LRUCache.set(__eventCacheKey, updatedEvent);
|
|
43
47
|
});
|
|
@@ -16,7 +16,9 @@ export default function useSCWebSocket() {
|
|
|
16
16
|
const scUserContext = useSCUser();
|
|
17
17
|
const [wsInstance, setWsInstance] = useState(null);
|
|
18
18
|
// Websocket uri, prefixPath, protocols and sub-protocols
|
|
19
|
-
const _wsProtocol = scContext.settings.notifications.webSocket.secure
|
|
19
|
+
const _wsProtocol = scContext.settings.notifications.webSocket.secure || !('secure' in scContext.settings.notifications.webSocket)
|
|
20
|
+
? WS_PROTOCOL_SECURE
|
|
21
|
+
: WS_PROTOCOL_INSECURE;
|
|
20
22
|
const _wsPrefixPath = scContext.settings.notifications.webSocket.prefixPath || WS_PREFIX_PATH;
|
|
21
23
|
const _wsUri = `${_wsProtocol}://${new URL(scContext.settings.portal).hostname}/${_wsPrefixPath}/${WS_FACILITY_NOTIFY}?subscribe-user`;
|
|
22
24
|
const _wsSubProtocol = scContext.settings.session.authToken && scContext.settings.session.authToken.accessToken
|
|
@@ -107,7 +107,7 @@ export declare const validateWebSocketDisableToastMessage: (value: any) => {
|
|
|
107
107
|
export declare const validateWebSocketSecure: (value: any) => {
|
|
108
108
|
errors: any[];
|
|
109
109
|
warnings: any[];
|
|
110
|
-
value:
|
|
110
|
+
value: any;
|
|
111
111
|
};
|
|
112
112
|
/**
|
|
113
113
|
* Validate prefixPath (webSocket)
|
|
@@ -158,6 +158,7 @@ export const validateWebSocket = (v) => {
|
|
|
158
158
|
.filter((key) => _options.includes(key))
|
|
159
159
|
.reduce((obj, key) => {
|
|
160
160
|
const res = notificationsWebSocketOptions[key].validator(v[key], v);
|
|
161
|
+
console.log(key, v, res);
|
|
161
162
|
res.errors.map((error) => errors.push(error));
|
|
162
163
|
res.warnings.map((warning) => warnings.push(warning));
|
|
163
164
|
obj[key] = res.value;
|
|
@@ -193,8 +194,12 @@ export const validateWebSocketDisableToastMessage = (value) => {
|
|
|
193
194
|
export const validateWebSocketSecure = (value) => {
|
|
194
195
|
const errors = [];
|
|
195
196
|
const warnings = [];
|
|
196
|
-
if (
|
|
197
|
-
|
|
197
|
+
if ((value === null || value === void 0 ? void 0 : value.toString()) !== undefined) {
|
|
198
|
+
if (!(typeof value === 'boolean')) {
|
|
199
|
+
errors.push(ValidationError.ERROR_INVALID_NOTIFICATIONS_WEBSOCKET_SECURE);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
198
203
|
return {
|
|
199
204
|
errors,
|
|
200
205
|
warnings,
|