@bigbinary/neeto-molecules 1.1.10 → 1.1.11

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