@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@selfcommunity/react-core",
3
- "version": "0.1.4",
3
+ "version": "0.1.5-alpha.0",
4
4
  "description": "React Core Components useful for integrating UI Community components (react-ui).",
5
5
  "author": "SelfCommunity <https://www.selfcommunity.com>",
6
6
  "homepage": "https://www.selfcommunity.com",
@@ -57,9 +57,10 @@
57
57
  "react-intl": "^5.25.0"
58
58
  },
59
59
  "dependencies": {
60
- "@selfcommunity/api-services": "^0.1.4",
61
- "@selfcommunity/react-i18n": "^0.1.4",
62
- "@selfcommunity/types": "^0.1.4",
60
+ "@selfcommunity/api-services": "^0.1.5-alpha.0",
61
+ "@selfcommunity/react-i18n": "^0.1.5-alpha.0",
62
+ "@selfcommunity/types": "^0.1.5-alpha.0",
63
+ "@selfcommunity/utils": "^0.1.5-alpha.0",
63
64
  "pubsub-js": "^1.9.4",
64
65
  "react-singleton-hook": "^3.2.3",
65
66
  "use-deep-compare-effect": "^1.8.1",
@@ -124,5 +125,5 @@
124
125
  "bugs": {
125
126
  "url": "https://github.com/selfcommunity/community-js/issues"
126
127
  },
127
- "gitHead": "054ebdf2fe6993fa65a81e204cd34c678958e047"
128
+ "gitHead": "ce47fd80ccb32a7129728396883790828a3722cd"
128
129
  }
@@ -1 +0,0 @@
1
-
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.Logger = void 0;
5
-
6
- /**
7
- * Emit styled message
8
- */
9
- class Logger {
10
- static info(scope, message) {
11
- console.info(`%c[${scope}]`, 'color:#008080', ` ${message}`);
12
- }
13
-
14
- static warn(scope, message) {
15
- console.warn(`%c[${scope}]`, 'color:#008080', ` ${message}`);
16
- }
17
-
18
- static error(scope, message) {
19
- console.error(`%c[${scope}]`, 'color:#008080', ` ${message}`);
20
- }
21
-
22
- static log(scope, message) {
23
- console.log(`%c[${scope}]`, 'color:#008080', ` ${message}`);
24
- }
25
-
26
- static debug(scope, message) {
27
- console.debug(`%c[${scope}]`, 'color:#008080', ` ${message}`);
28
- }
29
-
30
- }
31
-
32
- exports.Logger = Logger;
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.isObject = isObject;
5
- exports.mergeDeep = mergeDeep;
6
-
7
- /**
8
- * Check if v is an object
9
- * @param v
10
- */
11
- function isObject(v) {
12
- return typeof v === 'object' && !Array.isArray(v) && v !== null;
13
- }
14
- /**
15
- * Perfrom deep merge of two objects (not a shallow merge)
16
- * @param target
17
- * @param source
18
- * @return {*}
19
- */
20
-
21
-
22
- function mergeDeep(target, source) {
23
- let output = Object.assign({}, target);
24
-
25
- if (isObject(target) && isObject(source)) {
26
- Object.keys(source).forEach(key => {
27
- if (isObject(source[key])) {
28
- if (!(key in target)) {
29
- Object.assign(output, {
30
- [key]: source[key]
31
- });
32
- } else {
33
- output[key] = mergeDeep(target[key], source[key]);
34
- }
35
- } else {
36
- Object.assign(output, {
37
- [key]: source[key]
38
- });
39
- }
40
- });
41
- }
42
-
43
- return output;
44
- }
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.parseJwt = parseJwt;
5
-
6
- /**
7
- * Extract from a jwt token payload
8
- * @param token
9
- */
10
- function parseJwt(token) {
11
- let base64Url = token.split('.')[1];
12
- let base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
13
- let jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) {
14
- return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
15
- }).join(''));
16
- return JSON.parse(jsonPayload);
17
- }
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.camelCase = camelCase;
5
- exports.capitalize = capitalize;
6
- exports.isString = isString;
7
- exports.stripHtml = stripHtml;
8
-
9
- /**
10
- * Check if v is a string
11
- * @param v
12
- */
13
- function isString(v) {
14
- return typeof v === 'string' || v instanceof String;
15
- }
16
- /**
17
- * Capitalize a string
18
- * @param str
19
- */
20
-
21
-
22
- function capitalize(str) {
23
- let strVal = '';
24
- let strArr = str.split(' ');
25
-
26
- for (let chr = 0; chr < strArr.length; chr++) {
27
- strVal += strArr[chr].substring(0, 1).toUpperCase() + strArr[chr].substring(1, strArr[chr].length);
28
- }
29
-
30
- return strVal;
31
- }
32
- /**
33
- * CamelCase a string
34
- * @param str
35
- */
36
-
37
-
38
- function camelCase(str) {
39
- // Lower cases the string
40
- return str.toLowerCase() // Replaces any - or _ characters with a space
41
- .replace(/[-_]+/g, ' ') // Removes any non alphanumeric characters
42
- .replace(/[^\w\s]/g, '') // Uppercases the first character in each group immediately following a space
43
- // (delimited by spaces)
44
- .replace(/ (.)/g, $1 => {
45
- return $1.toUpperCase();
46
- }) // Removes spaces
47
- .replace(/ /g, '');
48
- }
49
- /**
50
- * Stripe html tags from a string
51
- * @param str
52
- */
53
-
54
-
55
- function stripHtml(str) {
56
- return str.replace(/<[^>]*>?/gm, '').trim();
57
- }
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.urlReplacer = exports.isValidUrls = exports.isValidUrl = exports.getDomain = void 0;
5
-
6
- /**
7
- * Utility Url Replacer
8
- * @param path
9
- */
10
- const urlReplacer = path => {
11
- const replacer = function replacer(tpl, data) {
12
- const re = /\$\(([^)]+)?\)/g;
13
- let match = re.exec(tpl);
14
-
15
- while (match) {
16
- tpl = tpl.replace(match[0], data[match[1]]);
17
- re.lastIndex = 0;
18
- match = re.exec(tpl);
19
- }
20
-
21
- return tpl;
22
- };
23
-
24
- return params => replacer(path, params);
25
- };
26
- /**
27
- * Get domain
28
- * @param url
29
- */
30
-
31
-
32
- exports.urlReplacer = urlReplacer;
33
-
34
- const getDomain = url => {
35
- // eslint-disable-next-line no-useless-escape,@typescript-eslint/prefer-regexp-exec
36
- const matches = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);
37
-
38
- if (matches && matches[1]) {
39
- return matches[1];
40
- }
41
-
42
- return '';
43
- };
44
- /**
45
- * Check a str is a valid url pattern
46
- * @param url
47
- */
48
-
49
-
50
- exports.getDomain = getDomain;
51
-
52
- const isValidUrl = url => {
53
- const regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/;
54
- return regexp.test(url);
55
- };
56
- /**
57
- * Check a str is a valid list of urls separated by delimiter
58
- * @param value
59
- * @param delimiter
60
- */
61
-
62
-
63
- exports.isValidUrl = isValidUrl;
64
-
65
- const isValidUrls = (value, delimiter) => {
66
- const urls = value.trim().split(delimiter);
67
- return urls.every(isValidUrl);
68
- };
69
-
70
- exports.isValidUrls = isValidUrls;
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.urlB64ToUint8Array = exports.loadVersionBrowser = void 0;
5
-
6
- /**
7
- * Take the application server's public key, which is Base64 URL-safe encoded,
8
- * and convert it to a UInt8Array, because this is the expected input of the subscribe()
9
- */
10
- const urlB64ToUint8Array = base64String => {
11
- const padding = '='.repeat((4 - base64String.length % 4) % 4);
12
- const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');
13
- const rawData = window.atob(base64);
14
- const outputArray = new Uint8Array(rawData.length);
15
-
16
- for (let i = 0; i < rawData.length; ++i) {
17
- outputArray[i] = rawData.charCodeAt(i);
18
- }
19
-
20
- return outputArray;
21
- };
22
- /**
23
- * Get browser version to track on backend
24
- * @return {{name: string, version: null}|{name: string, version: string}|{name: *, version: *}|{name: string, version}}
25
- */
26
-
27
-
28
- exports.urlB64ToUint8Array = urlB64ToUint8Array;
29
-
30
- const loadVersionBrowser = () => {
31
- if ('userAgentData' in navigator) {
32
- // navigator.userAgentData is not available in
33
- // Firefox and Safari
34
- const uaData = navigator['userAgentData']; // Outputs of navigator.userAgentData.brands[n].brand are e.g.
35
- // Chrome: 'Google Chrome'
36
- // Edge: 'Microsoft Edge'
37
- // Opera: 'Opera'
38
-
39
- let browsername;
40
- let browserversion;
41
- let chromeVersion = null;
42
-
43
- for (let i = 0; i < uaData['brands'].length; i++) {
44
- const brand = uaData['brands'][i].brand;
45
- browserversion = uaData['brands'][i].version;
46
-
47
- if (brand.match(/opera|chrome|edge|safari|firefox|msie|trident/i) !== null) {
48
- // If we have a chrome match, save the match, but try to find another match
49
- // E.g. Edge can also produce a false Chrome match.
50
- if (brand.match(/chrome/i) !== null) {
51
- chromeVersion = browserversion;
52
- } // If this is not a chrome match return immediately
53
- else {
54
- browsername = brand.substr(brand.indexOf(' ') + 1);
55
- return {
56
- name: browsername,
57
- version: browserversion
58
- };
59
- }
60
- }
61
- } // No non-Chrome match was found. If we have a chrome match, return it.
62
-
63
-
64
- if (chromeVersion !== null) {
65
- return {
66
- name: 'chrome',
67
- version: chromeVersion
68
- };
69
- }
70
- } // If no userAgentData is not present, or if no match via userAgentData was found,
71
- // try to extract the browser name and version from userAgent
72
-
73
-
74
- const userAgent = navigator.userAgent;
75
- let ua = userAgent;
76
- let tem;
77
- let M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
78
-
79
- if (/trident/i.test(M[1])) {
80
- tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
81
- return {
82
- name: 'IE',
83
- version: tem[1] || ''
84
- };
85
- }
86
-
87
- if (M[1] === 'Chrome') {
88
- tem = ua.match(/\bOPR\/(\d+)/);
89
-
90
- if (tem != null) {
91
- return {
92
- name: 'Opera',
93
- version: tem[1]
94
- };
95
- }
96
- }
97
-
98
- M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?']; // eslint-disable-next-line @typescript-eslint/prefer-regexp-exec
99
-
100
- if ((tem = ua.match(/version\/(\d+)/i)) != null) {
101
- M.splice(1, 1, tem[1]);
102
- }
103
-
104
- return {
105
- name: M[0],
106
- version: M[1]
107
- };
108
- };
109
-
110
- exports.loadVersionBrowser = loadVersionBrowser;
@@ -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;
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,MAAM;IACjB,MAAM,CAAC,IAAI,CAAC,KAAK,KAAA,EAAE,OAAO,KAAA;IAI1B,MAAM,CAAC,IAAI,CAAC,KAAK,KAAA,EAAE,OAAO,KAAA;IAI1B,MAAM,CAAC,KAAK,CAAC,KAAK,KAAA,EAAE,OAAO,KAAA;IAI3B,MAAM,CAAC,GAAG,CAAC,KAAK,KAAA,EAAE,OAAO,KAAA;IAIzB,MAAM,CAAC,KAAK,CAAC,KAAK,KAAA,EAAE,OAAO,KAAA;CAG5B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../../../../src/utils/object.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,KAAA,WAEzB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAgBhE"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Extract from a jwt token payload
3
- * @param token
4
- */
5
- export declare function parseJwt(token: any): any;
6
- //# sourceMappingURL=session.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../../../src/utils/session.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,KAAA,OAY7B"}