@bigbinary/neeto-molecules 3.15.43 → 3.15.45

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