@selfcommunity/react-core 0.1.4 → 0.1.5-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.
Files changed (154) hide show
  1. package/lib/cjs/components/provider/SCLocaleProvider/index.js +2 -2
  2. package/lib/cjs/components/provider/SCPreferencesProvider/index.js +2 -2
  3. package/lib/cjs/components/provider/SCUserProvider/index.js +3 -3
  4. package/lib/cjs/hooks/useSCAuth.js +3 -3
  5. package/lib/cjs/hooks/useSCConnectionsManager.js +3 -3
  6. package/lib/cjs/hooks/useSCFetchCategories.js +2 -2
  7. package/lib/cjs/hooks/useSCFetchCategory.js +3 -3
  8. package/lib/cjs/hooks/useSCFetchCommentObject.js +3 -3
  9. package/lib/cjs/hooks/useSCFetchCommentObjects.js +3 -3
  10. package/lib/cjs/hooks/useSCFetchCustomAdv.js +3 -3
  11. package/lib/cjs/hooks/useSCFetchFeedObject.js +3 -3
  12. package/lib/cjs/hooks/useSCFetchIncubator.js +3 -3
  13. package/lib/cjs/hooks/useSCFetchTag.js +3 -3
  14. package/lib/cjs/hooks/useSCFetchUser.js +3 -3
  15. package/lib/cjs/hooks/useSCFollowedCategoriesManager.js +3 -3
  16. package/lib/cjs/hooks/useSCFollowersManager.js +3 -3
  17. package/lib/cjs/hooks/useSCMediaClick.js +2 -2
  18. package/lib/cjs/hooks/useSCSubscribedIncubatorsManager.js +3 -3
  19. package/lib/cjs/hooks/useSCWebPushMessaging.js +19 -21
  20. package/lib/cjs/hooks/useSCWebSocket.js +2 -2
  21. package/lib/cjs/index.js +1 -23
  22. package/lib/cjs/themes/theme.js +3 -5
  23. package/lib/cjs/utils/errors.js +3 -3
  24. package/lib/cjs/utils/locale.js +4 -4
  25. package/lib/cjs/utils/validator.js +16 -22
  26. package/lib/esm/api-services/src/constants/Endpoints.d.ts.map +1 -1
  27. package/lib/esm/api-services/src/index.d.ts +26 -3
  28. package/lib/esm/api-services/src/index.d.ts.map +1 -1
  29. package/lib/esm/api-services/src/services/category/index.d.ts +42 -0
  30. package/lib/esm/api-services/src/services/category/index.d.ts.map +1 -1
  31. package/lib/esm/api-services/src/services/comment/index.d.ts +40 -0
  32. package/lib/esm/api-services/src/services/comment/index.d.ts.map +1 -0
  33. package/lib/esm/api-services/src/services/custom_adv/index.d.ts +16 -0
  34. package/lib/esm/api-services/src/services/custom_adv/index.d.ts.map +1 -0
  35. package/lib/esm/api-services/src/services/custom_page/index.d.ts +16 -0
  36. package/lib/esm/api-services/src/services/custom_page/index.d.ts.map +1 -0
  37. package/lib/esm/api-services/src/services/data_portability/index.d.ts +16 -0
  38. package/lib/esm/api-services/src/services/data_portability/index.d.ts.map +1 -0
  39. package/lib/esm/api-services/src/services/dynamic_preference/index.d.ts +16 -0
  40. package/lib/esm/api-services/src/services/dynamic_preference/index.d.ts.map +1 -0
  41. package/lib/esm/api-services/src/services/embed/index.d.ts +31 -0
  42. package/lib/esm/api-services/src/services/embed/index.d.ts.map +1 -0
  43. package/lib/esm/api-services/src/services/feed/index.d.ts +22 -0
  44. package/lib/esm/api-services/src/services/feed/index.d.ts.map +1 -0
  45. package/lib/esm/api-services/src/services/feed_object/index.d.ts +88 -0
  46. package/lib/esm/api-services/src/services/feed_object/index.d.ts.map +1 -0
  47. package/lib/esm/api-services/src/services/incubator/index.d.ts +28 -0
  48. package/lib/esm/api-services/src/services/incubator/index.d.ts.map +1 -0
  49. package/lib/esm/api-services/src/services/insight/index.d.ts +25 -0
  50. package/lib/esm/api-services/src/services/insight/index.d.ts.map +1 -0
  51. package/lib/esm/api-services/src/services/legal_page/index.d.ts +25 -0
  52. package/lib/esm/api-services/src/services/legal_page/index.d.ts.map +1 -0
  53. package/lib/esm/api-services/src/services/locality/index.d.ts +13 -0
  54. package/lib/esm/api-services/src/services/locality/index.d.ts.map +1 -0
  55. package/lib/esm/api-services/src/services/loyalty/index.d.ts +34 -0
  56. package/lib/esm/api-services/src/services/loyalty/index.d.ts.map +1 -0
  57. package/lib/esm/api-services/src/services/media/index.d.ts +28 -0
  58. package/lib/esm/api-services/src/services/media/index.d.ts.map +1 -0
  59. package/lib/esm/api-services/src/services/moderation/index.d.ts +25 -0
  60. package/lib/esm/api-services/src/services/moderation/index.d.ts.map +1 -0
  61. package/lib/esm/api-services/src/services/notification/index.d.ts +34 -0
  62. package/lib/esm/api-services/src/services/notification/index.d.ts.map +1 -0
  63. package/lib/esm/api-services/src/services/private_message/index.d.ts +37 -0
  64. package/lib/esm/api-services/src/services/private_message/index.d.ts.map +1 -0
  65. package/lib/esm/api-services/src/services/score/index.d.ts +16 -0
  66. package/lib/esm/api-services/src/services/score/index.d.ts.map +1 -0
  67. package/lib/esm/api-services/src/services/sso/index.d.ts +13 -0
  68. package/lib/esm/api-services/src/services/sso/index.d.ts.map +1 -0
  69. package/lib/esm/api-services/src/services/suggestion/index.d.ts +19 -0
  70. package/lib/esm/api-services/src/services/suggestion/index.d.ts.map +1 -0
  71. package/lib/esm/api-services/src/services/tag/index.d.ts +28 -0
  72. package/lib/esm/api-services/src/services/tag/index.d.ts.map +1 -0
  73. package/lib/esm/api-services/src/services/user/index.d.ts +132 -0
  74. package/lib/esm/api-services/src/services/user/index.d.ts.map +1 -1
  75. package/lib/esm/api-services/src/services/webhook/index.d.ts +43 -0
  76. package/lib/esm/api-services/src/services/webhook/index.d.ts.map +1 -0
  77. package/lib/esm/api-services/src/utils/token.d.ts +5 -0
  78. package/lib/esm/api-services/src/utils/token.d.ts.map +1 -1
  79. package/lib/esm/components/provider/SCLocaleProvider/index.js +2 -2
  80. package/lib/esm/components/provider/SCPreferencesProvider/index.js +2 -2
  81. package/lib/esm/components/provider/SCUserProvider/index.js +3 -3
  82. package/lib/esm/hooks/useSCAuth.js +3 -3
  83. package/lib/esm/hooks/useSCConnectionsManager.js +3 -3
  84. package/lib/esm/hooks/useSCFetchCategories.js +2 -2
  85. package/lib/esm/hooks/useSCFetchCategory.js +3 -3
  86. package/lib/esm/hooks/useSCFetchCommentObject.js +3 -3
  87. package/lib/esm/hooks/useSCFetchCommentObjects.js +3 -3
  88. package/lib/esm/hooks/useSCFetchCustomAdv.js +3 -3
  89. package/lib/esm/hooks/useSCFetchFeedObject.js +3 -3
  90. package/lib/esm/hooks/useSCFetchIncubator.js +3 -3
  91. package/lib/esm/hooks/useSCFetchTag.js +3 -3
  92. package/lib/esm/hooks/useSCFetchUser.js +3 -3
  93. package/lib/esm/hooks/useSCFollowedCategoriesManager.js +3 -3
  94. package/lib/esm/hooks/useSCFollowersManager.js +3 -3
  95. package/lib/esm/hooks/useSCMediaClick.js +2 -2
  96. package/lib/esm/hooks/useSCSubscribedIncubatorsManager.js +3 -3
  97. package/lib/esm/hooks/useSCWebPushMessaging.js +19 -21
  98. package/lib/esm/hooks/useSCWebSocket.js +2 -2
  99. package/lib/esm/index.js +1 -23
  100. package/lib/esm/react-core/src/hooks/useSCFetchAddressingTagList.d.ts.map +1 -1
  101. package/lib/esm/react-core/src/hooks/useSCFetchCommentObjects.d.ts +1 -2
  102. package/lib/esm/react-core/src/hooks/useSCFetchCommentObjects.d.ts.map +1 -1
  103. package/lib/esm/react-core/src/hooks/useSCWebSocket.d.ts +1 -1
  104. package/lib/esm/react-core/src/hooks/useSCWebSocket.d.ts.map +1 -1
  105. package/lib/esm/react-core/src/index.d.ts +2 -7
  106. package/lib/esm/react-core/src/index.d.ts.map +1 -1
  107. package/lib/esm/react-core/src/utils/validator.d.ts.map +1 -1
  108. package/lib/esm/themes/theme.js +3 -5
  109. package/lib/esm/utils/errors.js +3 -3
  110. package/lib/esm/utils/locale.js +4 -4
  111. package/lib/esm/utils/src/index.d.ts +8 -3
  112. package/lib/esm/utils/src/index.d.ts.map +1 -1
  113. package/lib/esm/utils/src/utils/browser.d.ts +9 -0
  114. package/lib/esm/utils/src/utils/browser.d.ts.map +1 -0
  115. package/lib/esm/{react-core → utils}/src/utils/logger.d.ts +0 -0
  116. package/lib/esm/utils/src/utils/logger.d.ts.map +1 -0
  117. package/lib/esm/{react-core → utils}/src/utils/object.d.ts +0 -0
  118. package/lib/esm/utils/src/utils/object.d.ts.map +1 -0
  119. package/lib/esm/utils/src/utils/string.d.ts +22 -0
  120. package/lib/esm/utils/src/utils/string.d.ts.map +1 -1
  121. package/lib/esm/utils/src/utils/url.d.ts +11 -0
  122. package/lib/esm/utils/src/utils/url.d.ts.map +1 -1
  123. package/lib/esm/{react-core → utils}/src/utils/websocket.d.ts +0 -0
  124. package/lib/esm/utils/src/utils/websocket.d.ts.map +1 -0
  125. package/lib/esm/utils/validator.js +16 -22
  126. package/lib/umd/react-core.js +1 -1
  127. package/package.json +6 -5
  128. package/lib/cjs/scss/styles.scss +0 -1
  129. package/lib/cjs/utils/logger.js +0 -32
  130. package/lib/cjs/utils/object.js +0 -44
  131. package/lib/cjs/utils/session.js +0 -17
  132. package/lib/cjs/utils/string.js +0 -57
  133. package/lib/cjs/utils/url.js +0 -70
  134. package/lib/cjs/utils/webPushMessaging.js +0 -110
  135. package/lib/cjs/utils/websocket.js +0 -307
  136. package/lib/esm/react-core/src/utils/logger.d.ts.map +0 -1
  137. package/lib/esm/react-core/src/utils/object.d.ts.map +0 -1
  138. package/lib/esm/react-core/src/utils/session.d.ts +0 -6
  139. package/lib/esm/react-core/src/utils/session.d.ts.map +0 -1
  140. package/lib/esm/react-core/src/utils/string.d.ts +0 -21
  141. package/lib/esm/react-core/src/utils/string.d.ts.map +0 -1
  142. package/lib/esm/react-core/src/utils/url.d.ts +0 -22
  143. package/lib/esm/react-core/src/utils/url.d.ts.map +0 -1
  144. package/lib/esm/react-core/src/utils/webPushMessaging.d.ts +0 -14
  145. package/lib/esm/react-core/src/utils/webPushMessaging.d.ts.map +0 -1
  146. package/lib/esm/react-core/src/utils/websocket.d.ts.map +0 -1
  147. package/lib/esm/scss/styles.scss +0 -1
  148. package/lib/esm/utils/logger.js +0 -32
  149. package/lib/esm/utils/object.js +0 -44
  150. package/lib/esm/utils/session.js +0 -17
  151. package/lib/esm/utils/string.js +0 -57
  152. package/lib/esm/utils/url.js +0 -70
  153. package/lib/esm/utils/webPushMessaging.js +0 -110
  154. package/lib/esm/utils/websocket.js +0 -307
@@ -1,307 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
-
6
- /**
7
- * WSClientPropTypes interface
8
- */
9
-
10
- /**
11
- * WSClient: manage socket connection
12
- * @param options
13
- * @constructor
14
- */
15
- class WSClient {
16
- /**
17
- * Constructor
18
- * @param cfg
19
- */
20
- constructor(cfg) {
21
- this._attempts = 1;
22
- this._heartbeatInterval = null;
23
- this._missedHeartbeats = 0;
24
-
25
- if (!this.isValidOptions(cfg)) {
26
- return;
27
- }
28
-
29
- this._cfg = Object.assign({}, {
30
- heartbeatMsg: null,
31
- debug: false,
32
- mustReconnect: true
33
- }, cfg);
34
- this.connect();
35
- }
36
- /**
37
- * Get instance
38
- */
39
-
40
-
41
- static getInstance(cfg) {
42
- this._instance = this._instance || new WSClient(cfg);
43
- return this._instance;
44
- }
45
- /**
46
- * Connect
47
- */
48
-
49
-
50
- connect() {
51
- try {
52
- if (this._ws && (this.isConnecting() || this.isConnected())) {
53
- // There is already a connection
54
- this._cfg.debug && console.info('Websocket is connecting or already connected.');
55
- return;
56
- } // Callback 'connecting' if exist
57
-
58
-
59
- typeof this._cfg.connecting === 'function' && this._cfg.connecting();
60
- this._cfg.debug && console.info(`Connecting to ${this._cfg.uri} ...`); // Open the connection
61
-
62
- this._ws = new WebSocket(this._cfg.uri, this._cfg.protocols);
63
- this._ws.onopen = this.onOpen.bind(this);
64
- this._ws.onmessage = this.onMessage.bind(this);
65
- this._ws.onerror = this.onError.bind(this);
66
- this._ws.onclose = this.onClose.bind(this);
67
- this._timer = null;
68
- } catch (err) {
69
- console.error(err);
70
- this.tryToReconnect();
71
- }
72
- }
73
- /**
74
- * Validate options
75
- * @param cfg
76
- */
77
-
78
-
79
- isValidOptions(cfg) {
80
- let _error = false;
81
-
82
- if (!cfg) {
83
- console.error('Invalid WSClient options.');
84
- return _error;
85
- }
86
-
87
- if (!cfg.uri) {
88
- console.error('Invalid WSClient Uri options.');
89
- _error = true;
90
- }
91
-
92
- if (cfg && cfg.connecting && !(typeof cfg.connecting === 'function')) {
93
- console.error('Invalid WSClient connecting options.');
94
- _error = true;
95
- }
96
-
97
- if (cfg && cfg.connected && !(typeof cfg.connected === 'function')) {
98
- console.error('Invalid WSClient connected options.');
99
- _error = true;
100
- }
101
-
102
- if (cfg && cfg.receiveMessage && !(typeof cfg.receiveMessage === 'function')) {
103
- console.error('Invalid WSClient receiveMessage options.');
104
- _error = true;
105
- }
106
-
107
- if (cfg && cfg.disconnected && !(typeof cfg.disconnected === 'function')) {
108
- console.error('Invalid WSClient connecting options.');
109
- _error = true;
110
- }
111
-
112
- if (cfg && cfg.heartbeatMsg && !(typeof cfg.heartbeatMsg === 'string')) {
113
- console.error('Invalid WSClient heartbeatMsg options.');
114
- _error = true;
115
- }
116
-
117
- if (cfg && cfg.debug && !(typeof cfg.debug === 'boolean')) {
118
- console.error('Invalid WSClient debug options.');
119
- _error = true;
120
- }
121
-
122
- return !_error;
123
- }
124
- /**
125
- * Try to reconnect if previous connection failed
126
- * Generate an interval, after that try to reconnect
127
- */
128
-
129
-
130
- tryToReconnect() {
131
- if (this._cfg.mustReconnect && !this._timer) {
132
- this._cfg.debug && console.info(`Reconnecting...`);
133
- let interval = this.generateInteval(this._attempts);
134
- this._timer = setTimeout(this.reconnect.bind(this), interval);
135
- }
136
- }
137
- /**
138
- * Reestablish the connection
139
- * Increase the number of attempts
140
- */
141
-
142
-
143
- reconnect() {
144
- this._attempts++;
145
- this.connect();
146
- }
147
- /**
148
- * Send heartbeat every 5 seconds
149
- * If missing more than 3 heartbeats close connection
150
- */
151
-
152
-
153
- sendHeartbeat() {
154
- try {
155
- this._missedHeartbeats++;
156
- if (this._missedHeartbeats > 3) throw new Error('Too many missed heartbeats.');
157
-
158
- this._ws.send(this._cfg.heartbeatMsg);
159
- } catch (e) {
160
- clearInterval(this._heartbeatInterval);
161
- this._heartbeatInterval = null;
162
- this._cfg.debug && console.warn(`Closing connection. Reason: ${e.message}`);
163
-
164
- if (!this.isClosing() && !this.isClosed()) {
165
- this.close();
166
- }
167
- }
168
- }
169
- /**
170
- * Established the new connection
171
- * Reset this._attempts counter
172
- */
173
-
174
-
175
- onOpen() {
176
- this._cfg.debug && console.info('Connected!');
177
- this._attempts = 1;
178
-
179
- if (this._cfg.heartbeatMsg && this._heartbeatInterval === null) {
180
- this._missedHeartbeats = 0;
181
- this._heartbeatInterval = setInterval(this.sendHeartbeat.bind(this), 5000);
182
- }
183
-
184
- typeof this._cfg.connected === 'function' && this._cfg.connected();
185
- }
186
- /**
187
- * Connection closed. Try to reconnect.
188
- * @param evt
189
- */
190
-
191
-
192
- onClose(evt) {
193
- this._cfg.debug && console.info('Connection closed!');
194
- typeof this._cfg.disconnected === 'function' && this._cfg.disconnected(evt);
195
- this.tryToReconnect();
196
- }
197
- /**
198
- * An error occured
199
- * @param evt
200
- */
201
-
202
-
203
- onError(evt) {
204
- this._cfg.debug && console.error('Websocket connection is broken!');
205
- this._cfg.debug && console.error(evt);
206
- }
207
- /**
208
- * A message has arrived.
209
- * If it is the heartbeat -> reset this._missedHeartbeats
210
- * If it is data pass data to the callback
211
- * @param evt
212
- */
213
-
214
-
215
- onMessage(evt) {
216
- if (this._cfg.heartbeatMsg && evt.data === this._cfg.heartbeatMsg) {
217
- // reset the counter for missed heartbeats
218
- this._missedHeartbeats = 0;
219
- } else if (typeof this._cfg.receiveMessage === 'function') {
220
- return this._cfg.receiveMessage(evt.data);
221
- }
222
- }
223
- /**
224
- * Generate an interval that is randomly between 0 and 2^k - 1, where k is
225
- * the number of connection attmpts, with a maximum interval of 30 seconds,
226
- * so it starts at 0 - 1 seconds and maxes out at 0 - 30 seconds
227
- */
228
-
229
-
230
- generateInteval(k) {
231
- let maxInterval = (Math.pow(2, k) - 1) * 1000; // If the generated interval is more than 30 seconds, truncate it down to 30 seconds.
232
-
233
- if (maxInterval > 30 * 1000) {
234
- maxInterval = 30 * 1000;
235
- } // generate the interval to a random number between 0 and the maxInterval determined from above
236
-
237
-
238
- return Math.random() * maxInterval;
239
- }
240
- /**
241
- * Send message
242
- * @param message
243
- */
244
-
245
-
246
- sendMessage(message) {
247
- this._ws && this._ws.send(message);
248
- }
249
- /**
250
- * Get the ws state
251
- */
252
-
253
-
254
- getState() {
255
- return this._ws && this._ws.readyState;
256
- }
257
- /**
258
- * Check if ws is in connecting state
259
- */
260
-
261
-
262
- isConnecting() {
263
- return this._ws && this._ws.readyState === 0;
264
- }
265
- /**
266
- * Check if ws is connected
267
- */
268
-
269
-
270
- isConnected() {
271
- return this._ws && this._ws.readyState === 1;
272
- }
273
- /**
274
- * Check if ws is in closing state
275
- */
276
-
277
-
278
- isClosing() {
279
- return this._ws && this._ws.readyState === 2;
280
- }
281
- /**
282
- * Check if ws is closed
283
- */
284
-
285
-
286
- isClosed() {
287
- return this._ws && this._ws.readyState === 3;
288
- }
289
- /**
290
- * Close the connection
291
- */
292
-
293
-
294
- close() {
295
- clearInterval(this._heartbeatInterval);
296
- this._cfg.mustReconnect = false;
297
-
298
- if (!this.isClosing() || !this.isClosed()) {
299
- this._ws.close();
300
-
301
- this._cfg.debug && console.error('Websocket closed.');
302
- }
303
- }
304
-
305
- }
306
-
307
- exports.default = WSClient;