@bigbinary/neeto-molecules 1.1.10 → 1.1.12

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