@bigbinary/neeto-molecules 3.15.41 → 3.15.43

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