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