@bigbinary/neeto-molecules 0.0.1

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 (183) hide show
  1. package/README.md +60 -0
  2. package/dist/BrowserSupport.cjs.js +1727 -0
  3. package/dist/BrowserSupport.cjs.js.map +1 -0
  4. package/dist/BrowserSupport.js +1721 -0
  5. package/dist/BrowserSupport.js.map +1 -0
  6. package/dist/Columns.cjs.js +191 -0
  7. package/dist/Columns.cjs.js.map +1 -0
  8. package/dist/Columns.js +184 -0
  9. package/dist/Columns.js.map +1 -0
  10. package/dist/Container.cjs.js +1277 -0
  11. package/dist/Container.cjs.js.map +1 -0
  12. package/dist/Container.js +1271 -0
  13. package/dist/Container.js.map +1 -0
  14. package/dist/CopyToClipboardButton.cjs.js +78 -0
  15. package/dist/CopyToClipboardButton.cjs.js.map +1 -0
  16. package/dist/CopyToClipboardButton.js +72 -0
  17. package/dist/CopyToClipboardButton.js.map +1 -0
  18. package/dist/CustomDomain.cjs.js +680 -0
  19. package/dist/CustomDomain.cjs.js.map +1 -0
  20. package/dist/CustomDomain.js +654 -0
  21. package/dist/CustomDomain.js.map +1 -0
  22. package/dist/CustomDomainDashboard.cjs.js +2306 -0
  23. package/dist/CustomDomainDashboard.cjs.js.map +1 -0
  24. package/dist/CustomDomainDashboard.js +2279 -0
  25. package/dist/CustomDomainDashboard.js.map +1 -0
  26. package/dist/DateFormat.cjs.js +51 -0
  27. package/dist/DateFormat.cjs.js.map +1 -0
  28. package/dist/DateFormat.js +45 -0
  29. package/dist/DateFormat.js.map +1 -0
  30. package/dist/DateRangeFilter.cjs.js +236 -0
  31. package/dist/DateRangeFilter.cjs.js.map +1 -0
  32. package/dist/DateRangeFilter.js +229 -0
  33. package/dist/DateRangeFilter.js.map +1 -0
  34. package/dist/DynamicVariables.cjs.js +112 -0
  35. package/dist/DynamicVariables.cjs.js.map +1 -0
  36. package/dist/DynamicVariables.js +106 -0
  37. package/dist/DynamicVariables.js.map +1 -0
  38. package/dist/EmailPreview.cjs.js +102 -0
  39. package/dist/EmailPreview.cjs.js.map +1 -0
  40. package/dist/EmailPreview.js +96 -0
  41. package/dist/EmailPreview.js.map +1 -0
  42. package/dist/ErrorPage.cjs.js +208 -0
  43. package/dist/ErrorPage.cjs.js.map +1 -0
  44. package/dist/ErrorPage.js +184 -0
  45. package/dist/ErrorPage.js.map +1 -0
  46. package/dist/Header.cjs.js +219 -0
  47. package/dist/Header.cjs.js.map +1 -0
  48. package/dist/Header.js +213 -0
  49. package/dist/Header.js.map +1 -0
  50. package/dist/IconPicker.cjs.js +1307 -0
  51. package/dist/IconPicker.cjs.js.map +1 -0
  52. package/dist/IconPicker.js +1301 -0
  53. package/dist/IconPicker.js.map +1 -0
  54. package/dist/IntegrationCard.cjs.js +75 -0
  55. package/dist/IntegrationCard.cjs.js.map +1 -0
  56. package/dist/IntegrationCard.js +69 -0
  57. package/dist/IntegrationCard.js.map +1 -0
  58. package/dist/IntegrationDisconnectAlert.cjs.js +81 -0
  59. package/dist/IntegrationDisconnectAlert.cjs.js.map +1 -0
  60. package/dist/IntegrationDisconnectAlert.js +75 -0
  61. package/dist/IntegrationDisconnectAlert.js.map +1 -0
  62. package/dist/IntegrationWalkthroughModal.cjs.js +42 -0
  63. package/dist/IntegrationWalkthroughModal.cjs.js.map +1 -0
  64. package/dist/IntegrationWalkthroughModal.js +36 -0
  65. package/dist/IntegrationWalkthroughModal.js.map +1 -0
  66. package/dist/IpRestriction.cjs.js +3764 -0
  67. package/dist/IpRestriction.cjs.js.map +1 -0
  68. package/dist/IpRestriction.js +3738 -0
  69. package/dist/IpRestriction.js.map +1 -0
  70. package/dist/KeyboardShortcuts.cjs.js +2242 -0
  71. package/dist/KeyboardShortcuts.cjs.js.map +1 -0
  72. package/dist/KeyboardShortcuts.js +2235 -0
  73. package/dist/KeyboardShortcuts.js.map +1 -0
  74. package/dist/LoginPage.cjs.js +618 -0
  75. package/dist/LoginPage.cjs.js.map +1 -0
  76. package/dist/LoginPage.js +593 -0
  77. package/dist/LoginPage.js.map +1 -0
  78. package/dist/MenuBar.cjs.js +31044 -0
  79. package/dist/MenuBar.cjs.js.map +1 -0
  80. package/dist/MenuBar.js +31038 -0
  81. package/dist/MenuBar.js.map +1 -0
  82. package/dist/NeetoWidget.cjs.js +3369 -0
  83. package/dist/NeetoWidget.cjs.js.map +1 -0
  84. package/dist/NeetoWidget.js +3343 -0
  85. package/dist/NeetoWidget.js.map +1 -0
  86. package/dist/PageLoader.cjs.js +158 -0
  87. package/dist/PageLoader.cjs.js.map +1 -0
  88. package/dist/PageLoader.js +134 -0
  89. package/dist/PageLoader.js.map +1 -0
  90. package/dist/PhoneNumber.cjs.js +7021 -0
  91. package/dist/PhoneNumber.cjs.js.map +1 -0
  92. package/dist/PhoneNumber.js +6989 -0
  93. package/dist/PhoneNumber.js.map +1 -0
  94. package/dist/PublishBlock.cjs.js +189 -0
  95. package/dist/PublishBlock.cjs.js.map +1 -0
  96. package/dist/PublishBlock.js +183 -0
  97. package/dist/PublishBlock.js.map +1 -0
  98. package/dist/Rename.cjs.js +306 -0
  99. package/dist/Rename.cjs.js.map +1 -0
  100. package/dist/Rename.js +300 -0
  101. package/dist/Rename.js.map +1 -0
  102. package/dist/ResponsiveDevicePicker.cjs.js +260 -0
  103. package/dist/ResponsiveDevicePicker.cjs.js.map +1 -0
  104. package/dist/ResponsiveDevicePicker.js +254 -0
  105. package/dist/ResponsiveDevicePicker.js.map +1 -0
  106. package/dist/Schedule.cjs.js +952 -0
  107. package/dist/Schedule.cjs.js.map +1 -0
  108. package/dist/Schedule.js +921 -0
  109. package/dist/Schedule.js.map +1 -0
  110. package/dist/Scrollable.cjs.js +184 -0
  111. package/dist/Scrollable.cjs.js.map +1 -0
  112. package/dist/Scrollable.js +178 -0
  113. package/dist/Scrollable.js.map +1 -0
  114. package/dist/ShareViaEmail.cjs.js +2992 -0
  115. package/dist/ShareViaEmail.cjs.js.map +1 -0
  116. package/dist/ShareViaEmail.js +2966 -0
  117. package/dist/ShareViaEmail.js.map +1 -0
  118. package/dist/ShareViaLink.cjs.js +1385 -0
  119. package/dist/ShareViaLink.cjs.js.map +1 -0
  120. package/dist/ShareViaLink.js +1360 -0
  121. package/dist/ShareViaLink.js.map +1 -0
  122. package/dist/Sidebar.cjs.js +32222 -0
  123. package/dist/Sidebar.cjs.js.map +1 -0
  124. package/dist/Sidebar.js +32196 -0
  125. package/dist/Sidebar.js.map +1 -0
  126. package/dist/SubHeader.cjs.js +272 -0
  127. package/dist/SubHeader.cjs.js.map +1 -0
  128. package/dist/SubHeader.js +265 -0
  129. package/dist/SubHeader.js.map +1 -0
  130. package/dist/TableWrapper.cjs.js +87 -0
  131. package/dist/TableWrapper.cjs.js.map +1 -0
  132. package/dist/TableWrapper.js +81 -0
  133. package/dist/TableWrapper.js.map +1 -0
  134. package/dist/ThemeSidebar.cjs.js +13618 -0
  135. package/dist/ThemeSidebar.cjs.js.map +1 -0
  136. package/dist/ThemeSidebar.js +13593 -0
  137. package/dist/ThemeSidebar.js.map +1 -0
  138. package/dist/TimeFormat.cjs.js +53 -0
  139. package/dist/TimeFormat.cjs.js.map +1 -0
  140. package/dist/TimeFormat.js +47 -0
  141. package/dist/TimeFormat.js.map +1 -0
  142. package/dist/TimezoneMismatchModal.cjs.js +176 -0
  143. package/dist/TimezoneMismatchModal.cjs.js.map +1 -0
  144. package/dist/TimezoneMismatchModal.js +168 -0
  145. package/dist/TimezoneMismatchModal.js.map +1 -0
  146. package/package.json +185 -0
  147. package/src/translations/en.json +449 -0
  148. package/types/BrowserSupport.d.ts +86 -0
  149. package/types/Columns.d.ts +53 -0
  150. package/types/Container.d.ts +35 -0
  151. package/types/CopyToClipboardButton.d.ts +21 -0
  152. package/types/CustomDomain.d.ts +19 -0
  153. package/types/CustomDomainDashboard.d.ts +33 -0
  154. package/types/DateFormat.d.ts +18 -0
  155. package/types/DateRangeFilter.d.ts +52 -0
  156. package/types/DynamicVariables.d.ts +45 -0
  157. package/types/EmailPreview.d.ts +41 -0
  158. package/types/ErrorPage.d.ts +15 -0
  159. package/types/Header.d.ts +30 -0
  160. package/types/IconPicker.d.ts +43 -0
  161. package/types/IntegrationCard.d.ts +45 -0
  162. package/types/IntegrationDisconnectAlert.d.ts +37 -0
  163. package/types/IntegrationWalkthroughModal.d.ts +31 -0
  164. package/types/IpRestriction.d.ts +23 -0
  165. package/types/KeyboardShortcuts.d.ts +147 -0
  166. package/types/LoginPage.d.ts +43 -0
  167. package/types/MenuBar.d.ts +125 -0
  168. package/types/NeetoWidget.d.ts +41 -0
  169. package/types/PageLoader.d.ts +38 -0
  170. package/types/PhoneNumber.d.ts +106 -0
  171. package/types/PublishBlock.d.ts +84 -0
  172. package/types/Rename.d.ts +60 -0
  173. package/types/ResponsiveDevicePicker.d.ts +30 -0
  174. package/types/Schedule.d.ts +132 -0
  175. package/types/Scrollable.d.ts +28 -0
  176. package/types/ShareViaEmail.d.ts +99 -0
  177. package/types/ShareViaLink.d.ts +117 -0
  178. package/types/Sidebar.d.ts +63 -0
  179. package/types/SubHeader.d.ts +97 -0
  180. package/types/TableWrapper.d.ts +38 -0
  181. package/types/TimeFormat.d.ts +17 -0
  182. package/types/TimezoneMismatchModal.d.ts +39 -0
  183. package/types/themeSidebar.d.ts +80 -0
@@ -0,0 +1,3764 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var neetoui = require('@bigbinary/neetoui');
5
+ var reactI18next = require('react-i18next');
6
+ var neetoIcons = require('@bigbinary/neeto-icons');
7
+ var formik = require('@bigbinary/neetoui/formik');
8
+ var reactQuery = require('react-query');
9
+ var axios = require('axios');
10
+ var i18next = require('i18next');
11
+ var ramda = require('ramda');
12
+ var yup = require('yup');
13
+ var pure = require('@bigbinary/neeto-commons-frontend/pure');
14
+
15
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
+
17
+ function _interopNamespace(e) {
18
+ if (e && e.__esModule) return e;
19
+ var n = Object.create(null);
20
+ if (e) {
21
+ Object.keys(e).forEach(function (k) {
22
+ if (k !== 'default') {
23
+ var d = Object.getOwnPropertyDescriptor(e, k);
24
+ Object.defineProperty(n, k, d.get ? d : {
25
+ enumerable: true,
26
+ get: function () { return e[k]; }
27
+ });
28
+ }
29
+ });
30
+ }
31
+ n["default"] = e;
32
+ return Object.freeze(n);
33
+ }
34
+
35
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
36
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
37
+ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
38
+ var yup__namespace = /*#__PURE__*/_interopNamespace(yup);
39
+
40
+ function _extends$1() {
41
+ _extends$1 = Object.assign ? Object.assign.bind() : function (target) {
42
+ for (var i = 1; i < arguments.length; i++) {
43
+ var source = arguments[i];
44
+ for (var key in source) {
45
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
46
+ target[key] = source[key];
47
+ }
48
+ }
49
+ }
50
+ return target;
51
+ };
52
+ return _extends$1.apply(this, arguments);
53
+ }
54
+
55
+ function _objectWithoutPropertiesLoose(source, excluded) {
56
+ if (source == null) return {};
57
+ var target = {};
58
+ var sourceKeys = Object.keys(source);
59
+ var key, i;
60
+ for (i = 0; i < sourceKeys.length; i++) {
61
+ key = sourceKeys[i];
62
+ if (excluded.indexOf(key) >= 0) continue;
63
+ target[key] = source[key];
64
+ }
65
+ return target;
66
+ }
67
+
68
+ function _objectWithoutProperties(source, excluded) {
69
+ if (source == null) return {};
70
+ var target = _objectWithoutPropertiesLoose(source, excluded);
71
+ var key, i;
72
+ if (Object.getOwnPropertySymbols) {
73
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
74
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
75
+ key = sourceSymbolKeys[i];
76
+ if (excluded.indexOf(key) >= 0) continue;
77
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
78
+ target[key] = source[key];
79
+ }
80
+ }
81
+ return target;
82
+ }
83
+
84
+ var _path, _path2, _g, _defs;
85
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
86
+ var SvgNeeto = function SvgNeeto(props) {
87
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends({
88
+ width: 50,
89
+ height: 50,
90
+ viewBox: "0 0 415 415",
91
+ fill: "none",
92
+ xmlns: "http://www.w3.org/2000/svg"
93
+ }, props), _path || (_path = /*#__PURE__*/React__namespace.createElement("path", {
94
+ d: "M414.989 207.495C414.989 92.899 322.091 0 207.495 0H0v414.989h414.989V207.495Z",
95
+ fill: "#0043AC"
96
+ })), /*#__PURE__*/React__namespace.createElement("mask", {
97
+ id: "neeto_svg__a",
98
+ style: {
99
+ maskType: "alpha"
100
+ },
101
+ maskUnits: "userSpaceOnUse",
102
+ x: 0,
103
+ y: 0,
104
+ width: 415,
105
+ height: 415
106
+ }, _path2 || (_path2 = /*#__PURE__*/React__namespace.createElement("path", {
107
+ d: "M414.989 207.495C414.989 92.899 322.091 0 207.495 0H0v414.989h414.989V207.495Z",
108
+ fill: "#0043AC"
109
+ }))), _g || (_g = /*#__PURE__*/React__namespace.createElement("g", {
110
+ mask: "url(#neeto_svg__a)"
111
+ }, /*#__PURE__*/React__namespace.createElement("path", {
112
+ d: "M233.747 348.74c88.579 101.145 172.015 116.411 202.661 111.401v32.491H-8.032V230.487c43.685-2.726 153.2 17.108 241.779 118.253Z",
113
+ fill: "url(#neeto_svg__b)"
114
+ }))), _defs || (_defs = /*#__PURE__*/React__namespace.createElement("defs", null, /*#__PURE__*/React__namespace.createElement("radialGradient", {
115
+ id: "neeto_svg__b",
116
+ cx: 0,
117
+ cy: 0,
118
+ r: 1,
119
+ gradientUnits: "userSpaceOnUse",
120
+ gradientTransform: "rotate(47.118 -220.556 214.818) scale(427.964 725.049)"
121
+ }, /*#__PURE__*/React__namespace.createElement("stop", {
122
+ stopColor: "#0043AC"
123
+ }), /*#__PURE__*/React__namespace.createElement("stop", {
124
+ offset: 1,
125
+ stopColor: "#3DB1CA",
126
+ stopOpacity: 0.8
127
+ })))));
128
+ };
129
+
130
+ var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
131
+
132
+ var css = ".neeto-molecules-pageloader__wrapper{height:100%;position:relative;width:100%}.neeto-molecules-pageloader__wrapper .neeto-molecules-pageloader{height:100%;left:0;position:absolute;top:0;width:100%}.neeto-molecules-pageloader__wrapper .neeto-molecules-pageloader__content{height:66px;margin-bottom:16px;overflow:hidden;padding:8px;position:relative;width:66px}.neeto-molecules-pageloader__wrapper .neeto-molecules-pageloader__text{color:rgb(var(--neeto-ui-gray-800));font-size:1.25rem;line-height:1.75rem;margin-bottom:4rem;text-align:center}.neeto-molecules-pageloader__spinner{display:flex;gap:2px;height:25px;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%)}.neeto-molecules-pageloader__spinner>div{animation:neeto-ui-stretch-delay 1.2s ease-in-out infinite;background-color:#fff;border-radius:2px;display:inline-flex;height:100%;width:2px}.neeto-molecules-pageloader__spinner .neeto-molecules-pageloader__rect2{animation-delay:-1.1s}.neeto-molecules-pageloader__spinner .neeto-molecules-pageloader__rect3{animation-delay:-1s}.neeto-molecules-pageloader__spinner .neeto-molecules-pageloader__rect4{animation-delay:-.9s}.neeto-molecules-pageloader__spinner .neeto-molecules-pageloader__rect5{animation-delay:-.8s}@keyframes neeto-ui-stretch-delay{0%,40%,to{transform:scaleY(.4);-webkit-transform:scaleY(.4)}20%{transform:scaleY(1);-webkit-transform:scaleY(1)}}";
133
+ n(css,{});
134
+
135
+ var _excluded = ["text"];
136
+ var PageLoader = function PageLoader(_ref) {
137
+ var _ref$text = _ref.text,
138
+ text = _ref$text === void 0 ? "" : _ref$text,
139
+ otherProps = _objectWithoutProperties(_ref, _excluded);
140
+ return /*#__PURE__*/React__default["default"].createElement("div", _extends$1({
141
+ className: "neeto-molecules-pageloader__wrapper"
142
+ }, otherProps), /*#__PURE__*/React__default["default"].createElement("div", {
143
+ className: "neeto-molecules-pageloader neeto-ui-flex neeto-ui-flex-col neeto-ui-items-center neeto-ui-justify-center"
144
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
145
+ className: "neeto-molecules-pageloader__content neeto-ui-flex neeto-ui-flex-shrink-0 neeto-ui-items-center neeto-ui-justify-center"
146
+ }, /*#__PURE__*/React__default["default"].createElement(SvgNeeto, {
147
+ className: "neeto-molecules-pageloader__logo",
148
+ size: 50
149
+ }), /*#__PURE__*/React__default["default"].createElement("div", {
150
+ className: "neeto-molecules-pageloader__spinner"
151
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
152
+ className: "neeto-molecules-pageloader__rect1"
153
+ }), /*#__PURE__*/React__default["default"].createElement("div", {
154
+ className: "neeto-molecules-pageloader__rect2"
155
+ }), /*#__PURE__*/React__default["default"].createElement("div", {
156
+ className: "neeto-molecules-pageloader__rect3"
157
+ }), /*#__PURE__*/React__default["default"].createElement("div", {
158
+ className: "neeto-molecules-pageloader__rect4"
159
+ }), /*#__PURE__*/React__default["default"].createElement("div", {
160
+ className: "neeto-molecules-pageloader__rect5"
161
+ }))), text && /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
162
+ style: "h5",
163
+ weight: "semibold"
164
+ }, text)));
165
+ };
166
+ var PageLoader$1 = /*#__PURE__*/React__default["default"].memo(PageLoader);
167
+
168
+ function _arrayWithHoles(arr) {
169
+ if (Array.isArray(arr)) return arr;
170
+ }
171
+
172
+ function _iterableToArrayLimit(arr, i) {
173
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
174
+ if (null != _i) {
175
+ var _s,
176
+ _e,
177
+ _x,
178
+ _r,
179
+ _arr = [],
180
+ _n = !0,
181
+ _d = !1;
182
+ try {
183
+ if (_x = (_i = _i.call(arr)).next, 0 === i) {
184
+ if (Object(_i) !== _i) return;
185
+ _n = !1;
186
+ } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
187
+ } catch (err) {
188
+ _d = !0, _e = err;
189
+ } finally {
190
+ try {
191
+ if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
192
+ } finally {
193
+ if (_d) throw _e;
194
+ }
195
+ }
196
+ return _arr;
197
+ }
198
+ }
199
+
200
+ function _arrayLikeToArray(arr, len) {
201
+ if (len == null || len > arr.length) len = arr.length;
202
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
203
+ return arr2;
204
+ }
205
+
206
+ function _unsupportedIterableToArray(o, minLen) {
207
+ if (!o) return;
208
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
209
+ var n = Object.prototype.toString.call(o).slice(8, -1);
210
+ if (n === "Object" && o.constructor) n = o.constructor.name;
211
+ if (n === "Map" || n === "Set") return Array.from(o);
212
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
213
+ }
214
+
215
+ function _nonIterableRest() {
216
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
217
+ }
218
+
219
+ function _slicedToArray(arr, i) {
220
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
221
+ }
222
+
223
+ var IP_RESTRICTIONS_ENGINE_BASE_URL = "ip_restrictions/api/v1";
224
+ var INITIAL_VALUES = {
225
+ ipStart: "",
226
+ ipEnd: ""
227
+ };
228
+ var QUERY_KEYS = {
229
+ IP_RESTRICTION: "IP_RESTRICTION",
230
+ ALLOWED_IP_RANGES: "ALLOWED_IP_RANGES",
231
+ CURRENT_IP: "CURRENT_IP"
232
+ };
233
+ var TRUNCATE_LENGTH = 18;
234
+
235
+ var allowedIpRangesUrl = "".concat(IP_RESTRICTIONS_ENGINE_BASE_URL, "/allowed_ips");
236
+ var fetch = function fetch() {
237
+ return axios__default["default"].get(allowedIpRangesUrl);
238
+ };
239
+ var create = function create(payload) {
240
+ return axios__default["default"].post(allowedIpRangesUrl, {
241
+ allowedIpRange: payload
242
+ });
243
+ };
244
+ var destroy = function destroy(id) {
245
+ return axios__default["default"]["delete"]("".concat(allowedIpRangesUrl, "/").concat(id));
246
+ };
247
+ var update$1 = function update(_ref) {
248
+ var id = _ref.id,
249
+ payload = _ref.payload;
250
+ return axios__default["default"].patch("".concat(allowedIpRangesUrl, "/").concat(id), {
251
+ allowedIpRange: payload
252
+ });
253
+ };
254
+ var allowedIpRangesApi = {
255
+ fetch: fetch,
256
+ create: create,
257
+ destroy: destroy,
258
+ update: update$1
259
+ };
260
+
261
+ var ALLOWED_IP_RANGES = QUERY_KEYS.ALLOWED_IP_RANGES;
262
+ var useFetchAllowedIpRanges = function useFetchAllowedIpRanges() {
263
+ return reactQuery.useQuery([ALLOWED_IP_RANGES], function () {
264
+ return allowedIpRangesApi.fetch();
265
+ });
266
+ };
267
+ var useCreateAllowedIpRanges = function useCreateAllowedIpRanges() {
268
+ var queryClient = reactQuery.useQueryClient();
269
+ return reactQuery.useMutation(allowedIpRangesApi.create, {
270
+ onSuccess: function onSuccess() {
271
+ return queryClient.invalidateQueries(ALLOWED_IP_RANGES);
272
+ }
273
+ });
274
+ };
275
+ var useDestroyAllowedIpRanges = function useDestroyAllowedIpRanges() {
276
+ var queryClient = reactQuery.useQueryClient();
277
+ return reactQuery.useMutation(allowedIpRangesApi.destroy, {
278
+ onSuccess: function onSuccess() {
279
+ queryClient.invalidateQueries(ALLOWED_IP_RANGES);
280
+ }
281
+ });
282
+ };
283
+ var useUpdateAllowedIpRanges = function useUpdateAllowedIpRanges() {
284
+ var queryClient = reactQuery.useQueryClient();
285
+ return reactQuery.useMutation(allowedIpRangesApi.update, {
286
+ onSuccess: function onSuccess() {
287
+ queryClient.invalidateQueries(ALLOWED_IP_RANGES);
288
+ }
289
+ });
290
+ };
291
+
292
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
293
+
294
+ var ipNum = {};
295
+
296
+ var BinaryUtils = {};
297
+
298
+ (function (exports) {
299
+ Object.defineProperty(exports, "__esModule", { value: true });
300
+ exports.matchingBitCount = exports.intLog2 = exports.cidrPrefixToMaskBinaryString = exports.leftPadWithZeroBit = exports.dottedDecimalNotationToBinaryString = exports.parseBinaryStringToBigInt = exports.decimalNumberToOctetString = exports.numberToBinaryString = void 0;
301
+ /**
302
+ * Converts a decimal number to binary string
303
+ *
304
+ * @param num number to parse
305
+ * @returns {string} the binary string representation of number
306
+ */
307
+ exports.numberToBinaryString = (num) => {
308
+ return num.toString(2);
309
+ };
310
+ /**
311
+ * Converts a decimal number to binary octet (8 bit) string. If needed the octet will be padded with zeros
312
+ * to make it up to 8 bits
313
+ *
314
+ * @param {number} num to convert to octet string
315
+ * @returns {string} the octet string representation of given number
316
+ */
317
+ exports.decimalNumberToOctetString = (num) => {
318
+ let binaryString = exports.numberToBinaryString(num);
319
+ let length = binaryString.length;
320
+ if (length > 8) {
321
+ throw new Error("Given decimal in binary contains digits greater than an octet");
322
+ }
323
+ return exports.leftPadWithZeroBit(binaryString, 8);
324
+ };
325
+ /**
326
+ * Parses number in binary to number in BigInt
327
+ *
328
+ * @param num binary number in string to parse
329
+ * @returns {number} binary number in BigInt
330
+ */
331
+ exports.parseBinaryStringToBigInt = (num) => {
332
+ return BigInt(`0b${num}`);
333
+ };
334
+ /**
335
+ * Given an IPv4 number in dot-decimal notated string, e.g 192.168.0.1 converts it to
336
+ * binary string, e.g. '11000000101010000000000000000001'
337
+ *
338
+ * @param dottedDecimal IPv4 string in dot-decimal notation
339
+ * @returns {string} the binary value of the given ipv4 number in string
340
+ */
341
+ exports.dottedDecimalNotationToBinaryString = (dottedDecimal) => {
342
+ let stringOctets = dottedDecimal.split(".");
343
+ return stringOctets.reduce((binaryAsString, octet) => {
344
+ return binaryAsString.concat(exports.decimalNumberToOctetString(parseInt(octet)));
345
+ }, '');
346
+ };
347
+ /**
348
+ * Given a binary string, adds a number of zero to the left until string is as long as the given string length
349
+ * @param {string} binaryString the string to pad
350
+ * @param {number} finalStringLength the final length of string after padding
351
+ * @returns {string}
352
+ */
353
+ exports.leftPadWithZeroBit = (binaryString, finalStringLength) => {
354
+ if (binaryString.length > finalStringLength) {
355
+ throw new Error(`Given string is already longer than given final length after padding: ${finalStringLength}`);
356
+ }
357
+ return "0".repeat(finalStringLength - binaryString.length).concat(binaryString);
358
+ };
359
+ /**
360
+ * Given the prefix portion of a cidr notation and the type of IP number, returns the mask in binary string
361
+ *
362
+ * @param {number} cidrPrefix the prefix part of a cidr notation
363
+ * @param {IPNumType.IPv4 | IPNumType.IPv6} ipType the type of the ip number in the range the cidr represents
364
+ */
365
+ exports.cidrPrefixToMaskBinaryString = (cidrPrefix, ipType) => {
366
+ let cidrUpperValue;
367
+ if (ipType == "IPv4" /* IPv4 */) {
368
+ cidrUpperValue = 32;
369
+ }
370
+ else {
371
+ cidrUpperValue = 128;
372
+ }
373
+ if (cidrPrefix > cidrUpperValue)
374
+ throw Error(`Value is greater than ${cidrUpperValue}`);
375
+ let onBits = '1'.repeat(cidrPrefix);
376
+ let offBits = '0'.repeat(cidrUpperValue - cidrPrefix);
377
+ return `${onBits}${offBits}`;
378
+ };
379
+ /**
380
+ * Calculates the log, to base 2 of given number.
381
+ *
382
+ * @throws Error if number cannot be converted to log base 2
383
+ * @param givenNumber the number to calculate log base 2
384
+ * @return the log base 2 of given number
385
+ */
386
+ exports.intLog2 = (givenNumber) => {
387
+ let result = 0;
388
+ while (givenNumber % 2n === 0n) {
389
+ if (givenNumber === 2n) {
390
+ result++;
391
+ break;
392
+ }
393
+ givenNumber = givenNumber >> 1n;
394
+ if (givenNumber % 2n !== 0n) {
395
+ result = 0;
396
+ break;
397
+ }
398
+ result++;
399
+ }
400
+ if (result == 0) {
401
+ throw new Error(`The value of log2 for ${givenNumber.toString()} is not an integer`);
402
+ }
403
+ return result;
404
+ };
405
+ /**
406
+ * Starting from the most significant bit (from left) returns the number of first bits from both string that are equal
407
+ * @param firstBinaryString first binary string
408
+ * @param secondBinaryString second binary string
409
+ */
410
+ exports.matchingBitCount = (firstBinaryString, secondBinaryString) => {
411
+ let longerString;
412
+ let otherString;
413
+ if (firstBinaryString.length >= secondBinaryString.length) {
414
+ longerString = firstBinaryString;
415
+ otherString = secondBinaryString;
416
+ }
417
+ else {
418
+ longerString = secondBinaryString;
419
+ otherString = firstBinaryString;
420
+ }
421
+ let count = 0;
422
+ for (; count < longerString.length; count++) {
423
+ if (longerString.charAt(count) === otherString.charAt(count)) {
424
+ continue;
425
+ }
426
+ break;
427
+ }
428
+ return count;
429
+ };
430
+
431
+ } (BinaryUtils));
432
+
433
+ var Hexadecatet$1 = {};
434
+
435
+ var Validator = {};
436
+
437
+ var IPv6Utils = {};
438
+
439
+ var hasRequiredIPv6Utils;
440
+
441
+ function requireIPv6Utils () {
442
+ if (hasRequiredIPv6Utils) return IPv6Utils;
443
+ hasRequiredIPv6Utils = 1;
444
+ Object.defineProperty(IPv6Utils, "__esModule", { value: true });
445
+ IPv6Utils.collapseIPv6Number = IPv6Utils.expandIPv6Number = void 0;
446
+ const BinaryUtils_1 = BinaryUtils;
447
+ const Validator_1 = requireValidator();
448
+ let extractPrefix = (ipv6String) => {
449
+ return ipv6String.includes("/") ? `/${ipv6String.split("/")[1]}` : "";
450
+ };
451
+ /**
452
+ * Expands an IPv6 number in abbreviated format into its full form
453
+ *
454
+ * {@see https://en.wikipedia.org/wiki/IPv6_address#Representation} for more on the representation of IPv6 addresses
455
+ *
456
+ * @param {string} ipv6String the abbreviated IPv6 address to expand
457
+ * @returns {string} the expanded IPv6 address
458
+ */
459
+ IPv6Utils.expandIPv6Number = (ipv6String) => {
460
+ let expandWithZero = (hexadecimalArray) => {
461
+ let paddedArray = hexadecimalArray.map((hexadecimal) => {
462
+ return BinaryUtils_1.leftPadWithZeroBit(hexadecimal, 4);
463
+ });
464
+ return paddedArray.join(":");
465
+ };
466
+ let expandDoubleColon = (gapCount) => {
467
+ let pads = [];
468
+ for (let count = 0; count < gapCount; count++) {
469
+ pads.push("0000");
470
+ }
471
+ return pads.join(":");
472
+ };
473
+ if (/(:){3,}/.test(ipv6String))
474
+ throw "given IPv6 contains consecutive : more than two";
475
+ const prefix = extractPrefix(ipv6String);
476
+ if (ipv6String.includes("/")) {
477
+ ipv6String = ipv6String.split("/")[0];
478
+ }
479
+ let isValid = Validator_1.Validator.IPV6_PATTERN.test(ipv6String);
480
+ if (!isValid) {
481
+ throw Error(Validator_1.Validator.invalidIPv6PatternMessage);
482
+ }
483
+ if (ipv6String.includes("::")) {
484
+ let split = ipv6String.split("::");
485
+ let leftPortion = split[0];
486
+ let rightPortion = split[1];
487
+ let leftPortionSplit = leftPortion.split(":").filter(hexadecimal => { return hexadecimal !== ""; });
488
+ let rightPortionSplit = rightPortion.split(":").filter(hexadecimal => { return hexadecimal !== ""; });
489
+ let doublePortion = expandDoubleColon(8 - (leftPortionSplit.length + rightPortionSplit.length));
490
+ let leftString = expandWithZero(leftPortionSplit);
491
+ if (leftString !== "") {
492
+ leftString += ":";
493
+ }
494
+ let rightString = expandWithZero(rightPortionSplit);
495
+ if (rightString !== "") {
496
+ rightString = ":" + rightString;
497
+ }
498
+ return `${leftString}${doublePortion}${rightString}${prefix}`;
499
+ }
500
+ else {
501
+ return `${expandWithZero(ipv6String.split(":"))}${prefix}`;
502
+ }
503
+ };
504
+ /**
505
+ * Collapses an IPv6 number in full format into its abbreviated form
506
+ *
507
+ * {@see https://en.wikipedia.org/wiki/IPv6_address#Representation} for more on the representation of IPv6 addresses
508
+ *
509
+ * @param {string} ipv6String the full form IPv6 number to collapse
510
+ * @returns {string} the collapsed IPv6 number
511
+ */
512
+ IPv6Utils.collapseIPv6Number = (ipv6String) => {
513
+ const prefix = extractPrefix(ipv6String);
514
+ if (ipv6String.includes("/")) {
515
+ ipv6String = ipv6String.split("/")[0];
516
+ }
517
+ let isValid = Validator_1.Validator.IPV6_PATTERN.test(ipv6String);
518
+ if (!isValid) {
519
+ throw Error(Validator_1.Validator.invalidIPv6PatternMessage);
520
+ }
521
+ let hexadecimals = ipv6String.split(":");
522
+ let hexadecimalsWithoutLeadingZeros = hexadecimals.map((hexidecimal) => {
523
+ let withoutLeadingZero = hexidecimal.replace(/^0+/, '');
524
+ if (withoutLeadingZero !== '') {
525
+ return withoutLeadingZero;
526
+ }
527
+ else {
528
+ return "0";
529
+ }
530
+ });
531
+ let contracted = hexadecimalsWithoutLeadingZeros.join(":").replace(/((^0)?(:0){2,}|(^0)(:0){1,})/, ':');
532
+ if (contracted.slice(-1) === ":") {
533
+ return `${contracted}:${prefix}`;
534
+ }
535
+ contracted = contracted.replace(":0:", "::");
536
+ return `${contracted}${prefix}`;
537
+ };
538
+
539
+ return IPv6Utils;
540
+ }
541
+
542
+ var HexadecimalUtils = {};
543
+
544
+ var hasRequiredHexadecimalUtils;
545
+
546
+ function requireHexadecimalUtils () {
547
+ if (hasRequiredHexadecimalUtils) return HexadecimalUtils;
548
+ hasRequiredHexadecimalUtils = 1;
549
+ (function (exports) {
550
+ Object.defineProperty(exports, "__esModule", { value: true });
551
+ exports.hexadectetNotationToBinaryString = exports.binaryStringToHexadecimalString = exports.colonHexadecimalNotationToBinaryString = exports.hexadecimalStringToHexadecatetString = exports.hexadecimalStringToBinaryString = exports.bigIntToHexadecimalString = void 0;
552
+ const IPv6Utils_1 = requireIPv6Utils();
553
+ const BinaryUtils_1 = BinaryUtils;
554
+ /**
555
+ * Converts a given bigint number to a hexadecimal string
556
+ * @param num the bigint number
557
+ * @returns {string} the hexadeciaml string
558
+ */
559
+ exports.bigIntToHexadecimalString = (num) => {
560
+ return num.toString(16);
561
+ };
562
+ /**
563
+ * Converts a number in hexadecimal (base 16) to binary string
564
+ * @param {string} hexadecimalString the number in base 16
565
+ * @returns {string} the number converted to base 2
566
+ */
567
+ exports.hexadecimalStringToBinaryString = (hexadecimalString) => {
568
+ let inDecimal = BigInt(`0x${hexadecimalString}`);
569
+ return inDecimal.toString(2);
570
+ };
571
+ /**
572
+ * Converts a number in hexadecimal (base 16) to binary hexadecatet string.
573
+ * This means the bits in the output cannot be more than 16
574
+ *
575
+ * @param hexadecimalString {string} the number converted to binary hexadecatet string
576
+ */
577
+ exports.hexadecimalStringToHexadecatetString = (hexadecimalString) => {
578
+ let binaryString = exports.hexadecimalStringToBinaryString(hexadecimalString);
579
+ let length = binaryString.length;
580
+ if (length > 16) {
581
+ throw new Error("Given decimal in binary contains digits greater than an Hexadecatet");
582
+ }
583
+ return BinaryUtils_1.leftPadWithZeroBit(binaryString, 16);
584
+ };
585
+ /**
586
+ * Given an IPv6 number in hexadecimal notated string, e.g 2001:0db8:0000:0000:0000:0000:0000:0000 converts it to
587
+ * binary string
588
+ *
589
+ * @param hexadecimalString IPv6 string
590
+ * @returns {string} the binary value of the given ipv6 number in string
591
+ */
592
+ exports.colonHexadecimalNotationToBinaryString = (hexadecimalString) => {
593
+ let expandedIPv6 = IPv6Utils_1.expandIPv6Number(hexadecimalString);
594
+ let stringHexadecimal = expandedIPv6.split(":");
595
+ return stringHexadecimal.reduce((binaryAsString, hexidecimal) => {
596
+ return binaryAsString.concat(exports.hexadecimalStringToHexadecatetString(hexidecimal));
597
+ }, '');
598
+ };
599
+ /**
600
+ * Converts number in binary string to hexadecimal string
601
+ * @param {string} num in binary string
602
+ * @returns {string} num in hexadecimal string
603
+ */
604
+ exports.binaryStringToHexadecimalString = (num) => {
605
+ // first convert to binary string to decimal (big Integer)
606
+ let inDecimal = BigInt(`0b${num}`);
607
+ return inDecimal.toString(16);
608
+ };
609
+ /**
610
+ * Converts a given IPv6 number expressed in the hexadecimal string notation into a 16 bit binary number in string
611
+ * @param {string} hexadectetString the IPv6 number
612
+ * @returns {string} the IPv6 number converted to binary string
613
+ */
614
+ exports.hexadectetNotationToBinaryString = (hexadectetString) => {
615
+ let expand = IPv6Utils_1.expandIPv6Number(hexadectetString);
616
+ let hexadecimals = expand.split(":");
617
+ return hexadecimals.reduce((hexadecimalAsString, hexavalue) => {
618
+ return hexadecimalAsString.concat(BinaryUtils_1.leftPadWithZeroBit(exports.hexadecimalStringToBinaryString(hexavalue), 16));
619
+ }, '');
620
+ };
621
+
622
+ } (HexadecimalUtils));
623
+ return HexadecimalUtils;
624
+ }
625
+
626
+ var hasRequiredValidator;
627
+
628
+ function requireValidator () {
629
+ if (hasRequiredValidator) return Validator;
630
+ hasRequiredValidator = 1;
631
+ Object.defineProperty(Validator, "__esModule", { value: true });
632
+ Validator.Validator = void 0;
633
+ const BinaryUtils_1 = BinaryUtils;
634
+ const BinaryUtils_2 = BinaryUtils;
635
+ const IPv6Utils_1 = requireIPv6Utils();
636
+ const HexadecimalUtils_1 = requireHexadecimalUtils();
637
+ const HexadecimalUtils_2 = requireHexadecimalUtils();
638
+ class Validator$1 {
639
+ /**
640
+ * Checks if given ipNumber is in between the given lower and upper bound
641
+ *
642
+ * @param ipNumber ipNumber to check
643
+ * @param lowerBound lower bound
644
+ * @param upperBound upper bound
645
+ * @returns {boolean} true if ipNumber is between lower and upper bound
646
+ */
647
+ static isWithinRange(ipNumber, lowerBound, upperBound) {
648
+ return ipNumber >= lowerBound && ipNumber <= upperBound;
649
+ }
650
+ /**
651
+ * Checks if the number given is within the value considered valid for an ASN number
652
+ *
653
+ * @param asnNumber the asn number to validate
654
+ * @returns {[boolean , string]} first value is true if valid ASN, false otherwise. Second value contains
655
+ * "valid" or an error message when value is invalid
656
+ */
657
+ static isValidAsnNumber(asnNumber) {
658
+ let isValid = this.isWithinRange(asnNumber, 0n, this.THIRTY_TWO_BIT_SIZE);
659
+ return [isValid, isValid ? [] : [Validator$1.invalidAsnRangeMessage]];
660
+ }
661
+ /**
662
+ * Checks if the given ASN number is a 16bit ASN number
663
+ *
664
+ * @param {bigint} asnNumber to check if 16bit or not
665
+ * @returns {[boolean , string]} first value is true if valid 16bit ASN, false otherwise. Second value contains
666
+ * "valid" or an error message when value is invalid
667
+ */
668
+ static isValid16BitAsnNumber(asnNumber) {
669
+ let isValid = Validator$1.isWithinRange(asnNumber, 0n, Validator$1.SIXTEEN_BIT_SIZE);
670
+ return [isValid, isValid ? [] : [Validator$1.invalid16BitAsnRangeMessage]];
671
+ }
672
+ /**
673
+ * Checks if the number given is within the value considered valid for an IPv4 number
674
+ *
675
+ * @param ipv4Number the asn number to validate
676
+ * @returns {[boolean , string]} first value is true if valid IPv4 number, false otherwise. Second value contains
677
+ * "valid" or an error message when value is invalid
678
+ */
679
+ static isValidIPv4Number(ipv4Number) {
680
+ ipv4Number = typeof ipv4Number === "bigint" ? ipv4Number : BigInt(ipv4Number);
681
+ let isValid = this.isWithinRange(ipv4Number, 0n, this.THIRTY_TWO_BIT_SIZE);
682
+ return isValid ? [isValid, []] : [isValid, [Validator$1.invalidIPv4NumberMessage]];
683
+ }
684
+ /**
685
+ * Checks if the number given is within the value considered valid for an IPv6 number
686
+ *
687
+ * @param ipv6Number the asn number to validate
688
+ * @returns {[boolean , string]} first value is true if valid IPv6 number, false otherwise. Second value contains
689
+ * "valid" or an error message when value is invalid
690
+ */
691
+ static isValidIPv6Number(ipv6Number) {
692
+ let isValid = this.isWithinRange(ipv6Number, 0n, this.ONE_HUNDRED_AND_TWENTY_EIGHT_BIT_SIZE);
693
+ return isValid ? [isValid, []] : [isValid, [Validator$1.invalidIPv6NumberMessage]];
694
+ }
695
+ /**
696
+ * Checks if the number given is valid for an IPv4 octet
697
+ *
698
+ * @param octetNumber the octet value
699
+ * @returns {boolean} true if valid octet, false otherwise
700
+ */
701
+ static isValidIPv4Octet(octetNumber) {
702
+ let withinRange = this.isWithinRange(octetNumber, 0n, this.EIGHT_BIT_SIZE);
703
+ return [withinRange, withinRange ? [] : [Validator$1.invalidOctetRangeMessage]];
704
+ }
705
+ /**
706
+ * Checks if the number given is valid for an IPv6 hexadecatet
707
+ *
708
+ * @param {bigint} hexadecatetNum the hexadecatet value
709
+ * @returns {[boolean , string]} first value is true if valid hexadecatet, false otherwise. Second value contains
710
+ * "valid" or an error message when value is invalid
711
+ */
712
+ static isValidIPv6Hexadecatet(hexadecatetNum) {
713
+ let isValid = this.isWithinRange(hexadecatetNum, 0n, this.SIXTEEN_BIT_SIZE);
714
+ return isValid ? [isValid, []] : [isValid, [Validator$1.invalidHexadecatetMessage]];
715
+ }
716
+ /**
717
+ * Checks if given string is a valid IPv4 value.
718
+ *
719
+ * @param {string} ipv4String the IPv4 string to validate
720
+ * @returns {[boolean , string]} result of validation, first value represents if is valid IPv4, second value
721
+ * contains error message if invalid IPv4
722
+ */
723
+ static isValidIPv4String(ipv4String) {
724
+ let rawOctets = ipv4String.split(".");
725
+ if (rawOctets.length != 4 || rawOctets.includes('')) {
726
+ return [false, [Validator$1.invalidOctetCountMessage]];
727
+ }
728
+ let isValid = rawOctets.every(octet => {
729
+ return Validator$1.isNumeric(octet) ? Validator$1.isValidIPv4Octet(BigInt(octet))[0] : false;
730
+ });
731
+ if (!isValid) {
732
+ return [false, [Validator$1.invalidOctetRangeMessage]];
733
+ }
734
+ isValid = Validator$1.IPV4_PATTERN.test(ipv4String);
735
+ return [isValid, isValid ? [] : [Validator$1.invalidIPv4PatternMessage]];
736
+ }
737
+ /**
738
+ * Checks if given string is a valid IPv6 value.
739
+ *
740
+ * @param {string} ipv6String the IPv6 string to validate
741
+ * @returns {[boolean , string]} result of validation, first value represents if is valid IPv6, second value
742
+ * contains error message if invalid IPv6
743
+ */
744
+ static isValidIPv6String(ipv6String) {
745
+ try {
746
+ let hexadecimals = IPv6Utils_1.expandIPv6Number(ipv6String).split(":");
747
+ if (hexadecimals.length != 8) {
748
+ return [false, [Validator$1.invalidHexadecatetCountMessage]];
749
+ }
750
+ let isValid = hexadecimals.every(hexadecimal => {
751
+ return Validator$1.isHexadecatet(hexadecimal) ?
752
+ Validator$1.isValidIPv6Hexadecatet(BigInt(`0x${hexadecimal}`))[0] : false;
753
+ });
754
+ if (!isValid) {
755
+ return [false, [Validator$1.invalidHexadecatetMessage]];
756
+ }
757
+ isValid = Validator$1.IPV6_PATTERN.test(ipv6String);
758
+ return [isValid, isValid ? [] : [Validator$1.invalidIPv6PatternMessage]];
759
+ }
760
+ catch (error) {
761
+ return [false, [error]];
762
+ }
763
+ }
764
+ /**
765
+ * Checks if given value is a valid prefix value
766
+ *
767
+ * @param prefixValue value to check
768
+ * @param ipNumType The type of IP number
769
+ * @returns {(boolean|string)[]} a tuple representing if valid or not and corresponding message
770
+ */
771
+ static isValidPrefixValue(prefixValue, ipNumType) {
772
+ if ("IPv4" /* IPv4 */ === ipNumType) {
773
+ let withinRange = Validator$1.isWithinRange(BigInt(prefixValue), 0n, 32n);
774
+ return [withinRange, withinRange ? [] : [Validator$1.invalidPrefixValueMessage]];
775
+ }
776
+ if ("IPv6" /* IPv6 */ === ipNumType) {
777
+ let withinRange = Validator$1.isWithinRange(BigInt(prefixValue), 0n, 128n);
778
+ return [withinRange, withinRange ? [] : [Validator$1.invalidPrefixValueMessage]];
779
+ }
780
+ return [false, [Validator$1.invalidInetNumType]];
781
+ }
782
+ /**
783
+ * Checks if given string is a valid IPv4 mask
784
+ *
785
+ * @param {string} ipv4MaskString the given IPv4 mask string
786
+ * @returns {[boolean , string]} first value is true if valid IPv4 mask string, false otherwise. Second value
787
+ * contains "valid" or an error message when value is invalid
788
+ */
789
+ static isValidIPv4Mask(ipv4MaskString) {
790
+ let ipv4InBinary = BinaryUtils_1.dottedDecimalNotationToBinaryString(ipv4MaskString);
791
+ let isValid = Validator$1.IPV4_CONTIGUOUS_MASK_BIT_PATTERN.test(ipv4InBinary);
792
+ return isValid ? [isValid, []] : [isValid, [Validator$1.invalidMaskMessage]];
793
+ }
794
+ /**
795
+ * Checks if given string is a valid IPv6 mask
796
+ *
797
+ * @param {string} ipv6MaskString the given IPv6 mask string
798
+ * @returns {[boolean , string]} first value is true if valid IPv6 mask string, false otherwise. Second value
799
+ * contains "valid" or an error message when value is invalid
800
+ */
801
+ static isValidIPv6Mask(ipv6MaskString) {
802
+ let ipv6InBinary = HexadecimalUtils_2.hexadectetNotationToBinaryString(ipv6MaskString);
803
+ let isValid = Validator$1.IPV6_CONTIGUOUS_MASK_BIT_PATTERN.test(ipv6InBinary);
804
+ return isValid ? [isValid, []] : [isValid, [Validator$1.invalidMaskMessage]];
805
+ }
806
+ /**
807
+ * Checks if the given string is a valid IPv4 range in Cidr notation
808
+ *
809
+ * @param {string} ipv4RangeAsCidrString the IPv4 range in Cidr notation
810
+ *
811
+ * @returns {[boolean , string[]]} first value is true if valid IPv4 range in Cidr notation, false otherwise. Second
812
+ * value contains "valid" or an error message when value is invalid
813
+ */
814
+ static isValidIPv4CidrNotation(ipv4RangeAsCidrString) {
815
+ let cidrComponents = ipv4RangeAsCidrString.split("/");
816
+ if (cidrComponents.length !== 2 || (cidrComponents[0].length === 0 || cidrComponents[1].length === 0)) {
817
+ return [false, [Validator$1.invalidIPv4CidrNotationMessage]];
818
+ }
819
+ let ip = cidrComponents[0];
820
+ let range = cidrComponents[1];
821
+ if (isNaN(Number(range))) {
822
+ return [false, [Validator$1.invalidIPv4CidrNotationMessage]];
823
+ }
824
+ let [validIpv4, invalidIpv4Message] = Validator$1.isValidIPv4String(ip);
825
+ let [validPrefix, invalidPrefixMessage] = Validator$1.isValidPrefixValue(BigInt(range), "IPv4" /* IPv4 */);
826
+ let isValid = validIpv4 && validPrefix;
827
+ let invalidMessage = invalidIpv4Message.concat(invalidPrefixMessage);
828
+ return isValid ? [isValid, []] : [isValid, invalidMessage];
829
+ }
830
+ /**
831
+ * Checks if the given string is a valid IPv4 range in Cidr notation, with the ip number in the cidr notation
832
+ * being the start of the range
833
+ *
834
+ * @param {string} ipv4CidrNotation the IPv4 range in Cidr notation
835
+ *
836
+ * * @returns {[boolean , string[]]} first value is true if valid Cidr notation, false otherwise. Second
837
+ * value contains [] or an array of error message when invalid
838
+ */
839
+ static isValidIPv4CidrRange(ipv4CidrNotation) {
840
+ return Validator$1.isValidCidrRange(ipv4CidrNotation, Validator$1.isValidIPv4CidrNotation, BinaryUtils_1.dottedDecimalNotationToBinaryString, (value) => BinaryUtils_2.cidrPrefixToMaskBinaryString(value, "IPv4" /* IPv4 */));
841
+ }
842
+ /**
843
+ * Checks if the given string is a valid IPv6 range in Cidr notation, with the ip number in the cidr notation
844
+ * being the start of the range
845
+ *
846
+ * @param {string} ipv6CidrNotation the IPv6 range in Cidr notation
847
+ *
848
+ * * @returns {[boolean , string[]]} first value is true if valid Cidr notation, false otherwise. Second
849
+ * value contains [] or an array of error message when invalid
850
+ */
851
+ static isValidIPv6CidrRange(ipv6CidrNotation) {
852
+ return Validator$1.isValidCidrRange(ipv6CidrNotation, Validator$1.isValidIPv6CidrNotation, HexadecimalUtils_1.colonHexadecimalNotationToBinaryString, (value) => BinaryUtils_2.cidrPrefixToMaskBinaryString(value, "IPv6" /* IPv6 */));
853
+ }
854
+ static isValidCidrRange(rangeString, cidrNotationValidator, toBinaryStringConverter, prefixFactory) {
855
+ let validationResult = cidrNotationValidator(rangeString);
856
+ if (!validationResult[0]) {
857
+ return validationResult;
858
+ }
859
+ let cidrComponents = rangeString.split("/");
860
+ let ip = cidrComponents[0];
861
+ let range = cidrComponents[1];
862
+ let ipNumber = BigInt(`0b${toBinaryStringConverter(ip)}`);
863
+ let mask = BigInt(`0b${prefixFactory(parseInt(range))}`);
864
+ let isValid = (ipNumber & (mask)) === (ipNumber);
865
+ return isValid ? [isValid, []] : [isValid, [Validator$1.InvalidIPCidrRangeMessage]];
866
+ }
867
+ static isValidIPv4RangeString(ipv4RangeString) {
868
+ let firstLastValidator = (firstIP, lastIP) => BigInt(`0b${BinaryUtils_1.dottedDecimalNotationToBinaryString(firstIP)}`)
869
+ >= BigInt(`0b${BinaryUtils_1.dottedDecimalNotationToBinaryString(lastIP)}`);
870
+ return this.isValidRange(ipv4RangeString, Validator$1.isValidIPv4String, firstLastValidator);
871
+ }
872
+ static isValidIPv6RangeString(ipv6RangeString) {
873
+ let firstLastValidator = (firstIP, lastIP) => BigInt(`0b${HexadecimalUtils_2.hexadectetNotationToBinaryString(firstIP)}`)
874
+ >= BigInt(`0b${HexadecimalUtils_2.hexadectetNotationToBinaryString(lastIP)}`);
875
+ return this.isValidRange(ipv6RangeString, Validator$1.isValidIPv6String, firstLastValidator);
876
+ }
877
+ static isValidRange(rangeString, validator, firstLastValidator) {
878
+ let rangeComponents = rangeString.split("-").map(component => component.trim());
879
+ if (rangeComponents.length !== 2 || (rangeComponents[0].length === 0 || rangeComponents[1].length === 0)) {
880
+ return [false, [Validator$1.invalidRangeNotationMessage]];
881
+ }
882
+ let firstIP = rangeComponents[0];
883
+ let lastIP = rangeComponents[1];
884
+ let [validFirstIP, invalidFirstIPMessage] = validator(firstIP);
885
+ let [validLastIP, invalidLastIPMessage] = validator(lastIP);
886
+ let isValid = validFirstIP && validLastIP;
887
+ if (isValid && firstLastValidator(firstIP, lastIP)) {
888
+ return [false, [Validator$1.invalidRangeFirstNotGreaterThanLastMessage]];
889
+ }
890
+ let invalidMessage = invalidFirstIPMessage.concat(invalidLastIPMessage);
891
+ return isValid ? [isValid, []] : [isValid, invalidMessage];
892
+ }
893
+ /**
894
+ * Checks if the given string is a valid IPv6 range in Cidr notation
895
+ *
896
+ * @param {string} ipv6RangeAsCidrString the IPv6 range in Cidr notation
897
+ *
898
+ * @returns {[boolean , string]} first value is true if valid IPv6 range in Cidr notation, false otherwise.
899
+ * Second value contains "valid" or an error message when value is invalid
900
+ */
901
+ // TODO change to be like isValidIPv4CidrNotation where validation is done on the component of the cidr notation
902
+ // instead of a single regex check
903
+ static isValidIPv6CidrNotation(ipv6RangeAsCidrString) {
904
+ let isValid = Validator$1.IPV6_RANGE_PATTERN.test(ipv6RangeAsCidrString);
905
+ return isValid ? [isValid, []] : [isValid, [Validator$1.invalidIPv6CidrNotationString]];
906
+ }
907
+ /**
908
+ * Checks if the given string is a binary string. That is contains only contiguous 1s and 0s
909
+ *
910
+ * @param {string} binaryString the binary string
911
+ * @returns {(boolean|string)[]} a tuple representing if valid or not and corresponding message
912
+ */
913
+ static isValidBinaryString(binaryString) {
914
+ if (/^([10])+$/.test(binaryString)) {
915
+ return [true, []];
916
+ }
917
+ else {
918
+ return [false, [Validator$1.invalidBinaryStringErrorMessage]];
919
+ }
920
+ }
921
+ static isNumeric(value) {
922
+ return /^(\d+)$/.test(value);
923
+ }
924
+ static isHexadecatet(value) {
925
+ return /^[0-9A-Fa-f]{4}$/.test(value);
926
+ }
927
+ }
928
+ Validator.Validator = Validator$1;
929
+ Validator$1.IPV4_PATTERN = new RegExp(/^(0?[0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.(0?[0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.(0?[0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.(0?[0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$/);
930
+ // source: https://community.helpsystems.com/forums/intermapper/miscellaneous-topics/5acc4fcf-fa83-e511-80cf-0050568460e4
931
+ Validator$1.IPV6_PATTERN = new RegExp(/^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/);
932
+ Validator$1.IPV4_RANGE_PATTERN = new RegExp(/^(0?[0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.(0?[0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.(0?[0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.(0?[0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/)([1-9]|[1-2][0-9]|3[0-2])$/);
933
+ Validator$1.IPV6_RANGE_PATTERN = new RegExp(/^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*(\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8]))?$/);
934
+ Validator$1.IPV4_CONTIGUOUS_MASK_BIT_PATTERN = new RegExp(/^(1){0,32}(0){0,32}$/);
935
+ Validator$1.IPV6_CONTIGUOUS_MASK_BIT_PATTERN = new RegExp(/^(1){0,128}(0){0,128}$/);
936
+ Validator$1.EIGHT_BIT_SIZE = BigInt(`0b${"1".repeat(8)}`);
937
+ Validator$1.SIXTEEN_BIT_SIZE = BigInt(`0b${"1".repeat(16)}`);
938
+ Validator$1.THIRTY_TWO_BIT_SIZE = BigInt(`0b${"1".repeat(32)}`);
939
+ Validator$1.ONE_HUNDRED_AND_TWENTY_EIGHT_BIT_SIZE = BigInt(`0b${"1".repeat(128)}`);
940
+ Validator$1.IPV4_SIZE = BigInt("4294967296");
941
+ Validator$1.IPV6_SIZE = BigInt("340282366920938463463374607431768211456");
942
+ Validator$1.invalidAsnRangeMessage = "ASN number given less than zero or is greater than 32bit";
943
+ Validator$1.invalid16BitAsnRangeMessage = "ASN number given less than zero or is greater than 16bit";
944
+ Validator$1.invalidIPv4NumberMessage = "IPv4 number given less than zero or is greater than 32bit";
945
+ Validator$1.invalidIPv6NumberMessage = "IPv6 number given less than zero or is greater than 128bit";
946
+ Validator$1.invalidOctetRangeMessage = "Value given contains an invalid Octet; Value is less than zero or is greater than 8bit";
947
+ Validator$1.invalidHexadecatetMessage = "The value given is less than zero or is greater than 16bit";
948
+ Validator$1.invalidOctetCountMessage = "An IP4 number cannot have less or greater than 4 octets";
949
+ Validator$1.invalidHexadecatetCountMessage = "An IP6 number must have exactly 8 hexadecatet";
950
+ Validator$1.invalidMaskMessage = "The Mask is invalid";
951
+ Validator$1.invalidPrefixValueMessage = "A Prefix value cannot be less than 0 or greater than 32";
952
+ Validator$1.invalidIPv4CidrNotationMessage = "Cidr notation should be in the form [ip number]/[range]";
953
+ Validator$1.InvalidIPCidrRangeMessage = "Given IP number portion must is not the start of the range";
954
+ Validator$1.invalidRangeNotationMessage = "Range notation should be in the form [first ip]-[last ip]";
955
+ Validator$1.invalidRangeFirstNotGreaterThanLastMessage = "First IP in [first ip]-[last ip] must be less than Last IP";
956
+ Validator$1.invalidIPv6CidrNotationString = "A Cidr notation string should contain an IPv6 number and prefix";
957
+ Validator$1.takeOutOfRangeSizeMessage = "$count is greater than $size, the size of the range";
958
+ Validator$1.cannotSplitSingleRangeErrorMessage = "Cannot split an IP range with a single IP number";
959
+ Validator$1.invalidInetNumType = "Given ipNumType must be either InetNumType.IPv4 or InetNumType.IPv6";
960
+ Validator$1.invalidBinaryStringErrorMessage = "Binary string should contain only contiguous 1s and 0s";
961
+ Validator$1.invalidIPRangeSizeMessage = "Given size is zero or greater than maximum size of $iptype";
962
+ Validator$1.invalidIPRangeSizeForCidrMessage = "Given size can't be created via cidr prefix";
963
+ Validator$1.invalidIPv4PatternMessage = "Given IPv4 is not confirm to a valid IPv6 address";
964
+ Validator$1.invalidIPv6PatternMessage = "Given IPv6 is not confirm to a valid IPv6 address";
965
+
966
+ return Validator;
967
+ }
968
+
969
+ Object.defineProperty(Hexadecatet$1, "__esModule", { value: true });
970
+ Hexadecatet$1.Hexadecatet = void 0;
971
+ const Validator_1$4 = requireValidator();
972
+ /**
973
+ * A representation of a 4-digit hexadecimal number.
974
+ *
975
+ * It consists of four (base 16) number. ie FFFF
976
+ *
977
+ * It is used to represents the components of an IPv6 address
978
+ */
979
+ class Hexadecatet {
980
+ /**
981
+ * Constructor for creating an instance of {@link Hexadecatet}
982
+ *
983
+ * @param {string | number} givenValue a string or numeric value. If given value is a string then it should be a
984
+ * four (base 16) number representation of a 16bit value. If it is a number, then it should be a decimal number
985
+ * representation of a 16 bit value
986
+ */
987
+ constructor(givenValue) {
988
+ let hexadecatetValue;
989
+ if (typeof givenValue === 'string') {
990
+ hexadecatetValue = parseInt(givenValue, 16);
991
+ }
992
+ else {
993
+ hexadecatetValue = parseInt(String(givenValue), 16);
994
+ }
995
+ let [isValid, message] = Validator_1$4.Validator.isValidIPv6Hexadecatet(BigInt(hexadecatetValue));
996
+ if (!isValid) {
997
+ throw Error(message.filter(msg => { return msg !== ''; }).toString());
998
+ }
999
+ this.value = hexadecatetValue;
1000
+ }
1001
+ /**
1002
+ * A convenience method for constructing an instance of {@link Hexadecatet} from a four (base 16) number
1003
+ * representation of a 16bit value.
1004
+ *
1005
+ * @param {string} rawValue the four (base 16) number
1006
+ * @returns {Hexadecatet} an instance of {@link Hexadecatet}
1007
+ */
1008
+ static fromString(rawValue) {
1009
+ return new Hexadecatet(rawValue);
1010
+ }
1011
+ ;
1012
+ /**
1013
+ * A convenience method for constructing an instance of {@link Hexadecatet} from a decimal number representation
1014
+ * of a 16 bit value
1015
+ *
1016
+ * @param {number} rawValue decimal number representation of a 16 bit value
1017
+ * @returns {Hexadecatet} an instance of {@link Hexadecatet}
1018
+ */
1019
+ static fromNumber(rawValue) {
1020
+ return new Hexadecatet(rawValue);
1021
+ }
1022
+ ;
1023
+ /**
1024
+ * Returns the numeric value in base 10 (ie decimal)
1025
+ *
1026
+ * @returns {number} the numeric value in base 10 (ie decimal)
1027
+ */
1028
+ getValue() {
1029
+ return this.value;
1030
+ }
1031
+ /**
1032
+ * Returns the string representation of the base 16 representation of the value
1033
+ * @returns {string} the string representation of the base 16 representation of the value
1034
+ */
1035
+ // TODO pad with a zero if digit is less than 4
1036
+ toString() {
1037
+ return this.value.toString(16);
1038
+ }
1039
+ }
1040
+ Hexadecatet$1.Hexadecatet = Hexadecatet;
1041
+
1042
+ var IPNumber = {};
1043
+
1044
+ var Octet$1 = {};
1045
+
1046
+ Object.defineProperty(Octet$1, "__esModule", { value: true });
1047
+ Octet$1.Octet = void 0;
1048
+ const Validator_1$3 = requireValidator();
1049
+ /**
1050
+ * A binary representation of a 8 bit value.
1051
+ *
1052
+ * {@see https://en.wikipedia.org/wiki/Octet_(computing)} for more information on Octets
1053
+ *
1054
+ * An octet is used in the textual representation of an {@link IPv4} number, where the IP number value is divided
1055
+ * into 4 octets
1056
+ */
1057
+ class Octet {
1058
+ /**
1059
+ * Constructor for creating an instance of an Octet.
1060
+ *
1061
+ * The constructor parameter given could either be a string or number.
1062
+ *
1063
+ * If a string, it is the string representation of the numeric value of the octet
1064
+ * If a number, it is the numeric representation of the value of the octet
1065
+ *
1066
+ * @param {string | number} givenValue value of the octet to be created.
1067
+ */
1068
+ constructor(givenValue) {
1069
+ let octetValue;
1070
+ if (typeof givenValue === 'string') {
1071
+ octetValue = parseInt(givenValue);
1072
+ }
1073
+ else {
1074
+ octetValue = givenValue;
1075
+ }
1076
+ let [isValid, message] = Validator_1$3.Validator.isValidIPv4Octet(BigInt(octetValue));
1077
+ if (!isValid) {
1078
+ throw Error(message.filter(msg => { return msg !== ''; }).toString());
1079
+ }
1080
+ this.value = octetValue;
1081
+ }
1082
+ /**
1083
+ * Convenience method for creating an Octet out of a string value representing the value of the octet
1084
+ *
1085
+ * @param {string} rawValue the octet value in string
1086
+ * @returns {Octet} the Octet instance
1087
+ */
1088
+ static fromString(rawValue) {
1089
+ return new Octet(rawValue);
1090
+ }
1091
+ ;
1092
+ /**
1093
+ * Convenience method for creating an Octet out of a numeric value representing the value of the octet
1094
+ *
1095
+ * @param {number} rawValue the octet value in number
1096
+ * @returns {Octet} the Octet instance
1097
+ */
1098
+ static fromNumber(rawValue) {
1099
+ return new Octet(rawValue);
1100
+ }
1101
+ ;
1102
+ /**
1103
+ * Method to get the numeric value of the octet
1104
+ *
1105
+ * @returns {number} the numeric value of the octet
1106
+ */
1107
+ getValue() {
1108
+ return this.value;
1109
+ }
1110
+ /**
1111
+ * Returns a decimal representation of the value of the octet in string
1112
+ *
1113
+ * @returns {string} a decimal representation of the value of the octet in string
1114
+ */
1115
+ toString() {
1116
+ return this.value.toString(10);
1117
+ }
1118
+ }
1119
+ Octet$1.Octet = Octet;
1120
+
1121
+ Object.defineProperty(IPNumber, "__esModule", { value: true });
1122
+ IPNumber.isIPv4 = IPNumber.IPv6Mask = IPNumber.IPv4Mask = IPNumber.IPv6 = IPNumber.Asn = IPNumber.IPv4 = IPNumber.AbstractIPNum = void 0;
1123
+ const Octet_1 = Octet$1;
1124
+ const Validator_1$2 = requireValidator();
1125
+ const BinaryUtils_1$2 = BinaryUtils;
1126
+ const BinaryUtils_2 = BinaryUtils;
1127
+ const BinaryUtils_3 = BinaryUtils;
1128
+ const BinaryUtils_4 = BinaryUtils;
1129
+ const Hexadecatet_1$1 = Hexadecatet$1;
1130
+ const HexadecimalUtils_1$1 = requireHexadecimalUtils();
1131
+ const IPv6Utils_1 = requireIPv6Utils();
1132
+ const HexadecimalUtils_2 = requireHexadecimalUtils();
1133
+ /**
1134
+ * Provides the implementation of functionality that are common
1135
+ * to {@link IPv4}, {@link IPv6}, {@link IPv4Mask} and {@link IPv6Mask}
1136
+ */
1137
+ class AbstractIPNum {
1138
+ /**
1139
+ * Gets the numeric value of an IP number as {@link BigInt}
1140
+ *
1141
+ * @returns bigInt the numeric value of an IP number.
1142
+ */
1143
+ getValue() {
1144
+ return this.value;
1145
+ }
1146
+ /**
1147
+ * Gets the binary string representation of an IP number.
1148
+ *
1149
+ * @returns {string} the string binary representation.
1150
+ */
1151
+ toBinaryString() {
1152
+ return BinaryUtils_3.leftPadWithZeroBit(this.value.toString(2), this.bitSize);
1153
+ }
1154
+ /**
1155
+ * Checks if an IP number has a value greater than the present value
1156
+ * @returns {boolean} true, if there is a value greater than the present value. Returns false otherwise.
1157
+ */
1158
+ hasNext() {
1159
+ return this.value < this.maximumBitSize;
1160
+ }
1161
+ /**
1162
+ * Checks if an IP number has a value lesser than the present value
1163
+ * @returns {boolean} true, if there is a value lesser than the present value. Returns false otherwise.
1164
+ */
1165
+ hasPrevious() {
1166
+ return this.value > 0n;
1167
+ }
1168
+ /**
1169
+ * Checks if the given IP number, is equals to the current IP number
1170
+ *
1171
+ * @param {AbstractIPNum} anotherIPNum the other IP number to compare with
1172
+ * @returns {boolean} true if the given IP number is equals
1173
+ */
1174
+ isEquals(anotherIPNum) {
1175
+ return this.value === anotherIPNum.value;
1176
+ }
1177
+ /**
1178
+ * Checks if the given IP number is lesser than this current IP number
1179
+ *
1180
+ * @param {AbstractIPNum} anotherIPNum the other IP number to compare with
1181
+ * @returns {boolean} true if the given IP number is less than this current one. False otherwise.
1182
+ */
1183
+ isLessThan(anotherIPNum) {
1184
+ return this.value < anotherIPNum.value;
1185
+ }
1186
+ /**
1187
+ * Checks if the given IP number is greater than this current IP number
1188
+ *
1189
+ * @param {AbstractIPNum} anotherIPNum the other IP number to compare with
1190
+ * @returns {boolean} true if the given IP number is greater than this current one. False otherwise.
1191
+ */
1192
+ isGreaterThan(anotherIPNum) {
1193
+ return this.value > anotherIPNum.value;
1194
+ }
1195
+ /**
1196
+ * Checks if the given IP number is less than or equals to this current IP number
1197
+ *
1198
+ * @param {AbstractIPNum} anotherIPNum the other IP number to compare with
1199
+ * @returns {boolean} true if the given IP number is less than or equals to this current one. False otherwise.
1200
+ */
1201
+ isLessThanOrEquals(anotherIPNum) {
1202
+ return this.value <= anotherIPNum.value;
1203
+ }
1204
+ /**
1205
+ * Checks if the given IP number is greater than or equals to this current IP number
1206
+ *
1207
+ * @param {AbstractIPNum} anotherIPNum the other IP number to compare with
1208
+ * @returns {boolean} {boolean} true if the given IP number is greater than or equals to this current one. False
1209
+ * otherwise.
1210
+ */
1211
+ isGreaterThanOrEquals(anotherIPNum) {
1212
+ return this.value >= anotherIPNum.value;
1213
+ }
1214
+ }
1215
+ IPNumber.AbstractIPNum = AbstractIPNum;
1216
+ /**
1217
+ * Represents an IPv4 number. A 32 bit number that is used to uniquely identify a device that is part of a computer
1218
+ * network that uses the internet protocol for communication.
1219
+ *
1220
+ * @see https://en.wikipedia.org/wiki/IPv4
1221
+ * @see https://www.rfc-editor.org/info/rfc791
1222
+ */
1223
+ class IPv4 extends AbstractIPNum {
1224
+ /**
1225
+ * Constructor for an IPv4 number.
1226
+ *
1227
+ * @param {string | bigint} ipValue value to construct an IPv4 from. The given value can either be
1228
+ * numeric or string. If a string is given then it needs to be in dot-decimal notation
1229
+ */
1230
+ constructor(ipValue) {
1231
+ super();
1232
+ /**
1233
+ * The number of bits needed to represents the value of the IPv4 number
1234
+ */
1235
+ this.bitSize = 32;
1236
+ /**
1237
+ * The maximum bit size (i.e. binary value) of the IPv4 number in BigInt
1238
+ */
1239
+ this.maximumBitSize = Validator_1$2.Validator.THIRTY_TWO_BIT_SIZE;
1240
+ /**
1241
+ * The type of IP number. Value is one of the values of the {@link IPNumType} enum
1242
+ * @type {IPNumType} the type of IP number
1243
+ */
1244
+ this.type = "IPv4" /* IPv4 */;
1245
+ /**
1246
+ * An array of {@link Octet}'s
1247
+ *
1248
+ * @type {Array} the octets that makes up the IPv4 number
1249
+ */
1250
+ this.octets = [];
1251
+ /**
1252
+ * The string character used to separate the individual octets when the IPv4 is rendered as strings
1253
+ *
1254
+ * @type {string} The string character used to separate the individual octets when rendered as strings
1255
+ */
1256
+ this.separator = ".";
1257
+ if (typeof ipValue === "string") {
1258
+ let [value, octets] = this.constructFromDecimalDottedString(ipValue);
1259
+ this.value = value;
1260
+ this.octets = octets;
1261
+ }
1262
+ else {
1263
+ let [value, octets] = this.constructFromBigIntValue(ipValue);
1264
+ this.value = value;
1265
+ this.octets = octets;
1266
+ }
1267
+ }
1268
+ /**
1269
+ * A convenience method for creating an {@link IPv4} by providing the decimal value of the IP number in BigInt
1270
+ *
1271
+ * @param {bigint} bigIntValue the decimal value of the IP number in BigInt
1272
+ * @returns {IPv4} the IPv4 instance
1273
+ */
1274
+ static fromNumber(bigIntValue) {
1275
+ return new IPv4(bigIntValue);
1276
+ }
1277
+ /**
1278
+ * A convenience method for creating an {@link IPv4} by providing the IP number in dot-decimal notation. E.g
1279
+ * "10.1.1.10"
1280
+ *
1281
+ * {@see https://en.wikipedia.org/wiki/Dot-decimal_notation} for more information on dot-decimal notation.
1282
+ *
1283
+ * @param {string} ipString the IP number in dot-decimal notation
1284
+ * @returns {IPv4} the IPv4 instance
1285
+ */
1286
+ static fromDecimalDottedString(ipString) {
1287
+ return new IPv4(ipString);
1288
+ }
1289
+ /**
1290
+ * Alias for IPv4.fromDecimalDottedString.
1291
+ *
1292
+ * @param {string} ipString the IP number in dot-decimal notation
1293
+ * @returns {IPv4} the IPv4 instance
1294
+ */
1295
+ static fromString(ipString) {
1296
+ return IPv4.fromDecimalDottedString(ipString);
1297
+ }
1298
+ /**
1299
+ * A convenience method for creating an {@link IPv4} from binary string
1300
+ *
1301
+ * @param {string} ipBinaryString the binary string representing the IPv4 number to be created
1302
+ * @returns {IPv4} the IPv4 instance
1303
+ */
1304
+ static fromBinaryString(ipBinaryString) {
1305
+ let validationResult = Validator_1$2.Validator.isValidBinaryString(ipBinaryString);
1306
+ if (validationResult[0]) {
1307
+ return new IPv4(BinaryUtils_2.parseBinaryStringToBigInt(ipBinaryString));
1308
+ }
1309
+ else {
1310
+ throw Error(validationResult[1].join(','));
1311
+ }
1312
+ }
1313
+ /**
1314
+ * A string representation of the IPv4 number. The string representation is in dot-decimal notation
1315
+ *
1316
+ * @returns {string} The string representation in dot-decimal notation
1317
+ */
1318
+ toString() {
1319
+ return this.octets.map((value) => { return value.toString(); }).join(this.separator);
1320
+ }
1321
+ /**
1322
+ * Gets the individual {@link Octet} that makes up the IPv4 number
1323
+ *
1324
+ * @returns {Array<Octet>} The individual {@link Octet} that makes up the IPv4 number
1325
+ */
1326
+ getOctets() {
1327
+ return this.octets;
1328
+ }
1329
+ /**
1330
+ * Returns the next IPv4 number
1331
+ *
1332
+ * @returns {IPv4} the next IPv4 number
1333
+ */
1334
+ nextIPNumber() {
1335
+ return IPv4.fromNumber(this.getValue() + 1n);
1336
+ }
1337
+ /**
1338
+ * Returns the previous IPv4 number
1339
+ *
1340
+ * @returns {IPv4} the previous IPv4 number
1341
+ */
1342
+ previousIPNumber() {
1343
+ return IPv4.fromNumber(this.getValue() - 1n);
1344
+ }
1345
+ /**
1346
+ * Returns this IPv4 number as a IPv4-Mapped IPv6 Address
1347
+ *
1348
+ * The IPv4-Mapped IPv6 Address allows an IPv4 number to be embedded within an IPv6 number
1349
+ *
1350
+ * {@see https://tools.ietf.org/html/rfc4291#section-2.5.5} for more information on the IPv4-Mapped IPv6 Address
1351
+ *
1352
+ * @returns {IPv6} an IPv6 number with the IPv4 embedded within it
1353
+ */
1354
+ toIPv4MappedIPv6() {
1355
+ let binary = '1'.repeat(16) + this.toBinaryString();
1356
+ return IPv6.fromBinaryString(binary);
1357
+ }
1358
+ constructFromDecimalDottedString(ipString) {
1359
+ let octets;
1360
+ let value;
1361
+ let [isValid, message] = Validator_1$2.Validator.isValidIPv4String(ipString);
1362
+ if (!isValid) {
1363
+ throw new Error(message.filter(msg => { return msg !== ''; }).toString());
1364
+ }
1365
+ let stringOctets = ipString.split(".");
1366
+ octets = stringOctets.map((rawOctet) => {
1367
+ return Octet_1.Octet.fromString(rawOctet);
1368
+ });
1369
+ value = BigInt(`0b${BinaryUtils_1$2.dottedDecimalNotationToBinaryString(ipString)}`);
1370
+ return [value, octets];
1371
+ }
1372
+ constructFromBigIntValue(ipv4Number) {
1373
+ let [isValid, message] = Validator_1$2.Validator.isValidIPv4Number(ipv4Number);
1374
+ if (!isValid) {
1375
+ throw new Error(message.filter(msg => { return msg !== ''; }).toString());
1376
+ }
1377
+ let binaryString = BinaryUtils_4.numberToBinaryString(ipv4Number);
1378
+ ipv4Number = typeof ipv4Number === "bigint" ? ipv4Number : BigInt(ipv4Number);
1379
+ return [ipv4Number, this.binaryStringToDecimalOctets(binaryString)];
1380
+ }
1381
+ binaryStringToDecimalOctets(ipv4BinaryString) {
1382
+ if (ipv4BinaryString.length < 32) {
1383
+ ipv4BinaryString = BinaryUtils_3.leftPadWithZeroBit(ipv4BinaryString, 32);
1384
+ }
1385
+ let octets = ipv4BinaryString.match(/.{1,8}/g);
1386
+ return octets.map((octet) => {
1387
+ return Octet_1.Octet.fromString(BinaryUtils_2.parseBinaryStringToBigInt(octet).toString());
1388
+ });
1389
+ }
1390
+ }
1391
+ IPNumber.IPv4 = IPv4;
1392
+ /**
1393
+ * Represents an Autonomous System Number. Which is a number that is used to identify
1394
+ * a group of IP addresses with a common, clearly defined routing policy.
1395
+ *
1396
+ * @see https://en.wikipedia.org/wiki/Autonomous_system_(Internet)
1397
+ * @see https://tools.ietf.org/html/rfc5396
1398
+ */
1399
+ class Asn extends AbstractIPNum {
1400
+ /**
1401
+ * Constructor for an instance of {@link ASN}
1402
+ *
1403
+ * @param {string | number} rawValue value to construct an ASN from. The given value can either be numeric or
1404
+ * string. If in string then it can be in asplain, asdot or asdot+ string representation format
1405
+ */
1406
+ constructor(rawValue) {
1407
+ super();
1408
+ /**
1409
+ * The number of bits needed to represents the value of the ASN number
1410
+ */
1411
+ this.bitSize = 32;
1412
+ /**
1413
+ * The maximum bit size (i.e. binary value) of the ASN number in BigInt
1414
+ */
1415
+ this.maximumBitSize = Validator_1$2.Validator.THIRTY_TWO_BIT_SIZE;
1416
+ this.type = "ASN" /* ASN */;
1417
+ if (typeof rawValue === 'string') {
1418
+ if (Asn.startWithASPrefix(rawValue)) {
1419
+ this.value = BigInt(parseInt(rawValue.substring(2)));
1420
+ }
1421
+ else if (rawValue.indexOf(".") != -1) {
1422
+ this.value = BigInt(this.parseFromDotNotation(rawValue));
1423
+ }
1424
+ else {
1425
+ this.value = BigInt(parseInt(rawValue));
1426
+ }
1427
+ }
1428
+ else {
1429
+ let valueAsBigInt = BigInt(rawValue);
1430
+ let [isValid, message] = Validator_1$2.Validator.isValidAsnNumber(valueAsBigInt);
1431
+ if (!isValid) {
1432
+ throw Error(message.filter(msg => { return msg !== ''; }).toString());
1433
+ }
1434
+ this.value = valueAsBigInt;
1435
+ }
1436
+ }
1437
+ /**
1438
+ * A convenience method for creating an instance of {@link Asn} from a string
1439
+ *
1440
+ * The given string can be in asplain, asdot or asdot+ representation format.
1441
+ * {@see https://tools.ietf.org/html/rfc5396} for more information on
1442
+ * the different ASN string representation
1443
+ *
1444
+ * @param {string} rawValue the asn string. In either asplain, asdot or asdot+ format
1445
+ * @returns {Asn} the constructed ASN instance
1446
+ */
1447
+ static fromString(rawValue) {
1448
+ return new Asn(rawValue);
1449
+ }
1450
+ ;
1451
+ /**
1452
+ * A convenience method for creating an instance of {@link Asn} from a numeric value
1453
+ *
1454
+ * @param {number} rawValue the asn numeric value
1455
+ * @returns {Asn} the constructed ASN instance
1456
+ */
1457
+ static fromNumber(rawValue) {
1458
+ return new Asn(rawValue);
1459
+ }
1460
+ ;
1461
+ /**
1462
+ * A convenience method for creating an instance of {@link Asn} from a binary string
1463
+ *
1464
+ * @param {string} binaryString to create an ASN instance from
1465
+ * @returns {Asn} the constructed ASN instance
1466
+ */
1467
+ static fromBinaryString(binaryString) {
1468
+ let validationResult = Validator_1$2.Validator.isValidBinaryString(binaryString);
1469
+ if (validationResult[0]) {
1470
+ return new Asn(parseInt(binaryString, 2));
1471
+ }
1472
+ else {
1473
+ throw Error(validationResult[1].join(','));
1474
+ }
1475
+ }
1476
+ /**
1477
+ * A string representation where the asn value is prefixed by "ASN". For example "AS65526"
1478
+ *
1479
+ * @returns {string} A string representation where the asn value is prefixed by "ASN"
1480
+ */
1481
+ toString() {
1482
+ let stringValue = this.value.toString();
1483
+ return `${Asn.AS_PREFIX}${stringValue}`;
1484
+ }
1485
+ /**
1486
+ * A string representation where the ASN numeric value of is represented as a string. For example "65526"
1487
+ *
1488
+ * @returns {string} A string representation where the ASN numeric value of is represented as a string
1489
+ */
1490
+ toASPlain() {
1491
+ return this.value.toString();
1492
+ }
1493
+ /**
1494
+ * A string representation where the ASN value is represented using the asplain notation if the ASN value is
1495
+ * less than 65536 and uses asdot+ notation when the value is greater than 65536.
1496
+ *
1497
+ * For example 65526 will be represented as "65526" while 65546 will be represented as "1.10"
1498
+ *
1499
+ *
1500
+ * @returns {string} A string representation of the ASN in either asplain or asdot+ notation depending on
1501
+ * whether the numeric value of the ASN number is greater than 65526 or not.
1502
+ */
1503
+ toASDot() {
1504
+ if (this.value.valueOf() >= 65536n) {
1505
+ return this.toASDotPlus();
1506
+ }
1507
+ return this.toASPlain();
1508
+ }
1509
+ /**
1510
+ * A string representation where the ASN value is represented using the asdot+ notation
1511
+ *
1512
+ * @returns {string} A string representation where the ASN value is represented using the asdot+ notation
1513
+ *
1514
+ */
1515
+ toASDotPlus() {
1516
+ let high = this.value.valueOf() / 65535n;
1517
+ let low = (this.value.valueOf() % 65535n) - high;
1518
+ return `${high}.${low}`;
1519
+ }
1520
+ /**
1521
+ * Converts the ASN value to binary numbers represented with strings
1522
+ *
1523
+ * @returns {string} a binary string representation of the value of the ASN number
1524
+ */
1525
+ toBinaryString() {
1526
+ return BinaryUtils_4.numberToBinaryString(this.value);
1527
+ }
1528
+ /**
1529
+ * Checks if the ASN value is 16bit
1530
+ *
1531
+ * @returns {boolean} true if the ASN is a 16bit value. False otherwise.
1532
+ */
1533
+ is16Bit() {
1534
+ let [valid16BitAsnNumber,] = Validator_1$2.Validator.isValid16BitAsnNumber(this.value);
1535
+ return valid16BitAsnNumber;
1536
+ }
1537
+ /**
1538
+ * Checks if the ASN value is 32bit
1539
+ *
1540
+ * @returns {boolean} true if the ASN is a 32bit value. False otherwise.
1541
+ */
1542
+ is32Bit() {
1543
+ return !this.is16Bit();
1544
+ }
1545
+ /**
1546
+ * Returns the next ASN number
1547
+ *
1548
+ * @returns {AbstractIPNum} the next ASN number
1549
+ */
1550
+ nextIPNumber() {
1551
+ return new Asn(this.value.valueOf() + 1n);
1552
+ }
1553
+ /**
1554
+ * Returns the previous ASN number
1555
+ *
1556
+ * @returns {AbstractIPNum} the previous ASN number
1557
+ */
1558
+ previousIPNumber() {
1559
+ return new Asn(this.value.valueOf() - 1n);
1560
+ }
1561
+ static startWithASPrefix(word) {
1562
+ return word.indexOf(Asn.AS_PREFIX) === 0;
1563
+ }
1564
+ parseFromDotNotation(rawValue) {
1565
+ let values = rawValue.split(".");
1566
+ let high = parseInt(values[0]);
1567
+ let low = parseInt(values[1]);
1568
+ return (high * 65535) + (low + high);
1569
+ }
1570
+ }
1571
+ IPNumber.Asn = Asn;
1572
+ Asn.AS_PREFIX = "AS";
1573
+ /**
1574
+ * Represents an IPv6 number. A 128 bit number that is used to uniquely identify a device that is part of a computer
1575
+ * network that uses the internet protocol for communication.
1576
+ *
1577
+ * @see https://en.wikipedia.org/wiki/IPv6
1578
+ * @see https://www.rfc-editor.org/info/rfc8200
1579
+ */
1580
+ class IPv6 extends AbstractIPNum {
1581
+ /**
1582
+ * Constructor for an IPv6 number.
1583
+ *
1584
+ * @param {string | bigint} ipValue value to construct an IPv6 from. The given value can either be
1585
+ * numeric or string. If a string is given then it needs to be in hexadecatet string notation
1586
+ */
1587
+ constructor(ipValue) {
1588
+ super();
1589
+ /**
1590
+ * The number of bits needed to represents the value of the IPv6 number
1591
+ */
1592
+ this.bitSize = 128;
1593
+ /**
1594
+ * The maximum bit size (i.e. binary value) of the IPv6 number in BigInt
1595
+ */
1596
+ this.maximumBitSize = Validator_1$2.Validator.ONE_HUNDRED_AND_TWENTY_EIGHT_BIT_SIZE;
1597
+ /**
1598
+ * The type of IP number. Value is one of the values of the {@link IPNumType} enum
1599
+ * @type {IPNumType} the type of IP number
1600
+ */
1601
+ this.type = "IPv6" /* IPv6 */;
1602
+ /**
1603
+ * An array of {@link Hexadecatet}'s
1604
+ *
1605
+ * @type {Array} the hexadecatet that makes up the IPv6 number
1606
+ */
1607
+ this.hexadecatet = [];
1608
+ /**
1609
+ * The string character used to separate the individual hexadecatet when the IPv6 is rendered as strings
1610
+ *
1611
+ * @type {string} The string character used to separate the individual hexadecatet when rendered as strings
1612
+ */
1613
+ this.separator = ":";
1614
+ if (typeof ipValue === "string") {
1615
+ let expandedIPv6 = IPv6Utils_1.expandIPv6Number(ipValue);
1616
+ let [value, hexadecatet] = this.constructFromHexadecimalDottedString(expandedIPv6);
1617
+ this.value = value;
1618
+ this.hexadecatet = hexadecatet;
1619
+ }
1620
+ else {
1621
+ let [value, hexadecatet] = this.constructFromBigIntValue(ipValue);
1622
+ this.value = value;
1623
+ this.hexadecatet = hexadecatet;
1624
+ }
1625
+ }
1626
+ /**
1627
+ * A convenience method for creating an {@link IPv6} by providing the decimal value of the IP number in BigInt
1628
+ *
1629
+ * @param {bigint} bigIntValue the decimal value of the IP number in BigInt
1630
+ * @returns {IPv6} the IPv6 instance
1631
+ */
1632
+ static fromBigInt(bigIntValue) {
1633
+ return new IPv6(bigIntValue);
1634
+ }
1635
+ /**
1636
+ * A convenience method for creating an {@link IPv6} by providing the IP number in hexadecatet notation. E.g
1637
+ * "2001:800:0:0:0:0:0:2002"
1638
+ *
1639
+ * {@see https://en.wikipedia.org/wiki/IPv6_address#Representation} for more information on hexadecatet notation.
1640
+ *
1641
+ * @param {string} ipString the IP number in hexadecatet
1642
+ * @returns {IPv6} the IPv6 instance
1643
+ */
1644
+ static fromHexadecatet(ipString) {
1645
+ return new IPv6(ipString);
1646
+ }
1647
+ /**
1648
+ * Alias for IPv6.fromHexadecimalString
1649
+ *
1650
+ * @param {string} ipString the IP number in hexadecatet
1651
+ * @returns {IPv6} the IPv6 instance
1652
+ */
1653
+ static fromString(ipString) {
1654
+ return IPv6.fromHexadecatet(ipString);
1655
+ }
1656
+ /**
1657
+ * A convenience method for creating an {@link IPv6} from binary string
1658
+ *
1659
+ * @param {string} ipBinaryString the binary string representing the IPv6 number to be created
1660
+ * @returns {IPv6} the IPv6 instance
1661
+ */
1662
+ static fromBinaryString(ipBinaryString) {
1663
+ let validationResult = Validator_1$2.Validator.isValidBinaryString(ipBinaryString);
1664
+ if (validationResult[0]) {
1665
+ let paddedBinaryString = BinaryUtils_3.leftPadWithZeroBit(ipBinaryString, 128);
1666
+ return new IPv6(BinaryUtils_2.parseBinaryStringToBigInt(paddedBinaryString));
1667
+ }
1668
+ else {
1669
+ throw Error(validationResult[1].join(','));
1670
+ }
1671
+ }
1672
+ /**
1673
+ * A convenience method for creating an IPv4-Compatible {@link IPv6} Address from an instance of {@link IPv4}
1674
+ *
1675
+ * @param {IPv4} ipv4 to create an IPv4-Compatible {@link IPv6} Address
1676
+ * @returns {IPv6} the IPv4-Compatible {@link IPv6} Address
1677
+ */
1678
+ static fromIPv4(ipv4) {
1679
+ return ipv4.toIPv4MappedIPv6();
1680
+ }
1681
+ /**
1682
+ * A convenience method for creating an IPv4-Compatible {@link IPv6} Address from a IPv4 represented in
1683
+ * dot-decimal notation i.e. 127.0.0.1
1684
+ *
1685
+ * @param {IPv4} ip4DotDecimalString string represented in a dot decimal string
1686
+ * @returns {IPv6} the IPv4-Compatible {@link IPv6} Address
1687
+ */
1688
+ static fromIPv4DotDecimalString(ip4DotDecimalString) {
1689
+ return new IPv4(ip4DotDecimalString).toIPv4MappedIPv6();
1690
+ }
1691
+ /**
1692
+ * A string representation of the IPv6 number.
1693
+ *
1694
+ * @returns {string} The string representation of IPv6
1695
+ */
1696
+ toString() {
1697
+ let ipv6String = this.hexadecatet.map((value) => { return value.toString(); }).join(":");
1698
+ if (this.hexadecatet.length < 8) {
1699
+ return "::" + ipv6String;
1700
+ }
1701
+ else {
1702
+ return ipv6String;
1703
+ }
1704
+ }
1705
+ /**
1706
+ * Gets the individual {@link Hexadecatet} that makes up the IPv6 number
1707
+ *
1708
+ * @returns {Array<Hexadecatet>} The individual {@link Hexadecatet} that makes up the IPv6 number
1709
+ */
1710
+ //TODO maybe rename to something like getSegments? so it can be same with getOctet
1711
+ getHexadecatet() {
1712
+ return this.hexadecatet;
1713
+ }
1714
+ /**
1715
+ * Returns the next IPv6 number
1716
+ *
1717
+ * @returns {IPv6} the next IPv6 number
1718
+ */
1719
+ nextIPNumber() {
1720
+ return IPv6.fromBigInt(this.getValue() + 1n);
1721
+ }
1722
+ /**
1723
+ * Returns the previous IPv6 number
1724
+ *
1725
+ * @returns {IPv6} the previous IPv6 number
1726
+ */
1727
+ previousIPNumber() {
1728
+ return IPv6.fromBigInt(this.getValue() - 1n);
1729
+ }
1730
+ constructFromBigIntValue(ipv6Number) {
1731
+ let [isValid, message] = Validator_1$2.Validator.isValidIPv6Number(ipv6Number);
1732
+ if (!isValid) {
1733
+ throw new Error(message.filter(msg => { return msg !== ''; }).toString());
1734
+ }
1735
+ let binaryString = BinaryUtils_4.numberToBinaryString(ipv6Number);
1736
+ return [ipv6Number, this.binaryStringToHexadecatets(binaryString)];
1737
+ }
1738
+ constructFromHexadecimalDottedString(expandedIPv6) {
1739
+ let [isValid, message] = Validator_1$2.Validator.isValidIPv6String(expandedIPv6);
1740
+ if (!isValid) {
1741
+ throw new Error(message.filter(msg => { return msg !== ''; }).toString());
1742
+ }
1743
+ let stringHexadecimals = expandedIPv6.split(":");
1744
+ let hexadecatet = stringHexadecimals.map((stringHexadecatet) => {
1745
+ return Hexadecatet_1$1.Hexadecatet.fromString(stringHexadecatet);
1746
+ });
1747
+ let value = BigInt(`0b${HexadecimalUtils_2.hexadectetNotationToBinaryString(expandedIPv6)}`);
1748
+ return [value, hexadecatet];
1749
+ }
1750
+ binaryStringToHexadecatets(binaryString) {
1751
+ let hexadecimalString = HexadecimalUtils_1$1.binaryStringToHexadecimalString(binaryString);
1752
+ while (hexadecimalString.length % 4 != 0) {
1753
+ hexadecimalString = '0' + hexadecimalString;
1754
+ }
1755
+ let hexadecimalStrings = hexadecimalString.match(/.{1,4}/g);
1756
+ return hexadecimalStrings.map((stringHexadecatet) => {
1757
+ return Hexadecatet_1$1.Hexadecatet.fromString(stringHexadecatet);
1758
+ });
1759
+ }
1760
+ }
1761
+ IPNumber.IPv6 = IPv6;
1762
+ /**
1763
+ * The IPv4Mask can be seen as a specialized IPv4 number where, in a 32 bit number, starting from the left, you
1764
+ * have continuous bits turned on (with 1 value) followed by bits turned off (with 0 value). In networking, it is used
1765
+ * to demarcate which bits are used to identify a network, and the ones that are used to identify hosts on the network
1766
+ */
1767
+ class IPv4Mask extends IPv4 {
1768
+ /**
1769
+ * Constructor for creating an instance of IPv4Mask.
1770
+ * The passed strings need to be a valid IPv4 mask number in dot-decimal notation.
1771
+ *
1772
+ * @param {string} ipString The passed string in dot-decimal notation
1773
+ */
1774
+ constructor(ipString) {
1775
+ super(ipString);
1776
+ /**
1777
+ * An array of {@link Octet}'s
1778
+ *
1779
+ * @type {Array} the octets that makes up the IPv4Mask
1780
+ */
1781
+ this.octets = [];
1782
+ let isValid;
1783
+ let message;
1784
+ [isValid, message] = Validator_1$2.Validator.isValidIPv4Mask(ipString);
1785
+ if (!isValid) {
1786
+ throw new Error(message.filter(msg => { return msg !== ''; }).toString());
1787
+ }
1788
+ let stringOctets = ipString.split(".");
1789
+ this.octets = stringOctets.map((rawOctet) => {
1790
+ return Octet_1.Octet.fromString(rawOctet);
1791
+ });
1792
+ let binaryString = BinaryUtils_1$2.dottedDecimalNotationToBinaryString(ipString);
1793
+ this.prefix = (binaryString.match(/1/g) || []).length;
1794
+ this.value = BigInt(`0b${binaryString}`);
1795
+ }
1796
+ /**
1797
+ * A convenience method for creating an instance of IPv4Mask. The passed strings need to be a valid IPv4
1798
+ * number in dot-decimal notation.
1799
+ *
1800
+ * @param {string} rawValue The passed string in dot-decimal notation
1801
+ * @returns {IPv4Mask} the instance of IPv4Mask
1802
+ */
1803
+ static fromDecimalDottedString(rawValue) {
1804
+ return new IPv4Mask(rawValue);
1805
+ }
1806
+ ;
1807
+ }
1808
+ IPNumber.IPv4Mask = IPv4Mask;
1809
+ /**
1810
+ * The IPv6Mask can be seen as a specialized IPv4 number where, in a 128 bit number, starting from the left,
1811
+ * you have continuous bits turned on (with 1 value) followed by bits turned off (with 0 value). In networking, it
1812
+ * is used to to demarcate which bits are used to identify a network, and the ones that are used to identify hosts
1813
+ * on the network
1814
+ */
1815
+ class IPv6Mask extends IPv6 {
1816
+ /**
1817
+ * Constructor for creating an instance of IPv6Mask.
1818
+ * The passed strings need to be a valid IPv6 mask number in dot-decimal notation
1819
+ *
1820
+ * @param {string} ipString The passed IPv6 string
1821
+ */
1822
+ constructor(ipString) {
1823
+ super(ipString);
1824
+ /**
1825
+ * An array of {@link Hexadecatet}'s
1826
+ *
1827
+ * @type {Array} the hexadecatet that makes up the IPv6 number
1828
+ */
1829
+ this.hexadecatet = [];
1830
+ let isValid;
1831
+ let message;
1832
+ [isValid, message] = Validator_1$2.Validator.isValidIPv6Mask(ipString);
1833
+ if (!isValid) {
1834
+ throw new Error(message.filter(msg => { return msg !== ''; }).toString());
1835
+ }
1836
+ let stringHexadecimals = ipString.split(":");
1837
+ this.hexadecatet = stringHexadecimals.map((stringHexadecatet) => {
1838
+ return Hexadecatet_1$1.Hexadecatet.fromString(stringHexadecatet);
1839
+ });
1840
+ let binaryString = HexadecimalUtils_2.hexadectetNotationToBinaryString(ipString);
1841
+ this.prefix = (binaryString.match(/1/g) || []).length;
1842
+ this.value = BigInt(`0b${binaryString}`);
1843
+ this.value = BigInt(`0b${HexadecimalUtils_2.hexadectetNotationToBinaryString(ipString)}`);
1844
+ }
1845
+ /**
1846
+ * A convenience method for creating an instance of IPv6Mask.
1847
+ * The passed strings need to be a valid IPv4 mask number in dot-decimal notation.
1848
+ *
1849
+ * @param {string} rawValue The passed string in textual notation
1850
+ * @returns {IPv6Mask} the instance of IPv6Mask
1851
+ */
1852
+ static fromHexadecatet(rawValue) {
1853
+ return new IPv6Mask(rawValue);
1854
+ }
1855
+ ;
1856
+ }
1857
+ IPNumber.IPv6Mask = IPv6Mask;
1858
+ /**
1859
+ * Check is the given IP number is an {@link IPv4} or not
1860
+ * @param ip the IP number to check if it is IPv4.
1861
+ */
1862
+ function isIPv4(ip) {
1863
+ return ip.bitSize === 32;
1864
+ }
1865
+ IPNumber.isIPv4 = isIPv4;
1866
+
1867
+ var IPNumType = {};
1868
+
1869
+ Object.defineProperty(IPNumType, "__esModule", { value: true });
1870
+
1871
+ var IPPool = {};
1872
+
1873
+ var IPRange = {};
1874
+
1875
+ var Prefix = {};
1876
+
1877
+ Object.defineProperty(Prefix, "__esModule", { value: true });
1878
+ Prefix.isIPv4Prefix = Prefix.IPv6Prefix = Prefix.IPv4Prefix = void 0;
1879
+ const Validator_1$1 = requireValidator();
1880
+ const IPNumber_1$1 = IPNumber;
1881
+ const BinaryUtils_1$1 = BinaryUtils;
1882
+ const HexadecimalUtils_1 = requireHexadecimalUtils();
1883
+ const Hexadecatet_1 = Hexadecatet$1;
1884
+ /**
1885
+ * Represents the prefix portion in the CIDR notation for representing IP ranges
1886
+ *
1887
+ * The IPv4 prefix portion represents the mask. It is the number of continuous bits turned on (with value 1)
1888
+ * counting from the left side of an 8 bit value.
1889
+ *
1890
+ * {@see https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing} for more information on CIDR
1891
+ */
1892
+ class IPv4Prefix {
1893
+ /**
1894
+ * Constructor for an instance of IPv4 prefix from a decimal number
1895
+ *
1896
+ * @param {number} rawValue the decimal value to construct the IPv4 prefix from.
1897
+ * @returns {IPv4Prefix} the instance of an IPv4 prefix
1898
+ */
1899
+ constructor(rawValue) {
1900
+ this.type = "IPv4";
1901
+ this.bitValue = 32n;
1902
+ let isValid;
1903
+ let message;
1904
+ [isValid, message] = Validator_1$1.Validator.isValidPrefixValue(rawValue, "IPv4" /* IPv4 */);
1905
+ if (!isValid) {
1906
+ throw new Error(message.filter(msg => { return msg !== ''; }).toString());
1907
+ }
1908
+ this.value = rawValue;
1909
+ }
1910
+ /**
1911
+ * Convenience method for constructing an instance of IPv4 prefix from a decimal number
1912
+ *
1913
+ * @param {number} rawValue the decimal value to construct the IPv4 prefix from.
1914
+ * @returns {IPv4Prefix} the instance of an IPv4 prefix
1915
+ */
1916
+ static fromNumber(rawValue) {
1917
+ return new IPv4Prefix(rawValue);
1918
+ }
1919
+ ;
1920
+ static fromRangeSize(rangeSize) {
1921
+ let prefixNumber = rangeSize === (1n) ? 32 : 32 - rangeSizeToPrefix(rangeSize, Validator_1$1.Validator.IPV4_SIZE);
1922
+ return IPv4Prefix.fromNumber(BigInt(prefixNumber));
1923
+ }
1924
+ ;
1925
+ /**
1926
+ * Gets the decimal value of the IPv4 prefix
1927
+ *
1928
+ * @returns {number} the decimal value of the IPv4 prefix
1929
+ */
1930
+ getValue() {
1931
+ return this.value;
1932
+ }
1933
+ /**
1934
+ * Gets the decimal value of the IPv4 prefix as string
1935
+ * @returns {string} The decimal value of the IPv4 prefix as string
1936
+ */
1937
+ toString() {
1938
+ return this.value.toString();
1939
+ }
1940
+ /**
1941
+ * Converts the IPv4 prefix to a {@link IPv4Mask}
1942
+ *
1943
+ * The IPv4 mask is the representation of the prefix in the dot-decimal notation
1944
+ *
1945
+ * @returns {IPv4Mask} the mask representation of the prefix
1946
+ */
1947
+ toMask() {
1948
+ let onBits = '1'.repeat(Number(this.value));
1949
+ let offBits = '0'.repeat(Number(32n - this.value));
1950
+ return IPNumber_1$1.IPv4Mask.fromDecimalDottedString(this.toDecimalNotation(`${onBits}${offBits}`));
1951
+ }
1952
+ /**
1953
+ * Returns the size (number of IP numbers) of range of this prefix
1954
+ *
1955
+ * @return {bigint} the size (number of IP numbers) of range of this prefix
1956
+ */
1957
+ toRangeSize() {
1958
+ /**
1959
+ * Using bitwise shift operation this will be
1960
+ * 1 << (this.bitValue - this.getValue())
1961
+ * Since left shift a number by x is equivalent to multiplying the number by the power x raised to 2
1962
+ * 2 << 4 = 2 * (2 raised to 4)
1963
+ */
1964
+ return 1n << (this.bitValue - this.getValue());
1965
+ }
1966
+ /**
1967
+ * Returns a prefix for when this prefix is merged
1968
+ * with another prefix of the same size
1969
+ */
1970
+ merge() {
1971
+ return new IPv4Prefix(this.value - 1n);
1972
+ }
1973
+ /**
1974
+ * Returns a prefix for when this prefix is split
1975
+ * into two equal halves
1976
+ */
1977
+ split() {
1978
+ return new IPv4Prefix(this.value + 1n);
1979
+ }
1980
+ toDecimalNotation(bits) {
1981
+ return `${BinaryUtils_1$1.parseBinaryStringToBigInt(bits.substr(0, 8))}.${BinaryUtils_1$1.parseBinaryStringToBigInt(bits.substr(8, 8))}.${BinaryUtils_1$1.parseBinaryStringToBigInt(bits.substr(16, 8))}.${BinaryUtils_1$1.parseBinaryStringToBigInt(bits.substr(24, 8))}`;
1982
+ }
1983
+ }
1984
+ Prefix.IPv4Prefix = IPv4Prefix;
1985
+ /**
1986
+ * Represents the prefix portion in the CIDR notation for representing IP ranges
1987
+ *
1988
+ * The IPv6 prefix portion represents the mask. It is the number of continuous bits turned on (with value 1)
1989
+ * counting from the left side of an 128 bit value.
1990
+ *
1991
+ * {@see https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing} for more information on CIDR
1992
+ */
1993
+ class IPv6Prefix {
1994
+ /**
1995
+ * Constructor for an instance of IPv6 prefix from a decimal number
1996
+ *
1997
+ * @param {number} rawValue the decimal value to construct the IPv6 prefix from.
1998
+ * @returns {IPv4Prefix} the instance of an IPv6 prefix
1999
+ */
2000
+ constructor(rawValue) {
2001
+ this.type = "IPv6";
2002
+ this.bitValue = 128n;
2003
+ let isValid;
2004
+ let message;
2005
+ [isValid, message] = Validator_1$1.Validator.isValidPrefixValue(rawValue, "IPv6" /* IPv6 */);
2006
+ if (!isValid) {
2007
+ throw new Error(message.filter(msg => { return msg !== ''; }).toString());
2008
+ }
2009
+ this.value = rawValue;
2010
+ }
2011
+ /**
2012
+ * Convenience method for constructing an instance of IPv46 prefix from a decimal number
2013
+ *
2014
+ * @param {number} rawValue the decimal value to construct the IPv6 prefix from.
2015
+ * @returns {IPv4Prefix} the instance of an IPv6 prefix
2016
+ */
2017
+ static fromNumber(rawValue) {
2018
+ return new IPv6Prefix(rawValue);
2019
+ }
2020
+ ;
2021
+ static fromRangeSize(rangeSize) {
2022
+ let prefixNumber = rangeSize === (1n) ? 128 : 128 - rangeSizeToPrefix(rangeSize, Validator_1$1.Validator.IPV6_SIZE);
2023
+ return IPv6Prefix.fromNumber(BigInt(prefixNumber));
2024
+ }
2025
+ /**
2026
+ * Gets the decimal value of the IPv6 prefix
2027
+ *
2028
+ * @returns {number} the decimal value of the IPv6 prefix
2029
+ */
2030
+ getValue() {
2031
+ return this.value;
2032
+ }
2033
+ /**
2034
+ * Gets the decimal value of the IPv4 prefix as string
2035
+ * @returns {string} he decimal value of the IPv4 prefix as string
2036
+ */
2037
+ toString() {
2038
+ return this.value.toString();
2039
+ }
2040
+ /**
2041
+ * Converts the IPv6 prefix to a {@link IPv6Mask}
2042
+ *
2043
+ * The IPv6 mask is the representation of the prefix in 8 groups of 16 bit values represented in hexadecimal
2044
+ *
2045
+ * @returns {IPv6Mask} the mask representation of the prefix
2046
+ */
2047
+ toMask() {
2048
+ let onBits = '1'.repeat(Number(this.value));
2049
+ let offBits = '0'.repeat(128 - Number(this.value));
2050
+ return IPNumber_1$1.IPv6Mask.fromHexadecatet(this.toHexadecatetNotation(`${onBits}${offBits}`));
2051
+ }
2052
+ /**
2053
+ * Returns the size (number of IP numbers) of range of this prefix
2054
+ *
2055
+ * @return {bigint} the size (number of IP numbers) of range of this prefix
2056
+ */
2057
+ toRangeSize() {
2058
+ /**
2059
+ * Using bitwise shift operation this will be
2060
+ * 1 << (this.bitValue - this.getValue())
2061
+ * Since left shift a number by x is equivalent to multiplying the number by the power x raised to 2
2062
+ * 2 << 4 = 2 * (2 raised to 4)
2063
+ */
2064
+ return 1n << (this.bitValue - this.getValue());
2065
+ }
2066
+ /**
2067
+ * Returns a prefix for when this prefix is merged
2068
+ * with another prefix of the same size
2069
+ */
2070
+ merge() {
2071
+ return new IPv6Prefix(this.value - 1n);
2072
+ }
2073
+ /**
2074
+ * Returns a prefix for when this prefix is split
2075
+ * into two equal halves
2076
+ */
2077
+ split() {
2078
+ return new IPv6Prefix(this.value + 1n);
2079
+ }
2080
+ toHexadecatetNotation(bits) {
2081
+ let binaryStrings = bits.match(/.{1,16}/g);
2082
+ let hexadecimalStrings = binaryStrings.map((binaryString) => {
2083
+ return Hexadecatet_1.Hexadecatet.fromString(HexadecimalUtils_1.binaryStringToHexadecimalString(binaryString));
2084
+ });
2085
+ return hexadecimalStrings.map((value) => { return value.toString(); }).join(":");
2086
+ }
2087
+ }
2088
+ Prefix.IPv6Prefix = IPv6Prefix;
2089
+ function rangeSizeToPrefix(rangeSize, rangeMaxSize) {
2090
+ let ipType = rangeMaxSize > (Validator_1$1.Validator.IPV4_SIZE) ? "IPv6" : "IPv4";
2091
+ if (rangeSize > (rangeMaxSize) || rangeSize === (0n)) {
2092
+ throw new Error(Validator_1$1.Validator.invalidIPRangeSizeMessage.replace("$iptype", ipType));
2093
+ }
2094
+ try {
2095
+ return BinaryUtils_1$1.intLog2(rangeSize);
2096
+ }
2097
+ catch (e) {
2098
+ throw new Error(Validator_1$1.Validator.invalidIPRangeSizeForCidrMessage);
2099
+ }
2100
+ }
2101
+ /**
2102
+ * Check is the given Prefix is an {@link IPv4Prefix} or not
2103
+ * @param prefix the IP prefix to check if it is IPv4Prefix.
2104
+ */
2105
+ function isIPv4Prefix(prefix) {
2106
+ return prefix.type === "IPv4";
2107
+ }
2108
+ Prefix.isIPv4Prefix = isIPv4Prefix;
2109
+
2110
+ Object.defineProperty(IPRange, "__esModule", { value: true });
2111
+ IPRange.isIPv4CidrRange = IPRange.IPv6CidrRange = IPRange.IPv4CidrRange = IPRange.AbstractIPRange = IPRange.RangedSet = void 0;
2112
+ const IPNumber_1 = IPNumber;
2113
+ const Prefix_1$1 = Prefix;
2114
+ const BinaryUtils_1 = BinaryUtils;
2115
+ const Validator_1 = requireValidator();
2116
+ /**
2117
+ * Represents a continuous segment of either IPv4 or IPv6 numbers
2118
+ * without adhering to classless inter-domain routing scheme
2119
+ * for allocating IP addresses.
2120
+ */
2121
+ class RangedSet {
2122
+ /**
2123
+ * Constructor for an instance of {@link RangedSet} from an
2124
+ * instance of either {@link IPv4CidrRange} or {@link IPv6CidrRange}
2125
+ *
2126
+ * Throws an exception if first IP number is not less than given last IP number
2127
+ *
2128
+ * @param first the first IP number of the range
2129
+ * @param last the last IP number of the range
2130
+ */
2131
+ constructor(first, last) {
2132
+ this.first = first;
2133
+ this.last = last;
2134
+ if (first.isGreaterThan(last)) {
2135
+ throw new Error(`${first.toString()} should be lower than ${last.toString()}`);
2136
+ }
2137
+ this.currentValue = first;
2138
+ this.bitValue = BigInt(first.bitSize);
2139
+ }
2140
+ /**
2141
+ * Convenience method for constructing an instance of {@link RangedSet} from a
2142
+ * single IP number.
2143
+ *
2144
+ * @param ip The IP number, either IPv4 or IPv6 to construct the range from.
2145
+ */
2146
+ static fromSingleIP(ip) {
2147
+ return new RangedSet(ip, ip);
2148
+ }
2149
+ /**
2150
+ * Convenience method for constructing an instance of {@link RangedSet} from an
2151
+ * instance of either {@link IPv4CidrRange} or {@link IPv6CidrRange}
2152
+ *
2153
+ * @param cidrRange an instance of {@link RangedSet}
2154
+ */
2155
+ static fromCidrRange(cidrRange) {
2156
+ return new RangedSet(cidrRange.getFirst(), cidrRange.getLast());
2157
+ }
2158
+ /**
2159
+ * Convenience method for constructing an instance of {@link RangedSet} from
2160
+ * a range string in the form of firstIp-lastIp
2161
+ *
2162
+ * @param rangeString string in the form of firstIp-lastIp
2163
+ */
2164
+ static fromRangeString(rangeString) {
2165
+ let ips = rangeString.split("-").map(ip => ip.trim());
2166
+ if (ips.length !== 2) {
2167
+ throw new Error("Argument should be in the format firstip-lastip");
2168
+ }
2169
+ let [firstIPString, lastIPString] = ips;
2170
+ let [isValidFirstIPv4,] = Validator_1.Validator.isValidIPv4String(firstIPString);
2171
+ let [isValidSecondIPv4,] = Validator_1.Validator.isValidIPv4String(lastIPString);
2172
+ let [isValidFirstIPv6,] = Validator_1.Validator.isValidIPv6String(firstIPString);
2173
+ let [isValidLastIPv6,] = Validator_1.Validator.isValidIPv6String(lastIPString);
2174
+ if (isValidFirstIPv4 && isValidSecondIPv4) {
2175
+ return new RangedSet(IPNumber_1.IPv4.fromDecimalDottedString(firstIPString), IPNumber_1.IPv4.fromDecimalDottedString(lastIPString));
2176
+ }
2177
+ else if (isValidFirstIPv6 && isValidLastIPv6) {
2178
+ return new RangedSet(IPNumber_1.IPv6.fromHexadecatet(firstIPString), IPNumber_1.IPv6.fromHexadecatet(lastIPString));
2179
+ }
2180
+ else {
2181
+ throw new Error("First IP and Last IP should be valid and same type");
2182
+ }
2183
+ }
2184
+ /**
2185
+ * Returns the first IP number in the range
2186
+ */
2187
+ getFirst() {
2188
+ return this.first;
2189
+ }
2190
+ /**
2191
+ * Returns the last IP number in the range
2192
+ */
2193
+ getLast() {
2194
+ return this.last;
2195
+ }
2196
+ /**
2197
+ * Returns the size, which is the number of IP numbers in the range.
2198
+ */
2199
+ getSize() {
2200
+ return this.last.getValue() - (this.first.getValue()) + 1n;
2201
+ }
2202
+ /**
2203
+ * Converts to a string representation of the range in the form of:
2204
+ * <first-ip>-<last-ip>
2205
+ */
2206
+ toRangeString() {
2207
+ return `${this.getFirst()}-${this.getLast()}`;
2208
+ }
2209
+ /**
2210
+ * Checks if this range is inside another range.
2211
+ *
2212
+ * @param otherRange the other range to check if this range is inside of.
2213
+ */
2214
+ inside(otherRange) {
2215
+ return otherRange.contains(this);
2216
+ }
2217
+ /**
2218
+ * Checks if this range contains the given other range.
2219
+ *
2220
+ * @param otherRange the other range to check if this range contains
2221
+ */
2222
+ contains(otherRange) {
2223
+ let thisFirst = this.getFirst();
2224
+ let thisLast = this.getLast();
2225
+ let otherFirst = otherRange.getFirst();
2226
+ let otherLast = otherRange.getLast();
2227
+ return (thisFirst.isLessThanOrEquals(otherFirst) && thisLast.isGreaterThanOrEquals(otherLast));
2228
+ }
2229
+ /**
2230
+ * Check if this range is equal to the given other range.
2231
+ *
2232
+ * @param otherRange the other range to check if equal to this range.
2233
+ */
2234
+ isEquals(otherRange) {
2235
+ return this.getFirst().isEquals(otherRange.getFirst())
2236
+ && this.getLast().isEquals(otherRange.getLast());
2237
+ }
2238
+ ;
2239
+ /**
2240
+ * Check if this range is less than the given range.
2241
+ *
2242
+ * @param otherRange the other range to check if less than.
2243
+ */
2244
+ isLessThan(otherRange) {
2245
+ if (this.isEquals(otherRange)) {
2246
+ return false;
2247
+ }
2248
+ else {
2249
+ if (this.getFirst().isEquals(otherRange.getFirst())) {
2250
+ return this.getSize() < (otherRange.getSize());
2251
+ }
2252
+ return this.getFirst().isLessThan(otherRange.getFirst());
2253
+ }
2254
+ }
2255
+ /**
2256
+ * Check if this range is greater than the given range.
2257
+ *
2258
+ * @param otherRange the other range to check if greater than.
2259
+ */
2260
+ isGreaterThan(otherRange) {
2261
+ if (this.isEquals(otherRange)) {
2262
+ return false;
2263
+ }
2264
+ else {
2265
+ if (this.getFirst().isEquals(otherRange.getFirst())) {
2266
+ return this.getSize() > (otherRange.getSize());
2267
+ }
2268
+ return this.getFirst().isGreaterThan(otherRange.getFirst());
2269
+ }
2270
+ }
2271
+ /**
2272
+ * Checks of this range overlaps with a given other range.
2273
+ *
2274
+ * This means it checks if part of a range is part of another range without
2275
+ * being totally contained in the other range. Hence Equal or ranges contained inside one
2276
+ * another are not considered as overlapping.
2277
+ *
2278
+ * @param otherRange the other range to check if it overlaps with this range.
2279
+ */
2280
+ isOverlapping(otherRange) {
2281
+ let thisFirst = this.getFirst();
2282
+ let thisLast = this.getLast();
2283
+ let otherFirst = otherRange.getFirst();
2284
+ let otherLast = otherRange.getLast();
2285
+ return (thisLast.isGreaterThan(otherFirst) && thisLast.isLessThanOrEquals(otherLast) && thisFirst.isLessThan(otherFirst)
2286
+ ||
2287
+ otherLast.isGreaterThan(thisFirst) && otherLast.isLessThanOrEquals(thisLast) && otherFirst.isLessThan(thisFirst));
2288
+ }
2289
+ /**
2290
+ * Check if this range can be converted to a CIDR range.
2291
+ */
2292
+ isCidrAble() {
2293
+ if (this.getSize() === 1n) {
2294
+ return true;
2295
+ }
2296
+ try {
2297
+ let prefix = BinaryUtils_1.intLog2(this.getSize());
2298
+ let netmask = BinaryUtils_1.parseBinaryStringToBigInt(BinaryUtils_1.cidrPrefixToMaskBinaryString(prefix, IPNumber_1.isIPv4(this.currentValue) ? "IPv4" /* IPv4 */ : "IPv6" /* IPv6 */));
2299
+ return (this.first.getValue()) === (netmask & (this.first.getValue()));
2300
+ }
2301
+ catch (e) {
2302
+ return false;
2303
+ }
2304
+ }
2305
+ /**
2306
+ * Converts an instance of range to an instance of CIDR range
2307
+ */
2308
+ toCidrRange() {
2309
+ if (IPNumber_1.isIPv4(this.currentValue)) {
2310
+ return this.toIPv4CidrRange();
2311
+ }
2312
+ else {
2313
+ return this.toIPv6CidrRange();
2314
+ }
2315
+ }
2316
+ ;
2317
+ /**
2318
+ * Checks if this range is consecutive with another range.
2319
+ *
2320
+ * This means if the two ranges can be placed side by side, without any gap. Hence Equal
2321
+ * or ranges contained inside one another, or overlapping ranges are not considered as consecutive.
2322
+ *
2323
+ * @param otherRange the other range to check if this range is consecutive to.
2324
+ */
2325
+ isConsecutive(otherRange) {
2326
+ let thisFirst = this.getFirst();
2327
+ let thisLast = this.getLast();
2328
+ let otherFirst = otherRange.getFirst();
2329
+ let otherLast = otherRange.getLast();
2330
+ return (thisLast.hasNext() && thisLast.nextIPNumber().isEquals(otherFirst)
2331
+ ||
2332
+ otherLast.hasNext() && otherLast.nextIPNumber().isEquals(thisFirst));
2333
+ }
2334
+ /**
2335
+ * Creates a range that is a union of this range and the given other range.
2336
+ *
2337
+ * @param otherRange the other range to combine with this range
2338
+ */
2339
+ union(otherRange) {
2340
+ if (this.isEquals(otherRange)) {
2341
+ return new RangedSet(otherRange.getFirst(), otherRange.getLast());
2342
+ }
2343
+ if (this.isOverlapping(otherRange)) {
2344
+ if (this.getFirst().isLessThan(otherRange.getFirst())) {
2345
+ return new RangedSet(this.getFirst(), otherRange.getLast());
2346
+ }
2347
+ else {
2348
+ return new RangedSet(otherRange.getFirst(), this.getLast());
2349
+ }
2350
+ }
2351
+ if (this.contains(otherRange)) {
2352
+ return new RangedSet(this.getFirst(), this.getLast());
2353
+ }
2354
+ else if (otherRange.contains(this)) {
2355
+ return new RangedSet(otherRange.getFirst(), otherRange.getLast());
2356
+ }
2357
+ throw new Error("Ranges do not overlap nor are equal");
2358
+ }
2359
+ /**
2360
+ * Prepends given range with this range.
2361
+ * The last IP in the given range should be adjacent to the first IP in this range
2362
+ *
2363
+ * @param otherRange the other range to prepend
2364
+ */
2365
+ prepend(otherRange) {
2366
+ if (otherRange.getLast().nextIPNumber().isEquals(this.getFirst())) {
2367
+ return new RangedSet(otherRange.getFirst(), this.getLast());
2368
+ }
2369
+ else {
2370
+ throw new Error("Range to prepend must be adjacent");
2371
+ }
2372
+ }
2373
+ /**
2374
+ * Appends given range with this range.
2375
+ * The last IP in this range should be adjacent to the first IP in range to append
2376
+ *
2377
+ * @param otherRange the other range to append
2378
+ */
2379
+ append(otherRange) {
2380
+ if (this.getLast().nextIPNumber().isEquals(otherRange.getFirst())) {
2381
+ return new RangedSet(this.getFirst(), otherRange.getLast());
2382
+ }
2383
+ else {
2384
+ throw new Error("Range to append must be adjacent");
2385
+ }
2386
+ }
2387
+ subtract(otherRange) {
2388
+ if (!this.isOverlapping(otherRange)) {
2389
+ throw new Error("Cannot subtract ranges that are not overlapping");
2390
+ }
2391
+ if (!this.isLessThan(otherRange)) {
2392
+ throw new Error("Cannot subtract a larger range from this range");
2393
+ }
2394
+ return new RangedSet(this.getFirst(), otherRange.getLast());
2395
+ }
2396
+ /**
2397
+ * Returns a sub range of a given size from this range.
2398
+ *
2399
+ * @param offset offset from this range where the subrange should begin
2400
+ * @param size the size of the range
2401
+ */
2402
+ takeSubRange(offset, size) {
2403
+ if (offset + (size) > (this.getSize())) {
2404
+ throw new RangeError("Requested range is greater than what can be taken");
2405
+ }
2406
+ if (size === (0n)) {
2407
+ throw new Error("Sub range cannot be zero");
2408
+ }
2409
+ let valueOfFirstIp = this.getFirst().value + (offset);
2410
+ let firstIp = IPNumber_1.isIPv4(this.getFirst()) ?
2411
+ IPNumber_1.IPv4.fromNumber(valueOfFirstIp) : IPNumber_1.IPv6.fromBigInt(valueOfFirstIp);
2412
+ let valueOfLastIp = firstIp.value + (size - 1n);
2413
+ let lastIp = IPNumber_1.isIPv4(firstIp) ? IPNumber_1.IPv4.fromNumber(valueOfLastIp) : IPNumber_1.IPv6.fromBigInt(valueOfLastIp);
2414
+ return new RangedSet(firstIp, lastIp);
2415
+ }
2416
+ /**
2417
+ * Performs a subtraction operation, where the passed range is removed from the original range.
2418
+ *
2419
+ * The return range from the subtraction operation could be a single or multiple ranges
2420
+ *
2421
+ * @param range
2422
+ */
2423
+ difference(range) {
2424
+ if (range.getSize() > (this.getSize())) {
2425
+ throw new Error("Range is greater than range to be subtracted from");
2426
+ }
2427
+ if (!this.contains(range)) {
2428
+ throw new Error("Range to subtract is not contained in this range");
2429
+ }
2430
+ let reminders = [];
2431
+ try {
2432
+ reminders.push(new RangedSet(this.getFirst(), range.getFirst().previousIPNumber()));
2433
+ }
2434
+ catch (e) { }
2435
+ try {
2436
+ reminders.push(new RangedSet(range.getLast().nextIPNumber(), this.getLast()));
2437
+ }
2438
+ catch (e) { }
2439
+ return reminders;
2440
+ }
2441
+ *take(count) {
2442
+ let computed = this.getFirst();
2443
+ let returnCount = count === undefined ? this.getSize().valueOf() : count;
2444
+ while (returnCount > 0) {
2445
+ returnCount--;
2446
+ yield computed;
2447
+ computed = computed.nextIPNumber();
2448
+ }
2449
+ }
2450
+ *[Symbol.iterator]() {
2451
+ yield* this.take();
2452
+ }
2453
+ toIPv4CidrRange() {
2454
+ let candidateRange = new IPv4CidrRange(IPNumber_1.IPv4.fromNumber(this.getFirst().getValue()), Prefix_1$1.IPv4Prefix.fromRangeSize(this.getSize()));
2455
+ if (candidateRange.getFirst().isEquals(this.getFirst())) {
2456
+ return candidateRange;
2457
+ }
2458
+ else {
2459
+ throw new Error("Range cannot be converted to CIDR");
2460
+ }
2461
+ }
2462
+ toIPv6CidrRange() {
2463
+ let candidateRange = new IPv6CidrRange(IPNumber_1.IPv6.fromBigInt(this.getFirst().getValue()), Prefix_1$1.IPv6Prefix.fromRangeSize(this.getSize()));
2464
+ if (candidateRange.getFirst().isEquals(this.getFirst())) {
2465
+ return candidateRange;
2466
+ }
2467
+ else {
2468
+ throw new Error("Range cannot be converted to CIDR");
2469
+ }
2470
+ }
2471
+ }
2472
+ IPRange.RangedSet = RangedSet;
2473
+ /**
2474
+ * Provides the implementation of functionality that are common to {@link IPv4CidrRange} and {@link IPv6CidrRange}
2475
+ */
2476
+ class AbstractIPRange {
2477
+ hasNextRange() {
2478
+ let sizeOfCurrentRange = this.getSize();
2479
+ return ((2n ** this.bitValue) - sizeOfCurrentRange) >= (this.getFirst().getValue() + (sizeOfCurrentRange));
2480
+ }
2481
+ hasPreviousRange() {
2482
+ return this.getSize() <= (this.getFirst().getValue());
2483
+ }
2484
+ toRangeSet() {
2485
+ return new RangedSet(this.getFirst(), this.getLast());
2486
+ }
2487
+ inside(otherRange) {
2488
+ return this.toRangeSet().inside(otherRange.toRangeSet());
2489
+ }
2490
+ contains(otherRange) {
2491
+ return this.toRangeSet().contains(otherRange.toRangeSet());
2492
+ }
2493
+ toRangeString() {
2494
+ return this.toRangeSet().toRangeString();
2495
+ }
2496
+ isOverlapping(otherRange) {
2497
+ return this.toRangeSet().isOverlapping(otherRange.toRangeSet());
2498
+ }
2499
+ isConsecutive(otherRange) {
2500
+ return this.toRangeSet().isConsecutive(otherRange.toRangeSet());
2501
+ }
2502
+ isCidrMergeable(otherRange) {
2503
+ const count = BigInt(BinaryUtils_1.matchingBitCount(this.getFirst().toBinaryString(), otherRange.getFirst().toBinaryString()));
2504
+ if (this.getPrefix().value - count !== 1n) {
2505
+ return false;
2506
+ }
2507
+ return this.isConsecutive(otherRange) && this.getSize() === (otherRange.getSize());
2508
+ }
2509
+ isMergeable(otherRange) {
2510
+ return this.isCidrMergeable(otherRange)
2511
+ || this.contains(otherRange)
2512
+ || this.inside(otherRange);
2513
+ }
2514
+ isEquals(otherRange) {
2515
+ return this.toRangeSet().isEquals(otherRange.toRangeSet());
2516
+ }
2517
+ merge(otherRange) {
2518
+ if (!this.isCidrMergeable(otherRange)) {
2519
+ throw new Error(`Cannot merge. Ranges (${this.toRangeString()},${otherRange.toRangeString()}) are not consecutive and/or of same size`);
2520
+ }
2521
+ return this.newInstance(this.getFirst(), this.getPrefix().merge());
2522
+ }
2523
+ /**
2524
+ * Returns a lazily evaluated representation of the IP range that produces IP numbers by either:
2525
+ *
2526
+ * - iterating over using the for of syntax
2527
+ * - converting to array using spread syntax
2528
+ * - or assigning values to variables using deconstruction
2529
+ *
2530
+ * @param count the number of IP numbers to lazily evaluate.
2531
+ * If none is given, the whole IP range is lazily returned.
2532
+ */
2533
+ *takeStream(count) {
2534
+ return this.toRangeSet().take(count);
2535
+ }
2536
+ *[Symbol.iterator]() {
2537
+ yield* this.toRangeSet();
2538
+ }
2539
+ }
2540
+ IPRange.AbstractIPRange = AbstractIPRange;
2541
+ /**
2542
+ * Represents a continuous segment of IPv4 numbers following the
2543
+ * classless inter-domain routing scheme for allocating IP addresses.
2544
+ *
2545
+ * @see https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
2546
+ */
2547
+ class IPv4CidrRange extends AbstractIPRange {
2548
+ /**
2549
+ * Constructor for creating an instance of an IPv4 range.
2550
+ *
2551
+ * The arguments taken by the constructor is inspired by the CIDR notation which basically consists of the IP
2552
+ * number and the prefix.
2553
+ *
2554
+ * @param {IPv4} ipv4 the IP number used to construct the range. By convention this is the first IP number in
2555
+ * the range, but it could also be any IP number within the range
2556
+ * @param {IPv4Prefix} cidrPrefix the prefix which is a representation of the number of bits used to mask the
2557
+ * given IP number in other to create the range
2558
+ */
2559
+ constructor(ipv4, cidrPrefix) {
2560
+ super();
2561
+ this.ipv4 = ipv4;
2562
+ this.cidrPrefix = cidrPrefix;
2563
+ this.bitValue = 32n;
2564
+ }
2565
+ /**
2566
+ * Convenience method for constructing an instance of an IPv4CidrRange from an IP range represented in CIDR notation
2567
+ *
2568
+ * @param {string} rangeIncidrNotation the range of the IPv4 number in CIDR notation
2569
+ * @returns {IPv4CidrRange} the IPv4CidrRange
2570
+ */
2571
+ static fromCidr(rangeIncidrNotation) {
2572
+ let [isValid, errorMessages] = Validator_1.Validator.isValidIPv4CidrNotation(rangeIncidrNotation);
2573
+ if (!isValid) {
2574
+ let messages = errorMessages.filter(message => { return message !== ''; });
2575
+ throw new Error(messages.join(' and '));
2576
+ }
2577
+ let cidrComponents = rangeIncidrNotation.split("/");
2578
+ let ipString = cidrComponents[0];
2579
+ let prefix = BigInt(parseInt(cidrComponents[1]));
2580
+ return new IPv4CidrRange(IPNumber_1.IPv4.fromDecimalDottedString(ipString), Prefix_1$1.IPv4Prefix.fromNumber(prefix));
2581
+ }
2582
+ /**
2583
+ * Gets the size of IPv4 numbers contained within the IPv4 range
2584
+ *
2585
+ * @returns {bigint} the amount of IPv4 numbers in the range
2586
+ */
2587
+ getSize() {
2588
+ return this.cidrPrefix.toRangeSize();
2589
+ }
2590
+ /**
2591
+ * Method that returns the IPv4 range in CIDR (Classless Inter-Domain Routing) notation.
2592
+ *
2593
+ * See {@link https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation} for more information
2594
+ * on the Classless Inter-Domain Routing notation
2595
+ *
2596
+ * @returns {string} the IPv4 range in CIDR (Classless Inter-Domain Routing) notation
2597
+ */
2598
+ toCidrString() {
2599
+ let first = this.ipv4.toString();
2600
+ return `${first.toString()}/${this.cidrPrefix.toString()}`;
2601
+ }
2602
+ /**
2603
+ * Method that returns the IPv4 range in string notation where the first IPv4 number and last IPv4 number are
2604
+ * separated by an hyphen. eg. 192.198.0.0-192.198.0.255
2605
+ *
2606
+ * @returns {string} the range in [first IPv4 number] - [last IPv4 number] format
2607
+ */
2608
+ toRangeString() {
2609
+ return super.toRangeString();
2610
+ }
2611
+ /**
2612
+ * Method that returns the first IPv4 number in the IPv4 range
2613
+ *
2614
+ * @returns {IPv4} the first IPv4 number in the IPv4 range
2615
+ */
2616
+ getFirst() {
2617
+ return IPNumber_1.IPv4.fromNumber(this.ipv4.getValue() & (this.cidrPrefix.toMask().getValue()));
2618
+ }
2619
+ /**
2620
+ * Method that returns the last IPv4 number in the IPv4 range
2621
+ *
2622
+ * @returns {IPv4} the last IPv4 number in the IPv4 range
2623
+ */
2624
+ getLast() {
2625
+ return last(this, this.ipv4);
2626
+ }
2627
+ newInstance(num, prefix) {
2628
+ return new IPv4CidrRange(num, prefix);
2629
+ }
2630
+ getPrefix() {
2631
+ return this.cidrPrefix;
2632
+ }
2633
+ /**
2634
+ * Indicates whether the given IPv4 range is an adjacent range.
2635
+ *
2636
+ * An adjacent range being one where the end of the given range, when incremented by one marks the start of the
2637
+ * other range. Or where the start of the given range, when decreased by one, marks the end of the other range
2638
+ *
2639
+ * @param {IPv4CidrRange} otherRange the other IPv4 range to compare with
2640
+ * @returns {boolean} true if the two IPv4 ranges are consecutive, false otherwise
2641
+ */
2642
+ isConsecutive(otherRange) {
2643
+ return super.isConsecutive(otherRange);
2644
+ }
2645
+ /**
2646
+ * Indicates if the given IPv4 range is a subset.
2647
+ *
2648
+ * By a subset range, it means all the values of the given range are contained by this IPv4 range
2649
+ *
2650
+ * @param {IPv4CidrRange} otherRange the other IPv4 range
2651
+ * @returns {boolean} true if the other Ipv4 range is a subset. False otherwise.
2652
+ */
2653
+ contains(otherRange) {
2654
+ return super.contains(otherRange);
2655
+ }
2656
+ /**
2657
+ * Indicate if the given range is a container range.
2658
+ *
2659
+ * By container range, it means all the IP number in this current range can be found within the given range.
2660
+ *
2661
+ * @param {IPv4CidrRange} otherRange he other IPv4 range
2662
+ * @returns {boolean} true if the other Ipv4 range is a container range. False otherwise.
2663
+ */
2664
+ inside(otherRange) {
2665
+ return super.inside(otherRange);
2666
+ }
2667
+ /**
2668
+ * Checks if two IPv4 ranges overlap
2669
+ * @param {IPv4CidrRange} otherRange the other IPv4 range
2670
+ * @returns {boolean} true if the ranges overlap, false otherwise
2671
+ */
2672
+ isOverlapping(otherRange) {
2673
+ return super.isOverlapping(otherRange);
2674
+ }
2675
+ /**
2676
+ * Method that takes IPv4 number from within an IPv4 range, starting from the first IPv4 number
2677
+ *
2678
+ * @param {bigint} count the amount of IPv4 number to take from the IPv4 range
2679
+ * @returns {Array<IPv4>} an array of IPv4 number, taken from the IPv4 range
2680
+ */
2681
+ take(count) {
2682
+ let ipv4s = [this.getFirst()];
2683
+ let iteratingIPv4 = this.getFirst();
2684
+ if (count > (this.getSize())) {
2685
+ let errMessage = Validator_1.Validator.takeOutOfRangeSizeMessage
2686
+ .replace("$count", count.toString())
2687
+ .replace("$size", this.getSize().toString());
2688
+ throw new Error(errMessage);
2689
+ }
2690
+ for (let counter = 0; counter < count - 1n; counter++) {
2691
+ ipv4s.push(iteratingIPv4.nextIPNumber());
2692
+ iteratingIPv4 = iteratingIPv4.nextIPNumber();
2693
+ }
2694
+ return ipv4s;
2695
+ }
2696
+ /**
2697
+ * Method that splits an IPv4 range into two halves
2698
+ *
2699
+ * @returns {Array<IPv4CidrRange>} An array of two {@link IPv4CidrRange}
2700
+ */
2701
+ split() {
2702
+ let prefixToSplit = this.cidrPrefix.getValue();
2703
+ if (prefixToSplit === 32n) {
2704
+ throw new Error("Cannot split an IP range with a single IP number");
2705
+ }
2706
+ let splitCidr = Prefix_1$1.IPv4Prefix.fromNumber(prefixToSplit + 1n);
2707
+ let firstIPOfFirstRange = this.getFirst();
2708
+ let firstRange = new IPv4CidrRange(firstIPOfFirstRange, splitCidr);
2709
+ let firstIPOfSecondRange = firstRange.getLast().nextIPNumber();
2710
+ let secondRange = new IPv4CidrRange(firstIPOfSecondRange, splitCidr);
2711
+ return [firstRange, secondRange];
2712
+ }
2713
+ /**
2714
+ * Method that split prefix into ranges of the given prefix,
2715
+ * throws an exception if the size of the given prefix is larger than target prefix
2716
+ *
2717
+ * @param prefix the prefix to use to split
2718
+ * @returns {Array<IPv4CidrRange>} An array of two {@link IPv4CidrRange}
2719
+ */
2720
+ splitInto(prefix) {
2721
+ let splitCount = prefix.getValue() - this.cidrPrefix.getValue();
2722
+ if (splitCount < 0) {
2723
+ throw new Error("Prefix to split into is larger than source prefix");
2724
+ }
2725
+ else if (splitCount === 0n) {
2726
+ return [new IPv4CidrRange(this.getFirst(), prefix)];
2727
+ }
2728
+ else if (splitCount === 1n) {
2729
+ return this.split();
2730
+ }
2731
+ else {
2732
+ let results = this.split();
2733
+ while (splitCount > 1) {
2734
+ results = results.flatMap(result => result.split());
2735
+ splitCount = splitCount - 1n;
2736
+ }
2737
+ return results;
2738
+ }
2739
+ }
2740
+ /**
2741
+ * Returns true if there is an adjacent IPv4 cidr range of exactly the same size next to this range
2742
+ */
2743
+ hasNextRange() {
2744
+ return super.hasNextRange();
2745
+ }
2746
+ /**
2747
+ * Returns true if there is an adjacent IPv4 cidr range of exactly the same size previous to this range
2748
+ */
2749
+ hasPreviousRange() {
2750
+ return super.hasPreviousRange();
2751
+ }
2752
+ /**
2753
+ * Return the next IPv6 cidr range, or undefined if no next range
2754
+ */
2755
+ nextRange() {
2756
+ if (this.hasNextRange()) {
2757
+ let sizeOfCurrentRange = this.getSize();
2758
+ let startOfNextRange = this.getFirst().getValue() + (sizeOfCurrentRange);
2759
+ return new IPv4CidrRange(new IPNumber_1.IPv4(startOfNextRange), this.cidrPrefix);
2760
+ }
2761
+ return;
2762
+ }
2763
+ /**
2764
+ * Return the previous IPv6 cidr range, or undefined if no next range
2765
+ */
2766
+ previousRange() {
2767
+ if (this.hasPreviousRange()) {
2768
+ let sizeOfCurrentRange = this.getSize();
2769
+ let startOfPreviousRange = this.getFirst().getValue() - (sizeOfCurrentRange);
2770
+ return new IPv4CidrRange(new IPNumber_1.IPv4(startOfPreviousRange), this.cidrPrefix);
2771
+ }
2772
+ return;
2773
+ }
2774
+ }
2775
+ IPRange.IPv4CidrRange = IPv4CidrRange;
2776
+ /**
2777
+ * Represents a continuous segment of IPv6 number following the
2778
+ * classless inter-domain routing scheme for allocating IP addresses.
2779
+ *
2780
+ * @see https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
2781
+ */
2782
+ class IPv6CidrRange extends AbstractIPRange {
2783
+ /**
2784
+ * Constructor for creating an instance of an IPv6 range.
2785
+ *
2786
+ * The arguments taken by the constructor is inspired by the CIDR notation which basically consists of the IP
2787
+ * number and the prefix.
2788
+ *
2789
+ * @param {IPv6} ipv6 the IP number used to construct the range. By convention this is the first IP number in
2790
+ * the range, but it could also be any IP number within the range
2791
+ * @param {IPv6Prefix} cidrPrefix the prefix which is a representation of the number of bits used to mask the
2792
+ * given IPv6 number in other to create the range
2793
+ */
2794
+ constructor(ipv6, cidrPrefix) {
2795
+ super();
2796
+ this.ipv6 = ipv6;
2797
+ this.cidrPrefix = cidrPrefix;
2798
+ this.bitValue = 128n;
2799
+ }
2800
+ /**
2801
+ * Convenience method for constructing an instance of an IPV6Range from an IP range represented in CIDR notation
2802
+ *
2803
+ * @param {string} rangeInCidrNotation the range of the IPv6 number in CIDR notation
2804
+ * @returns {IPv6CidrRange} the IPV6Range
2805
+ */
2806
+ static fromCidr(rangeInCidrNotation) {
2807
+ let [isValid, message] = Validator_1.Validator.isValidIPv6CidrNotation(rangeInCidrNotation);
2808
+ if (!isValid) {
2809
+ throw new Error(message.filter(msg => { return msg !== ''; }).toString());
2810
+ }
2811
+ let cidrComponents = rangeInCidrNotation.split("/");
2812
+ let ipString = cidrComponents[0];
2813
+ let prefix = BigInt(parseInt(cidrComponents[1]));
2814
+ return new IPv6CidrRange(IPNumber_1.IPv6.fromHexadecatet(ipString), Prefix_1$1.IPv6Prefix.fromNumber(prefix));
2815
+ }
2816
+ ;
2817
+ /**
2818
+ * Gets the size of IPv6 numbers contained within the IPv6 range
2819
+ *
2820
+ * @returns {bigint} the amount of IPv6 numbers in the range
2821
+ */
2822
+ getSize() {
2823
+ return this.cidrPrefix.toRangeSize();
2824
+ }
2825
+ /**
2826
+ * Method that returns the IPv6 range in CIDR (Classless Inter-Domain Routing) notation.
2827
+ *
2828
+ * See {@link https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation} for more information
2829
+ * on the Classless Inter-Domain Routing notation
2830
+ *
2831
+ * @returns {string} the IPv6 range in CIDR (Classless Inter-Domain Routing) notation
2832
+ */
2833
+ toCidrString() {
2834
+ let first = this.ipv6.toString();
2835
+ return `${first.toString()}/${this.cidrPrefix.toString()}`;
2836
+ }
2837
+ /**
2838
+ * Method that returns the IPv6 range in string notation where the first IPv6 number and last IPv6 number are
2839
+ * separated by an hyphen. eg. "2001:db8:0:0:0:0:0:0-2001:db8:0:ffff:ffff:ffff:ffff:ffff"
2840
+ *
2841
+ * @returns {string} the range in [first IPv6 number] - [last IPv6 number] format
2842
+ */
2843
+ toRangeString() {
2844
+ return super.toRangeString();
2845
+ }
2846
+ /**
2847
+ * Method that returns the first IPv6 number in the IPv6 range
2848
+ *
2849
+ * @returns {IPv6} the first IPv6 number in the IPv6 range
2850
+ */
2851
+ getFirst() {
2852
+ return IPNumber_1.IPv6.fromBigInt(this.ipv6.getValue() & (this.cidrPrefix.toMask().getValue()));
2853
+ }
2854
+ /**
2855
+ * Method that returns the last IPv6 number in the IPv6 range
2856
+ *
2857
+ * @returns {IPv6} the last IPv6 number in the IPv6 range
2858
+ */
2859
+ getLast() {
2860
+ return last(this, this.ipv6);
2861
+ }
2862
+ newInstance(num, prefix) {
2863
+ return new IPv6CidrRange(num, prefix);
2864
+ }
2865
+ getPrefix() {
2866
+ return this.cidrPrefix;
2867
+ }
2868
+ /**
2869
+ * Indicates whether the given IPv6 range is an adjacent range.
2870
+ *
2871
+ * An adjacent range being one where the end of the given range, when incremented by one marks the start of the
2872
+ * other range. Or where the start of the given range, when decreased by one, marks the end of the other range
2873
+ *
2874
+ * @param {IPv6CidrRange} otherRange the other IPv6 range to compare with
2875
+ * @returns {boolean} true if the two IPv6 ranges are consecutive, false otherwise
2876
+ */
2877
+ isConsecutive(otherRange) {
2878
+ return super.isConsecutive(otherRange);
2879
+ }
2880
+ /**
2881
+ * Indicates if the given IPv6 range is a subset.
2882
+ *
2883
+ * By a subset range, it means all the values of the given range are contained by this IPv6 range
2884
+ *
2885
+ * @param {IPv6CidrRange} otherRange the other IPv6 range
2886
+ * @returns {boolean} true if the other Ipv6 range is a subset. False otherwise.
2887
+ */
2888
+ contains(otherRange) {
2889
+ return super.contains(otherRange);
2890
+ }
2891
+ /**
2892
+ * Indicate if the given range is a container range.
2893
+ *
2894
+ * By container range, it means all the IP number in this current range can be found within the given range.
2895
+ *
2896
+ * @param {IPv6CidrRange} otherRange he other IPv6 range
2897
+ * @returns {boolean} true if the other Ipv6 range is a container range. False otherwise.
2898
+ */
2899
+ inside(otherRange) {
2900
+ return super.inside(otherRange);
2901
+ }
2902
+ /**
2903
+ * Checks if two IPv6 ranges overlap
2904
+ * @param {IPv6CidrRange} otherRange the other IPv6 range
2905
+ * @returns {boolean} true if the ranges overlap, false otherwise
2906
+ */
2907
+ isOverlapping(otherRange) {
2908
+ return super.isOverlapping(otherRange);
2909
+ }
2910
+ /**
2911
+ * Method that takes IPv6 number from within an IPv6 range, starting from the first IPv6 number
2912
+ *
2913
+ * @param {bigint} count the amount of IPv6 number to take from the IPv6 range
2914
+ * @returns {Array<IPv6>} an array of IPv6 number, taken from the IPv6 range
2915
+ */
2916
+ take(count) {
2917
+ let iPv6s = [this.getFirst()];
2918
+ let iteratingIPv6 = this.getFirst();
2919
+ if (count > (this.getSize())) {
2920
+ throw new Error(`${count.toString()} is greater than ${this.getSize().toString()}, the size of the range`);
2921
+ }
2922
+ for (var counter = 0; counter < count - 1n; counter++) {
2923
+ iPv6s.push(iteratingIPv6.nextIPNumber());
2924
+ iteratingIPv6 = iteratingIPv6.nextIPNumber();
2925
+ }
2926
+ return iPv6s;
2927
+ }
2928
+ /**
2929
+ * Method that splits an IPv6 cidr range into two halves
2930
+ *
2931
+ * @returns {Array<IPv6CidrRange>} An array of two {@link IPv6CidrRange}
2932
+ */
2933
+ split() {
2934
+ let prefixToSplit = this.cidrPrefix.getValue();
2935
+ if (prefixToSplit === 128n) {
2936
+ throw new Error("Cannot split an IP range with a single IP number");
2937
+ }
2938
+ let splitCidr = Prefix_1$1.IPv6Prefix.fromNumber(prefixToSplit + 1n);
2939
+ let firstIPOfFirstRange = this.getFirst();
2940
+ let firstRange = new IPv6CidrRange(firstIPOfFirstRange, splitCidr);
2941
+ let firstIPOfSecondRange = firstRange.getLast().nextIPNumber();
2942
+ let secondRange = new IPv6CidrRange(firstIPOfSecondRange, splitCidr);
2943
+ return [firstRange, secondRange];
2944
+ }
2945
+ /**
2946
+ * Method that split prefix into ranges of the given prefix,
2947
+ * throws an exception if the size of the given prefix is larger than target prefix
2948
+ *
2949
+ * @param prefix the prefix to use to split
2950
+ * @returns {Array<IPv6CidrRange>} An array of two {@link IPv6CidrRange}
2951
+ */
2952
+ splitInto(prefix) {
2953
+ let splitCount = prefix.getValue() - this.cidrPrefix.getValue();
2954
+ if (splitCount < 0) {
2955
+ throw new Error("Prefix to split into is larger than source prefix");
2956
+ }
2957
+ else if (splitCount === 0n) {
2958
+ return [new IPv6CidrRange(this.getFirst(), prefix)];
2959
+ }
2960
+ else if (splitCount === 1n) {
2961
+ return this.split();
2962
+ }
2963
+ else {
2964
+ let results = this.split();
2965
+ while (splitCount > 1) {
2966
+ results = results.flatMap(result => result.split());
2967
+ splitCount = splitCount - 1n;
2968
+ }
2969
+ return results;
2970
+ }
2971
+ }
2972
+ /**
2973
+ * Returns true if there is an adjacent IPv6 cidr range of exactly the same size next to this range
2974
+ */
2975
+ hasNextRange() {
2976
+ return super.hasNextRange();
2977
+ }
2978
+ /**
2979
+ * Returns true if there is an adjacent IPv6 cidr range of exactly the same size previous to this range
2980
+ */
2981
+ hasPreviousRange() {
2982
+ return super.hasPreviousRange();
2983
+ }
2984
+ /**
2985
+ * Return the next IPv6 cidr range, or undefined if no next range
2986
+ */
2987
+ nextRange() {
2988
+ if (this.hasNextRange()) {
2989
+ let sizeOfCurrentRange = this.getSize();
2990
+ let startOfNextRange = this.getFirst().getValue() + (sizeOfCurrentRange);
2991
+ return new IPv6CidrRange(new IPNumber_1.IPv6(startOfNextRange), this.cidrPrefix);
2992
+ }
2993
+ return;
2994
+ }
2995
+ /**
2996
+ * Return the previous IPv6 cidr range, or undefined if no next range
2997
+ */
2998
+ previousRange() {
2999
+ if (this.hasPreviousRange()) {
3000
+ let sizeOfCurrentRange = this.getSize();
3001
+ let startOfPreviousRange = this.getFirst().getValue() - sizeOfCurrentRange;
3002
+ return new IPv6CidrRange(new IPNumber_1.IPv6(startOfPreviousRange), this.cidrPrefix);
3003
+ }
3004
+ return;
3005
+ }
3006
+ }
3007
+ IPRange.IPv6CidrRange = IPv6CidrRange;
3008
+ // utility functions shared by both IPv6CidrRange and IPv4CidrRange
3009
+ let last = (range, ip) => {
3010
+ let bitValue = Number(range.bitValue.valueOf());
3011
+ let maskSize = BigInt(`0b${"1".repeat(bitValue)}`);
3012
+ let maskAsBigInteger = range.cidrPrefix.toMask().getValue();
3013
+ let invertedMask = BinaryUtils_1.leftPadWithZeroBit((maskAsBigInteger ^ (maskSize)).toString(2), bitValue);
3014
+ if (isIPv4CidrRange(range)) {
3015
+ return IPNumber_1.IPv4.fromNumber((ip.getValue()) | (BinaryUtils_1.parseBinaryStringToBigInt(invertedMask)));
3016
+ }
3017
+ else {
3018
+ return IPNumber_1.IPv6.fromBigInt((ip.getValue()) | (BinaryUtils_1.parseBinaryStringToBigInt(invertedMask)));
3019
+ }
3020
+ };
3021
+ function isIPv4CidrRange(ip) {
3022
+ return ip.bitValue.valueOf() === 32n;
3023
+ }
3024
+ IPRange.isIPv4CidrRange = isIPv4CidrRange;
3025
+
3026
+ Object.defineProperty(IPPool, "__esModule", { value: true });
3027
+ IPPool.Pool = void 0;
3028
+ const IPRange_1 = IPRange;
3029
+ const Prefix_1 = Prefix;
3030
+ /**
3031
+ * Represents a collection of IP {@link RangedSet}'s
3032
+ */
3033
+ class Pool {
3034
+ /**
3035
+ * Constructor for an IP pool.
3036
+ *
3037
+ * Creates a Pool of IP ranges from supplied {@link RangedSet}'s
3038
+ *
3039
+ * @param ranges the array of IP ranges that would make up the pool.
3040
+ */
3041
+ constructor(ranges) {
3042
+ this.backingSet = new SortedSet();
3043
+ ranges.forEach(range => {
3044
+ this.backingSet.add(range);
3045
+ });
3046
+ }
3047
+ /**
3048
+ * Convenient method for creating an instance from arrays of {@link IPv4} or {@link IPv6}
3049
+ * @param ipNumbers the arrays of {@link IPv4} or {@link IPv6} that will make up the pool.
3050
+ */
3051
+ static fromIP(ipNumbers) {
3052
+ let ranges = ipNumbers.map((ip) => {
3053
+ return IPRange_1.RangedSet.fromSingleIP(ip);
3054
+ });
3055
+ return new Pool(ranges);
3056
+ }
3057
+ /**
3058
+ * Convenient method for creating an instance from arrays of {@link RangedSet}.
3059
+ *
3060
+ * @param ipRanges the arrays of {@link RangedSet}'s that will make up the pool.
3061
+ */
3062
+ // TODO: TSE: This makes it possible to create an instance containing both Range set of IPv4 and IPv6
3063
+ static fromRangeSet(ipRanges) {
3064
+ return new Pool(ipRanges);
3065
+ }
3066
+ /**
3067
+ * Convenient method for creating an instance from arrays of {@link IPv4CidrRange} or {@link IPv6CidrRange}.
3068
+ *
3069
+ * @param cidrRanges the arrays of {@link IPv4CidrRange} or {@link IPv6CidrRange} that will make up the pool.
3070
+ */
3071
+ static fromCidrRanges(cidrRanges) {
3072
+ let cidr = cidrRanges;
3073
+ let rangeSet = cidr.map((range) => {
3074
+ return range.toRangeSet();
3075
+ });
3076
+ return new Pool(rangeSet);
3077
+ }
3078
+ /**
3079
+ * Returns an array of {@link RangedSet}'s that is contained within the pool
3080
+ */
3081
+ getRanges() {
3082
+ return this.backingSet.asArray();
3083
+ }
3084
+ /**
3085
+ * Returns an new {@link Pool} with all the IP ranges aggregated
3086
+ */
3087
+ aggregate() {
3088
+ let sortedRanges = this.backingSet.asArray();
3089
+ let mergedRanges = sortedRanges.reduce((accumulator, currentRange, currentIndex, array) => {
3090
+ if (accumulator.length == 0) {
3091
+ accumulator.push(currentRange);
3092
+ return accumulator;
3093
+ }
3094
+ else {
3095
+ let previous = accumulator.pop();
3096
+ let previousCidrRange = previous.toCidrRange();
3097
+ let currentCidrRange = currentRange.toCidrRange();
3098
+ if (previousCidrRange.isCidrMergeable(currentCidrRange)) {
3099
+ let merged = previousCidrRange.merge(currentCidrRange);
3100
+ accumulator.push(merged.toRangeSet());
3101
+ return accumulator;
3102
+ }
3103
+ else {
3104
+ if (!previous.contains(currentRange)) {
3105
+ accumulator.push(previous);
3106
+ accumulator.push(currentRange);
3107
+ }
3108
+ else {
3109
+ accumulator.push(previous);
3110
+ }
3111
+ return accumulator;
3112
+ }
3113
+ }
3114
+ }, []);
3115
+ let aggregatedPool = Pool.fromRangeSet(mergedRanges);
3116
+ if (aggregatedPool.getRanges().length !== this.getRanges().length) {
3117
+ return aggregatedPool.aggregate();
3118
+ }
3119
+ else {
3120
+ return aggregatedPool;
3121
+ }
3122
+ }
3123
+ /**
3124
+ * Gets a single range of size of the given prefix from pool.
3125
+ * Only returns a range if there is a single range in the pool of same size or greater than given prefix.
3126
+ *
3127
+ * throws exception if the requested range cannot be got from the pool.
3128
+ *
3129
+ * @param prefix prefix range to retrieve
3130
+ * TODO TSE
3131
+ */
3132
+ getCidrRange(prefix) {
3133
+ if (prefix.toRangeSize() > (this.getSize())) {
3134
+ throw new Error(`Not enough IP number in the pool for requested prefix: ${prefix}`);
3135
+ }
3136
+ let selectedCidrRange;
3137
+ let error;
3138
+ loop: for (let range of this.getRanges()) {
3139
+ for (let offset = 0n; offset + (prefix.toRangeSize()) <= (range.getSize()); offset = offset + 1n)
3140
+ try {
3141
+ let selectedRange = range.takeSubRange(offset, prefix.toRangeSize());
3142
+ selectedCidrRange = selectedRange.toCidrRange();
3143
+ let remaining = range.difference(selectedRange);
3144
+ this.removeExact(range);
3145
+ this.add(remaining);
3146
+ break loop;
3147
+ }
3148
+ catch (e) {
3149
+ if (e instanceof RangeError) {
3150
+ continue loop;
3151
+ }
3152
+ error = e;
3153
+ }
3154
+ }
3155
+ if (selectedCidrRange) {
3156
+ return selectedCidrRange;
3157
+ }
3158
+ else {
3159
+ throw (error === undefined ? new Error(`No range big enough in the pool for requested prefix: ${prefix}`) : error);
3160
+ }
3161
+ }
3162
+ /**
3163
+ * Gets a single or multiple ranges that fulfils the given prefix from the pool.
3164
+ *
3165
+ * throws exception if the requested range cannot be got from the pool.
3166
+ *
3167
+ * @param reqprefix prefix range to retrieve
3168
+ */
3169
+ getCidrRanges(reqprefix) {
3170
+ if (reqprefix.toRangeSize() > (this.getSize())) {
3171
+ throw new Error("Prefix greater than pool");
3172
+ }
3173
+ let go = (reqprefix, prefix, accummulated) => {
3174
+ try {
3175
+ let singleCidrRange = this.getCidrRange(prefix);
3176
+ accummulated.push(singleCidrRange);
3177
+ let currentSize = accummulated.reduce((previous, current) => {
3178
+ return previous + (current.getSize());
3179
+ }, 0n);
3180
+ if (reqprefix.toRangeSize() === (currentSize)) {
3181
+ return accummulated;
3182
+ }
3183
+ else {
3184
+ return go(reqprefix, prefix, accummulated);
3185
+ }
3186
+ }
3187
+ catch (e) {
3188
+ let lowerPrefix = Prefix_1.isIPv4Prefix(prefix) ?
3189
+ Prefix_1.IPv4Prefix.fromNumber(prefix.getValue() + 1n) : Prefix_1.IPv6Prefix.fromNumber(prefix.getValue() + 1n);
3190
+ return go(reqprefix, lowerPrefix, accummulated);
3191
+ }
3192
+ };
3193
+ return go(reqprefix, reqprefix, []);
3194
+ }
3195
+ /**
3196
+ * Returns the size of IP numbers in the pool
3197
+ */
3198
+ getSize() {
3199
+ return this
3200
+ .aggregate()
3201
+ .getRanges()
3202
+ .reduce((previous, current) => {
3203
+ return previous + current.getSize();
3204
+ }, 0n);
3205
+ }
3206
+ /**
3207
+ * Empties the pool and fill it with given ranges
3208
+ *
3209
+ * @param ipRanges the range to fill the pool with after emptying
3210
+ */
3211
+ resetWith(ipRanges) {
3212
+ this.backingSet.clear();
3213
+ this.backingSet = this.backingSet.add(ipRanges);
3214
+ }
3215
+ /**
3216
+ * Removes the given range from the pool. It only removes if the exact range exist in the pool.
3217
+ * It is a Noop and returns false, if the given range does not exist in the pool. Returns true otherwise
3218
+ *
3219
+ * @param rangeToRemove range to remove from ppol
3220
+ */
3221
+ removeExact(rangeToRemove) {
3222
+ let updatedSet = this.backingSet.removeExact(rangeToRemove);
3223
+ let isUpdated = !this.backingSet.isEquals(updatedSet);
3224
+ this.backingSet = updatedSet;
3225
+ return isUpdated;
3226
+ }
3227
+ /**
3228
+ * Removes the given range from the pool. If the given range overlaps, then it removes the overlapping portion.
3229
+ * It is a Noop and returns false, if the given range does not exist in the pool. Returns true otherwise
3230
+ *
3231
+ * @param rangeToRemove range to remove from ppol
3232
+ */
3233
+ removeOverlapping(rangeToRemove) {
3234
+ let updatedSet = this.backingSet.removeOverlapping(rangeToRemove);
3235
+ let isUpdated = !this.backingSet.isEquals(updatedSet);
3236
+ this.backingSet = updatedSet;
3237
+ return isUpdated;
3238
+ }
3239
+ /**
3240
+ * Adds the given range to the pool.
3241
+ *
3242
+ * @param range to add to pool.
3243
+ */
3244
+ add(range) {
3245
+ this.backingSet = this.backingSet.add(range);
3246
+ }
3247
+ /**
3248
+ * Removes all ranges from pool
3249
+ */
3250
+ clear() {
3251
+ this.backingSet.clear();
3252
+ }
3253
+ }
3254
+ IPPool.Pool = Pool;
3255
+ class SortedSet {
3256
+ constructor(array) {
3257
+ if (array) {
3258
+ this.backingArray = this.sortArray(array);
3259
+ }
3260
+ else {
3261
+ this.backingArray = new Array();
3262
+ }
3263
+ }
3264
+ sortArray(array) {
3265
+ array.sort((a, b) => {
3266
+ if (a.isLessThan(b)) {
3267
+ return -1;
3268
+ }
3269
+ if (a.isGreaterThan(b)) {
3270
+ return 1;
3271
+ }
3272
+ return 0;
3273
+ });
3274
+ return array;
3275
+ }
3276
+ asArray() {
3277
+ return this.backingArray;
3278
+ }
3279
+ isEquals(other) {
3280
+ if (this.backingArray.length !== other.asArray().length) {
3281
+ return false;
3282
+ }
3283
+ return this.backingArray.every((value, index) => {
3284
+ return value.getSize() === (other.asArray()[index].getSize());
3285
+ });
3286
+ }
3287
+ add(item) {
3288
+ let array = this.backingArray;
3289
+ if ("push" in item) {
3290
+ array = array.concat(item);
3291
+ }
3292
+ else {
3293
+ array.push(item);
3294
+ }
3295
+ return new SortedSet(this.sortArray(array));
3296
+ }
3297
+ removeExact(items) {
3298
+ let filtered = this.backingArray
3299
+ .filter(currentItem => {
3300
+ if ("push" in items) {
3301
+ return items.find(item => item.isEquals(currentItem)) !== undefined;
3302
+ }
3303
+ else {
3304
+ return !items.isEquals(currentItem);
3305
+ }
3306
+ });
3307
+ return new SortedSet(this.sortArray(filtered));
3308
+ }
3309
+ removeOverlapping(items) {
3310
+ let filtered = this.backingArray
3311
+ .flatMap(backingItem => {
3312
+ if ("push" in items) {
3313
+ return items.flatMap(item => {
3314
+ if (backingItem.contains(item)) {
3315
+ return backingItem.difference(item);
3316
+ }
3317
+ else if (backingItem.inside(item)) {
3318
+ return new Array();
3319
+ }
3320
+ else if (backingItem.isOverlapping(item)) {
3321
+ return [backingItem.subtract(item)];
3322
+ }
3323
+ else {
3324
+ return [item];
3325
+ }
3326
+ });
3327
+ }
3328
+ else {
3329
+ try {
3330
+ return backingItem.difference(items);
3331
+ }
3332
+ catch (e) {
3333
+ return backingItem;
3334
+ }
3335
+ }
3336
+ });
3337
+ return new SortedSet(this.sortArray(filtered));
3338
+ }
3339
+ clear() {
3340
+ this.backingArray = [];
3341
+ }
3342
+ }
3343
+
3344
+ (function (exports) {
3345
+ var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3346
+ if (k2 === undefined) k2 = k;
3347
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
3348
+ }) : (function(o, m, k, k2) {
3349
+ if (k2 === undefined) k2 = k;
3350
+ o[k2] = m[k];
3351
+ }));
3352
+ var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
3353
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
3354
+ };
3355
+ Object.defineProperty(exports, "__esModule", { value: true });
3356
+ /**
3357
+ * Exposes all the library's modules making them available from the "ip-num" module.
3358
+ * Making it possible to get access to all any of the modules by doing require("ip-num")
3359
+ *
3360
+ * @example
3361
+ * let ipNum = require("ip-num")
3362
+ * ipNum.IPv4CidrRange // gets access to IPv4CidrRange
3363
+ * ipNum.Asn // gets access to Asn
3364
+ */
3365
+ __exportStar(BinaryUtils, exports);
3366
+ __exportStar(Hexadecatet$1, exports);
3367
+ __exportStar(requireHexadecimalUtils(), exports);
3368
+ __exportStar(IPNumber, exports);
3369
+ __exportStar(IPNumType, exports);
3370
+ __exportStar(IPPool, exports);
3371
+ __exportStar(IPRange, exports);
3372
+ __exportStar(requireIPv6Utils(), exports);
3373
+ __exportStar(Octet$1, exports);
3374
+ __exportStar(Prefix, exports);
3375
+ __exportStar(requireValidator(), exports);
3376
+
3377
+ } (ipNum));
3378
+
3379
+ var isValidIPv4String = function isValidIPv4String(ip) {
3380
+ return ramda.isNotNil(ip) && ipNum.Validator.isValidIPv4String(ip)[0];
3381
+ };
3382
+ var isValidIPv6String = function isValidIPv6String(ip) {
3383
+ return ramda.isNotNil(ip) && ipNum.Validator.isValidIPv6String(ip)[0];
3384
+ };
3385
+ var isValidIpString = function isValidIpString(ip) {
3386
+ return isValidIPv4String(ip) || isValidIPv6String(ip);
3387
+ };
3388
+ var areIpAddressesInSameFormat = function areIpAddressesInSameFormat(ipStart, ipEnd) {
3389
+ return isValidIPv4String(ipStart) && isValidIPv4String(ipEnd) || isValidIPv6String(ipStart) && isValidIPv6String(ipEnd);
3390
+ };
3391
+ var isValidIPv4Range = function isValidIPv4Range(ipStart, ipEnd) {
3392
+ var ipStartAddr = ipNum.IPv4.fromDecimalDottedString(ipStart);
3393
+ var ipEndAddr = ipNum.IPv4.fromDecimalDottedString(ipEnd);
3394
+ return ipStartAddr.isLessThanOrEquals(ipEndAddr);
3395
+ };
3396
+ var isValidIPv6Range = function isValidIPv6Range(ipStart, ipEnd) {
3397
+ var ipStartAddr = ipNum.IPv6.fromString(ipStart);
3398
+ var ipEndAddr = ipNum.IPv6.fromString(ipEnd);
3399
+ return ipStartAddr.isLessThanOrEquals(ipEndAddr);
3400
+ };
3401
+ var isValidIPRange = function isValidIPRange(ipStart, ipEnd) {
3402
+ if (isValidIPv4String(ipStart) && isValidIPv4String(ipEnd)) {
3403
+ return isValidIPv4Range(ipStart, ipEnd);
3404
+ }
3405
+ if (isValidIPv6String(ipStart) && isValidIPv6String(ipEnd)) {
3406
+ return isValidIPv6Range(ipStart, ipEnd);
3407
+ }
3408
+ return false;
3409
+ };
3410
+ yup__namespace.addMethod(yup__namespace.string, "validIp", function (errorMessage) {
3411
+ return this.test("valid-ip", errorMessage, function (value) {
3412
+ if (ramda.isNil(value)) {
3413
+ return this;
3414
+ }
3415
+ var isValidIp = isValidIpString(value);
3416
+ return isValidIp || this.createError({
3417
+ path: this.path,
3418
+ message: errorMessage
3419
+ });
3420
+ });
3421
+ });
3422
+ var getIpRestrictionValidationSchema = function getIpRestrictionValidationSchema() {
3423
+ return yup__namespace.object().shape({
3424
+ ipStart: yup__namespace.string().validIp(i18next.t("neetoMolecules.ipRestriction.validations.invalidIp")).required(i18next.t("neetoMolecules.ipRestriction.validations.ipStartRequired")),
3425
+ ipEnd: yup__namespace.string().validIp(i18next.t("neetoMolecules.ipRestriction.validations.invalidIp")).when("ipStart", function (ipStart, schema) {
3426
+ return schema.test({
3427
+ test: function test(ipEnd) {
3428
+ return areIpAddressesInSameFormat(ipStart, ipEnd);
3429
+ },
3430
+ message: i18next.t("neetoMolecules.ipRestriction.validations.eitherIpv4OrIpv6")
3431
+ });
3432
+ }).when("ipStart", function (ipStart, schema) {
3433
+ return schema.test({
3434
+ test: function test(ipEnd) {
3435
+ return isValidIPRange(ipStart, ipEnd);
3436
+ },
3437
+ message: i18next.t("neetoMolecules.ipRestriction.validations.ipEndGreaterThanIpStart")
3438
+ });
3439
+ }).required(i18next.t("neetoMolecules.ipRestriction.validations.ipEndRequired"))
3440
+ });
3441
+ };
3442
+
3443
+ var FormRow = function FormRow(_ref) {
3444
+ var data = _ref.data,
3445
+ isAddNew = _ref.isAddNew,
3446
+ onCollapse = _ref.onCollapse;
3447
+ var _useCreateAllowedIpRa = useCreateAllowedIpRanges(),
3448
+ createAllowedIpRange = _useCreateAllowedIpRa.mutate;
3449
+ var _useUpdateAllowedIpRa = useUpdateAllowedIpRanges(),
3450
+ updateAllowedIpRange = _useUpdateAllowedIpRa.mutate;
3451
+ var _useTranslation = reactI18next.useTranslation(),
3452
+ t = _useTranslation.t;
3453
+ var handleSubmit = function handleSubmit(values) {
3454
+ if (isAddNew) {
3455
+ createAllowedIpRange(values);
3456
+ } else {
3457
+ updateAllowedIpRange({
3458
+ id: data.id,
3459
+ payload: values
3460
+ });
3461
+ }
3462
+ onCollapse();
3463
+ };
3464
+ return /*#__PURE__*/React__default["default"].createElement(formik.Form, {
3465
+ "data-cy": "allowed-ip-range-form",
3466
+ formikProps: {
3467
+ initialValues: data,
3468
+ validationSchema: getIpRestrictionValidationSchema(),
3469
+ onSubmit: handleSubmit
3470
+ }
3471
+ }, function (_ref2) {
3472
+ var isSubmitting = _ref2.isSubmitting;
3473
+ return /*#__PURE__*/React__default["default"].createElement("div", {
3474
+ className: "neeto-ui-bg-white flex w-full flex-row justify-between px-2 py-2"
3475
+ }, /*#__PURE__*/React__default["default"].createElement(formik.Input, {
3476
+ autoFocus: true,
3477
+ className: "w-5/12 flex-grow px-3 py-2 text-left",
3478
+ "data-cy": "ip-start-text-field",
3479
+ name: "ipStart",
3480
+ placeholder: t("neetoMolecules.ipRestriction.ipStart")
3481
+ }), /*#__PURE__*/React__default["default"].createElement(formik.Input, {
3482
+ className: "w-5/12 flex-grow px-3 py-2 text-left",
3483
+ "data-cy": "ip-end-text-field",
3484
+ name: "ipEnd",
3485
+ placeholder: t("neetoMolecules.ipRestriction.ipEnd")
3486
+ }), /*#__PURE__*/React__default["default"].createElement("div", {
3487
+ className: "w-5/12 flex-grow px-3 py-2 text-center"
3488
+ }, /*#__PURE__*/React__default["default"].createElement(formik.Button, {
3489
+ "data-cy": "save-changes-button",
3490
+ disabled: isSubmitting,
3491
+ icon: neetoIcons.Check,
3492
+ style: "text",
3493
+ tooltipProps: {
3494
+ content: "Submit",
3495
+ position: "top"
3496
+ },
3497
+ type: "submit"
3498
+ }), /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
3499
+ "data-cy": "ip-cancel-button",
3500
+ icon: neetoIcons.Close,
3501
+ style: "text",
3502
+ type: "reset",
3503
+ tooltipProps: {
3504
+ content: t("neetoMolecules.common.actions.cancel"),
3505
+ position: "top"
3506
+ },
3507
+ onClick: onCollapse
3508
+ })));
3509
+ });
3510
+ };
3511
+
3512
+ var Menu = neetoui.Dropdown.Menu,
3513
+ MenuItem = neetoui.Dropdown.MenuItem;
3514
+ var Row = function Row(_ref) {
3515
+ var data = _ref.data,
3516
+ setEditingRow = _ref.setEditingRow;
3517
+ var _useState = React.useState(false),
3518
+ _useState2 = _slicedToArray(_useState, 2),
3519
+ isDeleteIpRangeAlertOpen = _useState2[0],
3520
+ setIsDeleteIpRangeAlertOpen = _useState2[1];
3521
+ var _useDestroyAllowedIpR = useDestroyAllowedIpRanges(),
3522
+ destroyAllowedIpRange = _useDestroyAllowedIpR.mutate;
3523
+ var _useTranslation = reactI18next.useTranslation(),
3524
+ t = _useTranslation.t;
3525
+ var handleDelete = function handleDelete() {
3526
+ destroyAllowedIpRange(data.id);
3527
+ setIsDeleteIpRangeAlertOpen(false);
3528
+ };
3529
+ return /*#__PURE__*/React__default["default"].createElement("div", {
3530
+ className: "neeto-ui-bg-white flex w-full flex-row justify-between px-1 py-2",
3531
+ "data-cy": "ip-range-row"
3532
+ }, /*#__PURE__*/React__default["default"].createElement(neetoui.Tooltip, {
3533
+ content: data.ipStart,
3534
+ disabled: data.ipStart.length < TRUNCATE_LENGTH,
3535
+ position: "top"
3536
+ }, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
3537
+ className: "flex w-4/12 flex-grow items-center px-3 py-2 text-left",
3538
+ "data-cy": "ip-range-start-value",
3539
+ style: "body2"
3540
+ }, pure.truncate(data.ipStart, TRUNCATE_LENGTH))), /*#__PURE__*/React__default["default"].createElement(neetoui.Tooltip, {
3541
+ content: data.ipEnd,
3542
+ disabled: data.ipEnd.length < TRUNCATE_LENGTH,
3543
+ position: "top"
3544
+ }, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
3545
+ className: "flex w-4/12 flex-grow items-center px-3 py-2 text-left",
3546
+ "data-cy": "ip-range-end-value",
3547
+ style: "body2"
3548
+ }, pure.truncate(data.ipEnd, TRUNCATE_LENGTH))), /*#__PURE__*/React__default["default"].createElement("div", {
3549
+ className: "w-4/12 flex-grow px-3 py-2 text-center"
3550
+ }, /*#__PURE__*/React__default["default"].createElement(neetoui.Dropdown, {
3551
+ buttonStyle: "text",
3552
+ icon: neetoIcons.MenuVertical,
3553
+ position: "bottom-end"
3554
+ }, /*#__PURE__*/React__default["default"].createElement(Menu, null, /*#__PURE__*/React__default["default"].createElement(MenuItem.Button, {
3555
+ "data-cy": "ip-range-edit-button",
3556
+ onClick: function onClick() {
3557
+ return setEditingRow(data.id);
3558
+ }
3559
+ }, t("neetoMolecules.common.actions.edit")), /*#__PURE__*/React__default["default"].createElement(MenuItem.Button, {
3560
+ "data-cy": "ip-range-delete-button",
3561
+ onClick: function onClick() {
3562
+ return setIsDeleteIpRangeAlertOpen(true);
3563
+ }
3564
+ }, t("neetoMolecules.common.actions.delete")))), /*#__PURE__*/React__default["default"].createElement(neetoui.Alert, {
3565
+ isOpen: isDeleteIpRangeAlertOpen,
3566
+ submitButtonLabel: t("neetoMolecules.common.actions.delete"),
3567
+ message: /*#__PURE__*/React__default["default"].createElement(reactI18next.Trans, {
3568
+ i18nKey: "neetoMolecules.ipRestriction.allowedIpRangeConfirmation",
3569
+ values: {
3570
+ ipStart: data.ipStart,
3571
+ ipEnd: data.ipEnd
3572
+ }
3573
+ }),
3574
+ title: t("neetoMolecules.common.deleteAlert.title", {
3575
+ entity: t("neetoMolecules.ipRestriction.allowedIpRangeConfirmationTitle")
3576
+ }),
3577
+ onClose: function onClose() {
3578
+ return setIsDeleteIpRangeAlertOpen(false);
3579
+ },
3580
+ onSubmit: handleDelete
3581
+ })));
3582
+ };
3583
+ var Row$1 = /*#__PURE__*/React__default["default"].memo(Row);
3584
+
3585
+ var AllowedIpRanges = function AllowedIpRanges() {
3586
+ var _useState = React.useState(""),
3587
+ _useState2 = _slicedToArray(_useState, 2),
3588
+ editingRow = _useState2[0],
3589
+ setEditingRow = _useState2[1];
3590
+ var _useState3 = React.useState(false),
3591
+ _useState4 = _slicedToArray(_useState3, 2),
3592
+ showAddNew = _useState4[0],
3593
+ setShowAddNew = _useState4[1];
3594
+ var _useTranslation = reactI18next.useTranslation(),
3595
+ t = _useTranslation.t;
3596
+ var _useFetchAllowedIpRan = useFetchAllowedIpRanges(),
3597
+ allowedIpRanges = _useFetchAllowedIpRan.data;
3598
+ return /*#__PURE__*/React__default["default"].createElement("div", {
3599
+ className: "space-y-4",
3600
+ "data-cy": "allowed-ip-range-container"
3601
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
3602
+ className: "flex flex-row items-center"
3603
+ }, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
3604
+ "data-cy": "allowed-ip-range-heading",
3605
+ style: "h3"
3606
+ }, t("neetoMolecules.ipRestriction.allowedIpRangeTitle")), /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
3607
+ className: "ml-2",
3608
+ "data-cy": "add-allowed-ip-range-button",
3609
+ disabled: showAddNew,
3610
+ icon: neetoIcons.Plus,
3611
+ size: "small",
3612
+ tooltipProps: {
3613
+ content: "Add",
3614
+ position: "top"
3615
+ },
3616
+ onClick: function onClick() {
3617
+ return setShowAddNew(true);
3618
+ }
3619
+ })), /*#__PURE__*/React__default["default"].createElement("div", {
3620
+ className: "neeto-ui-text-gray-500 flex w-full flex-row justify-between"
3621
+ }, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
3622
+ className: "w-4/12 flex-grow px-3 py-2 text-left"
3623
+ }, t("neetoMolecules.ipRestriction.ipStart")), /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
3624
+ className: "w-4/12 flex-grow px-3 py-2 text-left"
3625
+ }, t("neetoMolecules.ipRestriction.ipEnd")), /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
3626
+ className: "w-4/12 flex-grow px-3 py-2 text-center"
3627
+ }, t("neetoMolecules.ipRestriction.actions"))), /*#__PURE__*/React__default["default"].createElement("div", {
3628
+ className: "items-between flex w-full flex-col space-y-2"
3629
+ }, showAddNew && /*#__PURE__*/React__default["default"].createElement(FormRow, {
3630
+ isAddNew: true,
3631
+ data: INITIAL_VALUES,
3632
+ onCollapse: function onCollapse() {
3633
+ return setShowAddNew(false);
3634
+ }
3635
+ }), allowedIpRanges === null || allowedIpRanges === void 0 ? void 0 : allowedIpRanges.map(function (allowedIpRange) {
3636
+ return editingRow === allowedIpRange.id ? /*#__PURE__*/React__default["default"].createElement(FormRow, {
3637
+ data: allowedIpRange,
3638
+ isAddNew: false,
3639
+ key: allowedIpRange.id,
3640
+ onCollapse: function onCollapse() {
3641
+ return setEditingRow("");
3642
+ }
3643
+ }) : /*#__PURE__*/React__default["default"].createElement(Row$1, {
3644
+ data: allowedIpRange,
3645
+ key: allowedIpRange.id,
3646
+ setEditingRow: setEditingRow
3647
+ });
3648
+ })));
3649
+ };
3650
+ var AllowedIpRanges$1 = /*#__PURE__*/React__default["default"].memo(AllowedIpRanges);
3651
+
3652
+ var show$1 = function show(params) {
3653
+ return axios__default["default"].get("".concat(IP_RESTRICTIONS_ENGINE_BASE_URL, "/current_ip"), {
3654
+ params: params
3655
+ });
3656
+ };
3657
+ var currentIpApi = {
3658
+ show: show$1
3659
+ };
3660
+
3661
+ var CURRENT_IP = QUERY_KEYS.CURRENT_IP;
3662
+ var useShowCurrentIp = function useShowCurrentIp() {
3663
+ return reactQuery.useQuery([CURRENT_IP], function () {
3664
+ return currentIpApi.show();
3665
+ });
3666
+ };
3667
+
3668
+ var CurrentIp = function CurrentIp() {
3669
+ var _useShowCurrentIp = useShowCurrentIp(),
3670
+ data = _useShowCurrentIp.data,
3671
+ isLoading = _useShowCurrentIp.isLoading;
3672
+ var _useTranslation = reactI18next.useTranslation(),
3673
+ t = _useTranslation.t;
3674
+ return /*#__PURE__*/React__default["default"].createElement("div", {
3675
+ className: "space-y-1",
3676
+ "data-cy": "current-ip-container"
3677
+ }, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
3678
+ "data-cy": "current-ip-heading"
3679
+ }, t("neetoMolecules.ipRestriction.currentIpTitle")), /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
3680
+ "data-cy": "current-ip-value",
3681
+ weight: "semibold"
3682
+ }, isLoading ? "..." : data.ip), /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
3683
+ className: "pt-2",
3684
+ "data-cy": "current-ip-description",
3685
+ style: "body2"
3686
+ }, t("neetoMolecules.ipRestriction.currentIpDescription")));
3687
+ };
3688
+ var CurrentIp$1 = /*#__PURE__*/React__default["default"].memo(CurrentIp);
3689
+
3690
+ var ipRestrictionUrl = "".concat(IP_RESTRICTIONS_ENGINE_BASE_URL, "/ip_restriction");
3691
+ var update = function update(params) {
3692
+ return axios__default["default"].patch(ipRestrictionUrl, {
3693
+ ipRestriction: params
3694
+ });
3695
+ };
3696
+ var show = function show() {
3697
+ return axios__default["default"].get(ipRestrictionUrl);
3698
+ };
3699
+ var ipRestrictionApi = {
3700
+ update: update,
3701
+ show: show
3702
+ };
3703
+
3704
+ var IP_RESTRICTION = QUERY_KEYS.IP_RESTRICTION;
3705
+ var useShowIpRestriction = function useShowIpRestriction() {
3706
+ return reactQuery.useQuery([IP_RESTRICTION], function () {
3707
+ return ipRestrictionApi.show();
3708
+ });
3709
+ };
3710
+ var useUpdateIpRestriction = function useUpdateIpRestriction() {
3711
+ var queryClient = reactQuery.useQueryClient();
3712
+ return reactQuery.useMutation(ipRestrictionApi.update, {
3713
+ onSuccess: function onSuccess() {
3714
+ return queryClient.invalidateQueries(IP_RESTRICTION);
3715
+ }
3716
+ });
3717
+ };
3718
+
3719
+ var IpRestriction = function IpRestriction() {
3720
+ var _useShowIpRestriction = useShowIpRestriction(),
3721
+ data = _useShowIpRestriction.data,
3722
+ isFetching = _useShowIpRestriction.isLoading;
3723
+ var _useUpdateIpRestricti = useUpdateIpRestriction(),
3724
+ updateIpRestriction = _useUpdateIpRestricti.mutate,
3725
+ isUpdating = _useUpdateIpRestricti.isLoading;
3726
+ var _useTranslation = reactI18next.useTranslation(),
3727
+ t = _useTranslation.t;
3728
+ var handleSwitchButtonChange = function handleSwitchButtonChange(e) {
3729
+ var payload = {
3730
+ isIpRestrictionEnabled: e.target.checked
3731
+ };
3732
+ updateIpRestriction(payload);
3733
+ };
3734
+ if (isFetching) {
3735
+ return /*#__PURE__*/React__default["default"].createElement("div", {
3736
+ className: "h-screen"
3737
+ }, /*#__PURE__*/React__default["default"].createElement(PageLoader$1, null));
3738
+ }
3739
+ return (
3740
+ /*#__PURE__*/
3741
+ // eslint-disable-next-line @bigbinary/neeto/use-neetoui-classes
3742
+ React__default["default"].createElement("div", {
3743
+ className: "neeto-ui-bg-white neeto-ui-border-gray-200 neeto-ui-rounded-sm mx-auto mb-4 w-full space-y-4 border sm:max-w-screen-sm md:max-w-screen-md lg:max-w-3xl",
3744
+ "data-cy": "ip-restrictions-card"
3745
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
3746
+ className: "space-y-1 p-4"
3747
+ }, /*#__PURE__*/React__default["default"].createElement(neetoui.Switch, {
3748
+ checked: data.isIpRestrictionEnabled,
3749
+ "data-cy": "enable-ip-restriction-switch",
3750
+ disabled: isFetching || isUpdating,
3751
+ label: t("neetoMolecules.ipRestriction.switchLabel"),
3752
+ onChange: handleSwitchButtonChange
3753
+ }), /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
3754
+ "data-cy": "ip-restriction-description",
3755
+ style: "body3"
3756
+ }, t("neetoMolecules.ipRestriction.description"))), data.isIpRestrictionEnabled && /*#__PURE__*/React__default["default"].createElement("div", {
3757
+ className: "neeto-ui-bg-gray-100 w-full space-y-4 p-4"
3758
+ }, /*#__PURE__*/React__default["default"].createElement(CurrentIp$1, null), /*#__PURE__*/React__default["default"].createElement(AllowedIpRanges$1, null)))
3759
+ );
3760
+ };
3761
+ var index = /*#__PURE__*/React__default["default"].memo(IpRestriction);
3762
+
3763
+ module.exports = index;
3764
+ //# sourceMappingURL=IpRestriction.cjs.js.map