@oneuptime/common 14.0.96 → 14.0.98

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 (271) hide show
  1. package/Models/AnalyticsModels/NetworkFlow.d.mts +4 -0
  2. package/Models/AnalyticsModels/NetworkFlow.d.ts +4 -0
  3. package/Models/AnalyticsModels/NetworkFlow.js +50 -0
  4. package/Models/DatabaseModels/Alert.d.mts +2 -0
  5. package/Models/DatabaseModels/Alert.d.ts +2 -0
  6. package/Models/DatabaseModels/Alert.js +63 -0
  7. package/Models/DatabaseModels/CodeRepository.d.mts +3 -0
  8. package/Models/DatabaseModels/CodeRepository.d.ts +3 -0
  9. package/Models/DatabaseModels/CodeRepository.js +104 -0
  10. package/Models/DatabaseModels/Incident.d.mts +2 -0
  11. package/Models/DatabaseModels/Incident.d.ts +2 -0
  12. package/Models/DatabaseModels/Incident.js +63 -0
  13. package/Models/DatabaseModels/Index.js +12 -0
  14. package/Models/DatabaseModels/NetworkAddressName.d.mts +14 -0
  15. package/Models/DatabaseModels/NetworkAddressName.d.ts +14 -0
  16. package/Models/DatabaseModels/NetworkAddressName.js +300 -0
  17. package/Models/DatabaseModels/NetworkAddressName.mjs +2 -0
  18. package/Models/DatabaseModels/NetworkDevice.d.mts +1 -0
  19. package/Models/DatabaseModels/NetworkDevice.d.ts +1 -0
  20. package/Models/DatabaseModels/NetworkDevice.js +38 -0
  21. package/Models/DatabaseModels/SecurityCase.d.mts +8 -0
  22. package/Models/DatabaseModels/SecurityCase.d.ts +8 -0
  23. package/Models/DatabaseModels/SecurityCase.js +145 -0
  24. package/Models/DatabaseModels/SecurityCaseEvidence.d.mts +32 -0
  25. package/Models/DatabaseModels/SecurityCaseEvidence.d.ts +32 -0
  26. package/Models/DatabaseModels/SecurityCaseEvidence.js +548 -0
  27. package/Models/DatabaseModels/SecurityCaseEvidence.mjs +2 -0
  28. package/Models/DatabaseModels/SecurityCaseFeed.d.mts +4 -1
  29. package/Models/DatabaseModels/SecurityCaseFeed.d.ts +4 -1
  30. package/Models/DatabaseModels/SecurityCaseFeed.js +6 -0
  31. package/Models/DatabaseModels/SecurityCasePriority.d.mts +2 -0
  32. package/Models/DatabaseModels/SecurityCasePriority.d.ts +2 -0
  33. package/Models/DatabaseModels/SecurityCasePriority.js +44 -0
  34. package/Models/DatabaseModels/SecurityCaseTask.d.mts +22 -0
  35. package/Models/DatabaseModels/SecurityCaseTask.d.ts +22 -0
  36. package/Models/DatabaseModels/SecurityCaseTask.js +467 -0
  37. package/Models/DatabaseModels/SecurityCaseTask.mjs +2 -0
  38. package/Models/DatabaseModels/SecurityHunt.d.mts +34 -0
  39. package/Models/DatabaseModels/SecurityHunt.d.ts +34 -0
  40. package/Models/DatabaseModels/SecurityHunt.js +608 -0
  41. package/Models/DatabaseModels/SecurityHunt.mjs +2 -0
  42. package/Models/DatabaseModels/SecurityWatchlist.d.mts +22 -0
  43. package/Models/DatabaseModels/SecurityWatchlist.d.ts +22 -0
  44. package/Models/DatabaseModels/SecurityWatchlist.js +411 -0
  45. package/Models/DatabaseModels/SecurityWatchlist.mjs +2 -0
  46. package/Models/DatabaseModels/SecurityWatchlistItem.d.mts +17 -0
  47. package/Models/DatabaseModels/SecurityWatchlistItem.d.ts +17 -0
  48. package/Models/DatabaseModels/SecurityWatchlistItem.js +321 -0
  49. package/Models/DatabaseModels/SecurityWatchlistItem.mjs +2 -0
  50. package/Types/AI/AIChatTypes.d.mts +1 -0
  51. package/Types/AI/AIChatTypes.d.ts +1 -0
  52. package/Types/AI/AIRunEventType.d.mts +1 -0
  53. package/Types/AI/AIRunEventType.d.ts +1 -0
  54. package/Types/AI/AIRunEventType.js +8 -0
  55. package/Types/AI/AiAffectedResources.d.mts +2 -1
  56. package/Types/AI/AiAffectedResources.d.ts +2 -1
  57. package/Types/AI/AiAffectedResources.js +12 -1
  58. package/Types/AI/AiTokenCount.d.mts +22 -1
  59. package/Types/AI/AiTokenCount.d.ts +22 -1
  60. package/Types/AI/AiTokenCount.js +126 -57
  61. package/Types/AI/AiTokenCount.mjs +2 -0
  62. package/Types/AI/CodeFixTaskContext.d.mts +1 -0
  63. package/Types/AI/CodeFixTaskContext.d.ts +1 -0
  64. package/Types/AffectedResources/AffectedResourceSearch.d.mts +53 -0
  65. package/Types/AffectedResources/AffectedResourceSearch.d.ts +53 -0
  66. package/Types/AffectedResources/AffectedResourceSearch.js +224 -0
  67. package/Types/AffectedResources/AffectedResourceSearch.mjs +11 -0
  68. package/Types/ArchivableValue/ArchivableValueUsage.d.mts +21 -2
  69. package/Types/ArchivableValue/ArchivableValueUsage.d.ts +21 -2
  70. package/Types/ArchivableValue/ArchivableValueUsage.js +91 -12
  71. package/Types/ArchivableValue/ArchivableValueUsage.mjs +1 -0
  72. package/Types/CodeRepository/CodeRepositorySetting.d.mts +1 -0
  73. package/Types/CodeRepository/CodeRepositorySetting.d.ts +1 -0
  74. package/Types/CodeRepository/CodeRepositorySetting.js +2 -0
  75. package/Types/Color.d.mts +0 -2
  76. package/Types/Color.d.ts +0 -2
  77. package/Types/Color.js +0 -14
  78. package/Types/Database/DatabaseProperty.d.mts +0 -2
  79. package/Types/Database/DatabaseProperty.d.ts +0 -2
  80. package/Types/Database/DatabaseProperty.js +0 -3
  81. package/Types/Date.d.mts +0 -2
  82. package/Types/Date.d.ts +0 -2
  83. package/Types/Date.js +0 -23
  84. package/Types/Domain.d.mts +0 -2
  85. package/Types/Domain.d.ts +0 -2
  86. package/Types/Domain.js +0 -14
  87. package/Types/Email/EmailTemplateType.d.mts +3 -0
  88. package/Types/Email/EmailTemplateType.d.ts +3 -0
  89. package/Types/Email/EmailTemplateType.js +4 -0
  90. package/Types/Email.d.mts +0 -2
  91. package/Types/Email.d.ts +0 -2
  92. package/Types/Email.js +0 -15
  93. package/Types/IP/IP.d.mts +0 -2
  94. package/Types/IP/IP.d.ts +0 -2
  95. package/Types/IP/IP.js +0 -14
  96. package/Types/Link.d.mts +1 -0
  97. package/Types/Link.d.ts +1 -0
  98. package/Types/Monitor/CriteriaAlert.d.mts +0 -2
  99. package/Types/Monitor/CriteriaAlert.d.ts +0 -2
  100. package/Types/Monitor/CriteriaAlert.js +0 -18
  101. package/Types/Monitor/CriteriaAlert.mjs +1 -2
  102. package/Types/Monitor/CriteriaFilter.d.mts +0 -2
  103. package/Types/Monitor/CriteriaFilter.d.ts +0 -2
  104. package/Types/Monitor/CriteriaFilter.js +1 -42
  105. package/Types/Monitor/CriteriaFilter.mjs +0 -1
  106. package/Types/Monitor/CriteriaIncident.d.mts +0 -2
  107. package/Types/Monitor/CriteriaIncident.d.ts +0 -2
  108. package/Types/Monitor/CriteriaIncident.js +0 -23
  109. package/Types/Monitor/CriteriaIncident.mjs +1 -2
  110. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.d.mts +0 -2
  111. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.d.ts +0 -2
  112. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.js +0 -11
  113. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.mjs +1 -2
  114. package/Types/Monitor/MonitorCriteria.d.mts +0 -2
  115. package/Types/Monitor/MonitorCriteria.d.ts +0 -2
  116. package/Types/Monitor/MonitorCriteria.js +0 -21
  117. package/Types/Monitor/MonitorCriteriaInstance.d.mts +0 -2
  118. package/Types/Monitor/MonitorCriteriaInstance.d.ts +0 -2
  119. package/Types/Monitor/MonitorCriteriaInstance.js +0 -54
  120. package/Types/Monitor/MonitorStep.d.mts +0 -2
  121. package/Types/Monitor/MonitorStep.d.ts +0 -2
  122. package/Types/Monitor/MonitorStep.js +0 -80
  123. package/Types/Monitor/MonitorSteps.d.mts +0 -2
  124. package/Types/Monitor/MonitorSteps.d.ts +0 -2
  125. package/Types/Monitor/MonitorSteps.js +0 -31
  126. package/Types/Name.d.mts +0 -2
  127. package/Types/Name.d.ts +0 -2
  128. package/Types/Name.js +0 -14
  129. package/Types/NetFlow/NetworkAddressName.d.mts +30 -0
  130. package/Types/NetFlow/NetworkAddressName.d.ts +30 -0
  131. package/Types/NetFlow/NetworkAddressName.js +149 -0
  132. package/Types/NetFlow/NetworkAddressName.mjs +6 -0
  133. package/Types/NetFlow/NetworkTraffic.d.mts +20 -0
  134. package/Types/NetFlow/NetworkTraffic.d.ts +20 -0
  135. package/Types/NetFlow/NetworkTraffic.js +5 -1
  136. package/Types/NetFlow/NetworkTraffic.mjs +2 -0
  137. package/Types/NetworkController/NetworkControllerReadSummary.d.mts +2 -0
  138. package/Types/NetworkController/NetworkControllerReadSummary.d.ts +2 -0
  139. package/Types/NetworkController/NetworkControllerReadSummary.js +7 -1
  140. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.d.mts +47 -1
  141. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.d.ts +47 -1
  142. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.js +173 -8
  143. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.mjs +7 -0
  144. package/Types/NotificationSetting/NotificationEmailRollupCategory.d.mts +1 -0
  145. package/Types/NotificationSetting/NotificationEmailRollupCategory.d.ts +1 -0
  146. package/Types/NotificationSetting/NotificationEmailRollupCategory.js +12 -0
  147. package/Types/NotificationSetting/NotificationEmailRollupPolicy.js +6 -0
  148. package/Types/NotificationSetting/NotificationSettingEventType.d.mts +3 -0
  149. package/Types/NotificationSetting/NotificationSettingEventType.d.ts +3 -0
  150. package/Types/NotificationSetting/NotificationSettingEventType.js +15 -0
  151. package/Types/ObjectID.d.mts +0 -1
  152. package/Types/ObjectID.d.ts +0 -1
  153. package/Types/ObjectID.js +0 -9
  154. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.d.mts +4 -0
  155. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.d.ts +4 -0
  156. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.js +25 -1
  157. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.mjs +4 -0
  158. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.d.mts +15 -0
  159. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.d.ts +15 -0
  160. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.js +118 -0
  161. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.mjs +9 -0
  162. package/Types/Permission.d.mts +8 -0
  163. package/Types/Permission.d.ts +8 -0
  164. package/Types/Permission.js +87 -3
  165. package/Types/Phone.d.mts +0 -2
  166. package/Types/Phone.d.ts +0 -2
  167. package/Types/Phone.js +0 -14
  168. package/Types/Port.d.mts +0 -2
  169. package/Types/Port.d.ts +0 -2
  170. package/Types/Port.js +0 -14
  171. package/Types/ProviderLogo/ProviderLogo.d.mts +8 -1
  172. package/Types/ProviderLogo/ProviderLogo.d.ts +8 -1
  173. package/Types/ProviderLogo/ProviderLogo.js +14 -0
  174. package/Types/SecurityCase/SecurityCaseEventEvidence.d.mts +67 -0
  175. package/Types/SecurityCase/SecurityCaseEventEvidence.d.ts +67 -0
  176. package/Types/SecurityCase/SecurityCaseEventEvidence.js +271 -0
  177. package/Types/SecurityCase/SecurityCaseEventEvidence.mjs +13 -0
  178. package/Types/SecurityCase/SecurityCaseEvidenceKind.d.mts +8 -0
  179. package/Types/SecurityCase/SecurityCaseEvidenceKind.d.ts +8 -0
  180. package/Types/SecurityCase/SecurityCaseEvidenceKind.js +34 -0
  181. package/Types/SecurityCase/SecurityCaseEvidenceKind.mjs +4 -0
  182. package/Types/SecurityEvent/SecurityHunt.d.mts +122 -0
  183. package/Types/SecurityEvent/SecurityHunt.d.ts +122 -0
  184. package/Types/SecurityEvent/SecurityHunt.js +391 -0
  185. package/Types/SecurityEvent/SecurityHunt.mjs +32 -0
  186. package/Types/SecurityEvent/SecurityWatchlist.d.mts +167 -0
  187. package/Types/SecurityEvent/SecurityWatchlist.d.ts +167 -0
  188. package/Types/SecurityEvent/SecurityWatchlist.js +648 -0
  189. package/Types/SecurityEvent/SecurityWatchlist.mjs +51 -0
  190. package/Types/SecurityEvent/SigmaRule.d.mts +2 -0
  191. package/Types/SecurityEvent/SigmaRule.d.ts +2 -0
  192. package/Types/SecurityEvent/SigmaRule.js +5 -0
  193. package/Types/Telemetry/OpenTelemetryGuides.js +177 -5
  194. package/Types/Version.d.mts +0 -2
  195. package/Types/Version.d.ts +0 -2
  196. package/Types/Version.js +0 -14
  197. package/Types/Workflow/AffectedResourcesSetting.d.mts +13 -0
  198. package/Types/Workflow/AffectedResourcesSetting.d.ts +13 -0
  199. package/Types/Workflow/AffectedResourcesSetting.js +120 -0
  200. package/Types/Workflow/AffectedResourcesSetting.mjs +8 -0
  201. package/Types/Workflow/Components/BaseModel.js +15 -3
  202. package/Types/Workflow/Documentation/DatabaseDocumentation.js +36 -0
  203. package/Types/Workflow/RunRecord.d.mts +3 -14
  204. package/Types/Workflow/RunRecord.d.ts +3 -14
  205. package/Types/Workflow/RunRecord.js +10 -51
  206. package/Utils/AI/InvestigationLogStall.d.mts +38 -0
  207. package/Utils/AI/InvestigationLogStall.d.ts +38 -0
  208. package/Utils/AI/InvestigationLogStall.js +163 -0
  209. package/Utils/AI/InvestigationLogStall.mjs +11 -0
  210. package/Utils/Inventory/AssetFactSource.d.mts +6 -2
  211. package/Utils/Inventory/AssetFactSource.d.ts +6 -2
  212. package/Utils/Inventory/AssetFactSource.js +18 -1
  213. package/Utils/Inventory/AssetFactSource.mjs +1 -0
  214. package/Utils/Markdown/FeedLead.d.mts +10 -0
  215. package/Utils/Markdown/FeedLead.d.ts +10 -0
  216. package/Utils/Markdown/FeedLead.js +198 -0
  217. package/Utils/Markdown/FeedLead.mjs +8 -0
  218. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.d.mts +9 -1
  219. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.d.ts +9 -1
  220. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.js +139 -18
  221. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.mjs +1 -0
  222. package/Utils/NetworkDevice/NetworkDeviceRefresh.d.mts +88 -0
  223. package/Utils/NetworkDevice/NetworkDeviceRefresh.d.ts +88 -0
  224. package/Utils/NetworkDevice/NetworkDeviceRefresh.js +232 -0
  225. package/Utils/NetworkDevice/NetworkDeviceRefresh.mjs +16 -0
  226. package/Utils/NetworkTraffic/NetworkAddressBlock.d.mts +20 -0
  227. package/Utils/NetworkTraffic/NetworkAddressBlock.d.ts +20 -0
  228. package/Utils/NetworkTraffic/NetworkAddressBlock.js +264 -0
  229. package/Utils/NetworkTraffic/NetworkAddressBlock.mjs +3 -0
  230. package/Utils/Project/RecordNumber.d.mts +43 -0
  231. package/Utils/Project/RecordNumber.d.ts +43 -0
  232. package/Utils/Project/RecordNumber.js +151 -0
  233. package/Utils/Project/RecordNumber.mjs +6 -0
  234. package/Utils/Schema/MonitorSchemas.d.mts +9 -0
  235. package/Utils/Schema/MonitorSchemas.d.ts +9 -0
  236. package/Utils/Schema/MonitorSchemas.js +291 -0
  237. package/Utils/Schema/MonitorSchemas.mjs +9 -0
  238. package/Utils/Schema/TypeSchemas.d.mts +12 -0
  239. package/Utils/Schema/TypeSchemas.d.ts +12 -0
  240. package/Utils/Schema/TypeSchemas.js +176 -0
  241. package/Utils/Schema/TypeSchemas.mjs +11 -0
  242. package/Utils/Schema/Zod.js +17 -17
  243. package/Utils/SecurityCase/SecurityCaseMarkdown.d.mts +43 -0
  244. package/Utils/SecurityCase/SecurityCaseMarkdown.d.ts +43 -0
  245. package/Utils/SecurityCase/SecurityCaseMarkdown.js +89 -0
  246. package/Utils/SecurityCase/SecurityCaseMarkdown.mjs +11 -0
  247. package/Utils/SecurityCase/SecurityCasePriorities.d.mts +2 -0
  248. package/Utils/SecurityCase/SecurityCasePriorities.d.ts +2 -0
  249. package/Utils/SecurityCase/SecurityCasePriorities.js +15 -1
  250. package/Utils/SecurityCase/SecurityCaseTargets.d.mts +128 -0
  251. package/Utils/SecurityCase/SecurityCaseTargets.d.ts +128 -0
  252. package/Utils/SecurityCase/SecurityCaseTargets.js +482 -0
  253. package/Utils/SecurityCase/SecurityCaseTargets.mjs +28 -0
  254. package/Utils/SecurityEvent/SecurityEventSearch.d.mts +56 -0
  255. package/Utils/SecurityEvent/SecurityEventSearch.d.ts +56 -0
  256. package/Utils/SecurityEvent/SecurityEventSearch.js +422 -0
  257. package/Utils/SecurityEvent/SecurityEventSearch.mjs +21 -0
  258. package/Utils/SecurityEvent/SecurityHuntSearch.d.mts +12 -0
  259. package/Utils/SecurityEvent/SecurityHuntSearch.d.ts +12 -0
  260. package/Utils/SecurityEvent/SecurityHuntSearch.js +51 -0
  261. package/Utils/SecurityEvent/SecurityHuntSearch.mjs +3 -0
  262. package/Utils/SecurityEvent/Sigma/SigmaRuleParser.js +22 -0
  263. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.d.mts +24 -0
  264. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.d.ts +24 -0
  265. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.js +183 -0
  266. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.mjs +9 -0
  267. package/Utils/Suggestions/TracePerformanceFixSuggestion.d.mts +9 -0
  268. package/Utils/Suggestions/TracePerformanceFixSuggestion.d.ts +9 -0
  269. package/Utils/Suggestions/TracePerformanceFixSuggestion.js +69 -1
  270. package/Utils/Suggestions/TracePerformanceFixSuggestion.mjs +4 -0
  271. package/package.json +1 -1
@@ -0,0 +1,88 @@
1
+ import { NetworkDeviceControllerReading } from "../../Types/NetworkDevice/NetworkDeviceDiscoveredDetails";
2
+ export declare const NETWORK_DEVICE_REFRESH_PENDING_MS: number;
3
+ export declare const NETWORK_DEVICE_REFRESH_GIVE_UP_MS: number;
4
+ export declare const NETWORK_DEVICE_REFRESH_POLL_AT: Date;
5
+ export declare const MONITOR_BACKED_REASON: string;
6
+ export declare const NO_PROBE_REASON: string;
7
+ export declare const POLLING_OFF_REASON: string;
8
+ export declare const CONTROLLER_OFF_REASON: string;
9
+ export interface NetworkDeviceRefreshAnswer {
10
+ requestedAt: string;
11
+ isProbeReading: boolean;
12
+ probeName?: string | undefined;
13
+ isControllerReading: boolean;
14
+ controllerName?: string | undefined;
15
+ wasAlreadyRequested: boolean;
16
+ }
17
+ export declare function readNetworkDeviceRefreshAnswer(value: unknown): NetworkDeviceRefreshAnswer | undefined;
18
+ export interface NetworkDeviceRefreshSource {
19
+ probeId?: unknown;
20
+ isPollingEnabled?: unknown;
21
+ monitoringMethod?: unknown;
22
+ hostname?: unknown;
23
+ discoveredDetails?: unknown;
24
+ }
25
+ export interface NetworkDeviceRefreshReaders {
26
+ isProbePolled: boolean;
27
+ controller?: NetworkDeviceControllerReading | undefined;
28
+ }
29
+ /**
30
+ * Who can be asked to read a device again: its probe, its controller, both,
31
+ * or neither (then Refresh has nothing to ask, and is not offered).
32
+ */
33
+ export declare function getNetworkDeviceRefreshReaders(device: NetworkDeviceRefreshSource): NetworkDeviceRefreshReaders;
34
+ export declare function canRefreshNetworkDevice(device: NetworkDeviceRefreshSource): boolean;
35
+ /**
36
+ * True for a refresh asked for so recently, and not answered yet, that a new
37
+ * ask is the same one.
38
+ */
39
+ export declare function isNetworkDeviceRefreshPending(data: {
40
+ refreshRequestedAt: unknown;
41
+ lastPolledAt: unknown;
42
+ now: Date;
43
+ }): boolean;
44
+ /**
45
+ * True when a poll that lands now is the first since someone asked for the
46
+ * device to be read again: the poll before it landed before the ask.
47
+ */
48
+ export declare function isFirstPollSinceRefresh(data: {
49
+ refreshRequestedAt: unknown;
50
+ previousLastPolledAt: unknown;
51
+ }): boolean;
52
+ export declare enum NetworkDeviceRefreshProgress {
53
+ Waiting = "waiting",
54
+ Read = "read",
55
+ Unreachable = "unreachable",
56
+ Late = "late"
57
+ }
58
+ export interface NetworkDeviceRefreshStanding {
59
+ progress: NetworkDeviceRefreshProgress;
60
+ isProbePending: boolean;
61
+ isControllerPending: boolean;
62
+ }
63
+ /**
64
+ * Where a refresh stands, from the device as it reads now: its probe has
65
+ * answered once it polled the device after the ask (lastPolledAt), and its
66
+ * controller once its reading was read after the ask (the reading's
67
+ * readAt). Both on the server's clock, as the ask's time is; only "late"
68
+ * reads the page's own clock, and three minutes leave room for a skew.
69
+ */
70
+ export declare function getNetworkDeviceRefreshStanding(data: {
71
+ answer: NetworkDeviceRefreshAnswer;
72
+ lastPolledAt: unknown;
73
+ isReachable: unknown;
74
+ controllerReadAt: unknown;
75
+ now: Date;
76
+ }): NetworkDeviceRefreshStanding;
77
+ /**
78
+ * A refresh someone asked for that has not been answered yet, and is not
79
+ * late: what a page opened after the ask - another tab, a reload - shows as
80
+ * under way. Who reads it is worked out from the device as it is.
81
+ */
82
+ export declare function getPendingNetworkDeviceRefresh(data: {
83
+ device: NetworkDeviceRefreshSource & {
84
+ refreshRequestedAt?: unknown;
85
+ lastPolledAt?: unknown;
86
+ };
87
+ now: Date;
88
+ }): NetworkDeviceRefreshAnswer | undefined;
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NetworkDeviceRefreshProgress = exports.CONTROLLER_OFF_REASON = exports.POLLING_OFF_REASON = exports.NO_PROBE_REASON = exports.MONITOR_BACKED_REASON = exports.NETWORK_DEVICE_REFRESH_POLL_AT = exports.NETWORK_DEVICE_REFRESH_GIVE_UP_MS = exports.NETWORK_DEVICE_REFRESH_PENDING_MS = void 0;
4
+ exports.readNetworkDeviceRefreshAnswer = readNetworkDeviceRefreshAnswer;
5
+ exports.getNetworkDeviceRefreshReaders = getNetworkDeviceRefreshReaders;
6
+ exports.canRefreshNetworkDevice = canRefreshNetworkDevice;
7
+ exports.isNetworkDeviceRefreshPending = isNetworkDeviceRefreshPending;
8
+ exports.isFirstPollSinceRefresh = isFirstPollSinceRefresh;
9
+ exports.getNetworkDeviceRefreshStanding = getNetworkDeviceRefreshStanding;
10
+ exports.getPendingNetworkDeviceRefresh = getPendingNetworkDeviceRefresh;
11
+ const NetworkDeviceMonitoringMethod_1 = require("../../Types/NetworkDevice/NetworkDeviceMonitoringMethod");
12
+ const NetworkDeviceDiscoveredDetails_1 = require("../../Types/NetworkDevice/NetworkDeviceDiscoveredDetails");
13
+ /*
14
+ * "REFRESH": READ A NETWORK DEVICE AGAIN NOW (OneUptime issue #5185: "Inventory
15
+ * should support refreshing discovered information as devices and network
16
+ * details change").
17
+ *
18
+ * A device's details are read on schedules: its probe polls it every few
19
+ * minutes, a network controller connection reads Meraki every few minutes,
20
+ * discovery scans sweep its address every few hours, and its Inventory item
21
+ * copies the device every fifteen minutes. After a firmware upgrade or a
22
+ * swapped box, a person should not have to wait for those: Refresh asks the
23
+ * readers that can be asked to read it now.
24
+ *
25
+ * - Its probe, when a probe polls it (polling on, a probe and an address,
26
+ * not monitor-backed): the device goes to the front of its probe's queue,
27
+ * so the probe's next fetch - within a minute - pings it, and walks it
28
+ * when it has SNMP credentials. Its Inventory item is copied as soon as
29
+ * that poll lands.
30
+ * - Its controller, when a network controller connection describes it
31
+ * (the Meraki dashboard): that connection is read at once, and writes
32
+ * the device's reading again even when nothing in it changed - so the
33
+ * reading says it was read just now.
34
+ *
35
+ * Discovery scans are not run from here: a scan sweeps a whole range, and
36
+ * sweeping a /16 to refresh one device is out of all proportion. What they
37
+ * read stays as it is, with when.
38
+ *
39
+ * Pure, and shared: the refresh route decides with it, the poll pipeline
40
+ * knows a poll answers a refresh with it, and the Dashboard draws the
41
+ * button's states with it.
42
+ */
43
+ /*
44
+ * A refresh asked for again within this long of the last one, before that
45
+ * one was answered, IS that one: nothing is queued twice.
46
+ */
47
+ exports.NETWORK_DEVICE_REFRESH_PENDING_MS = 60 * 1000;
48
+ /*
49
+ * How long a refresh is waited for. A probe fetches every minute; past this
50
+ * the probe is likely offline or busy, and the page says so.
51
+ */
52
+ exports.NETWORK_DEVICE_REFRESH_GIVE_UP_MS = 3 * 60 * 1000;
53
+ // Where a refreshed device goes in its probe's queue: first.
54
+ exports.NETWORK_DEVICE_REFRESH_POLL_AT = new Date(0);
55
+ /*
56
+ * Why a device cannot be read again now, as the refresh route refuses it
57
+ * and the card shows it (NetworkDeviceRefreshRunner.getCannotRefreshReason).
58
+ * The server's own words, as every refusal the API sends is.
59
+ */
60
+ exports.MONITOR_BACKED_REASON = "This device is checked by its monitor, so nothing polls it: there is nothing to read again. Its details come from discovery scans of its address.";
61
+ exports.NO_PROBE_REASON = "No probe polls this device yet. Pick the probe that reaches it in the device's Settings, then refresh it.";
62
+ exports.POLLING_OFF_REASON = "Polling is turned off for this device. Turn it on in the device's Settings to read it again.";
63
+ /*
64
+ * A device only its Meraki connection reads, while that connection is
65
+ * turned off: the card offered Refresh for the connection's reading, so the
66
+ * refusal names the connection rather than the probe the device never had.
67
+ */
68
+ exports.CONTROLLER_OFF_REASON = "The Meraki connection that reads this device is turned off. Turn it on at the foot of the network's Traffic page, then refresh the device.";
69
+ /*
70
+ * An answer read back without trusting its shape: undefined when it is not
71
+ * one (no time that parses, nobody reading).
72
+ */
73
+ function readNetworkDeviceRefreshAnswer(value) {
74
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
75
+ return undefined;
76
+ }
77
+ const answer = value;
78
+ const requestedAt = readTime(answer["requestedAt"]);
79
+ const isProbeReading = answer["isProbeReading"] === true;
80
+ const isControllerReading = answer["isControllerReading"] === true;
81
+ if (requestedAt === undefined || (!isProbeReading && !isControllerReading)) {
82
+ return undefined;
83
+ }
84
+ const text = (key) => {
85
+ const read = answer[key];
86
+ return typeof read === "string" && read.trim() ? read.trim() : undefined;
87
+ };
88
+ const probeName = text("probeName");
89
+ const controllerName = text("controllerName");
90
+ return Object.assign(Object.assign(Object.assign(Object.assign({ requestedAt: new Date(requestedAt).toISOString(), isProbeReading: isProbeReading }, (probeName ? { probeName: probeName } : {})), { isControllerReading: isControllerReading }), (controllerName ? { controllerName: controllerName } : {})), { wasAlreadyRequested: answer["wasAlreadyRequested"] === true });
91
+ }
92
+ function readTime(value) {
93
+ if (value instanceof Date) {
94
+ const time = value.getTime();
95
+ return Number.isNaN(time) ? undefined : time;
96
+ }
97
+ if (typeof value === "string" && value.trim()) {
98
+ const time = new Date(value.trim()).getTime();
99
+ return Number.isNaN(time) ? undefined : time;
100
+ }
101
+ return undefined;
102
+ }
103
+ /**
104
+ * Who can be asked to read a device again: its probe, its controller, both,
105
+ * or neither (then Refresh has nothing to ask, and is not offered).
106
+ */
107
+ function getNetworkDeviceRefreshReaders(device) {
108
+ const hostname = typeof device.hostname === "string" ? device.hostname.trim() : "";
109
+ const probeId = device.probeId === undefined || device.probeId === null
110
+ ? ""
111
+ : String(device.probeId).trim();
112
+ const monitoringMethod = typeof device.monitoringMethod === "string"
113
+ ? device.monitoringMethod
114
+ : undefined;
115
+ const isProbePolled = Boolean(probeId &&
116
+ hostname &&
117
+ device.isPollingEnabled !== false &&
118
+ NetworkDeviceMonitoringMethod_1.NetworkDeviceMonitoringMethodUtil.isProbePolled(monitoringMethod));
119
+ const controller = (0, NetworkDeviceDiscoveredDetails_1.readNetworkDeviceDiscoveredDetails)(device.discoveredDetails).controller;
120
+ return controller
121
+ ? { isProbePolled: isProbePolled, controller: controller }
122
+ : { isProbePolled: isProbePolled };
123
+ }
124
+ // True when something can be asked to read the device again.
125
+ function canRefreshNetworkDevice(device) {
126
+ const readers = getNetworkDeviceRefreshReaders(device);
127
+ return readers.isProbePolled || Boolean(readers.controller);
128
+ }
129
+ /**
130
+ * True for a refresh asked for so recently, and not answered yet, that a new
131
+ * ask is the same one.
132
+ */
133
+ function isNetworkDeviceRefreshPending(data) {
134
+ const requestedAt = readTime(data.refreshRequestedAt);
135
+ if (requestedAt === undefined) {
136
+ return false;
137
+ }
138
+ const polledAt = readTime(data.lastPolledAt);
139
+ const age = data.now.getTime() - requestedAt;
140
+ return (age >= 0 &&
141
+ age < exports.NETWORK_DEVICE_REFRESH_PENDING_MS &&
142
+ (polledAt === undefined || polledAt < requestedAt));
143
+ }
144
+ /**
145
+ * True when a poll that lands now is the first since someone asked for the
146
+ * device to be read again: the poll before it landed before the ask.
147
+ */
148
+ function isFirstPollSinceRefresh(data) {
149
+ const requestedAt = readTime(data.refreshRequestedAt);
150
+ if (requestedAt === undefined) {
151
+ return false;
152
+ }
153
+ const previous = readTime(data.previousLastPolledAt);
154
+ return previous === undefined || previous < requestedAt;
155
+ }
156
+ var NetworkDeviceRefreshProgress;
157
+ (function (NetworkDeviceRefreshProgress) {
158
+ // Asked, and waiting for the readers.
159
+ NetworkDeviceRefreshProgress["Waiting"] = "waiting";
160
+ // Every reader asked has read it since, and its probe reached it.
161
+ NetworkDeviceRefreshProgress["Read"] = "read";
162
+ // Its probe polled it since the ask, and could not reach it.
163
+ NetworkDeviceRefreshProgress["Unreachable"] = "unreachable";
164
+ // A reader asked has not read it in the time a read takes.
165
+ NetworkDeviceRefreshProgress["Late"] = "late";
166
+ })(NetworkDeviceRefreshProgress || (exports.NetworkDeviceRefreshProgress = NetworkDeviceRefreshProgress = {}));
167
+ /**
168
+ * Where a refresh stands, from the device as it reads now: its probe has
169
+ * answered once it polled the device after the ask (lastPolledAt), and its
170
+ * controller once its reading was read after the ask (the reading's
171
+ * readAt). Both on the server's clock, as the ask's time is; only "late"
172
+ * reads the page's own clock, and three minutes leave room for a skew.
173
+ */
174
+ function getNetworkDeviceRefreshStanding(data) {
175
+ const requestedAt = readTime(data.answer.requestedAt);
176
+ const polledAt = readTime(data.lastPolledAt);
177
+ const controllerReadAt = readTime(data.controllerReadAt);
178
+ const isAnsweredAt = (time) => {
179
+ return (requestedAt !== undefined && time !== undefined && time >= requestedAt);
180
+ };
181
+ const isProbePending = data.answer.isProbeReading && !isAnsweredAt(polledAt);
182
+ const isControllerPending = data.answer.isControllerReading && !isAnsweredAt(controllerReadAt);
183
+ if (!isProbePending && !isControllerPending) {
184
+ return {
185
+ progress: data.answer.isProbeReading && data.isReachable === false
186
+ ? NetworkDeviceRefreshProgress.Unreachable
187
+ : NetworkDeviceRefreshProgress.Read,
188
+ isProbePending: false,
189
+ isControllerPending: false,
190
+ };
191
+ }
192
+ const isLate = requestedAt !== undefined &&
193
+ data.now.getTime() - requestedAt >= exports.NETWORK_DEVICE_REFRESH_GIVE_UP_MS;
194
+ return {
195
+ progress: isLate
196
+ ? NetworkDeviceRefreshProgress.Late
197
+ : NetworkDeviceRefreshProgress.Waiting,
198
+ isProbePending: isProbePending,
199
+ isControllerPending: isControllerPending,
200
+ };
201
+ }
202
+ /**
203
+ * A refresh someone asked for that has not been answered yet, and is not
204
+ * late: what a page opened after the ask - another tab, a reload - shows as
205
+ * under way. Who reads it is worked out from the device as it is.
206
+ */
207
+ function getPendingNetworkDeviceRefresh(data) {
208
+ var _a;
209
+ const requestedAt = readTime(data.device.refreshRequestedAt);
210
+ if (requestedAt === undefined ||
211
+ data.now.getTime() - requestedAt >= exports.NETWORK_DEVICE_REFRESH_GIVE_UP_MS) {
212
+ return undefined;
213
+ }
214
+ const readers = getNetworkDeviceRefreshReaders(data.device);
215
+ const controllerReadAt = readTime((_a = readers.controller) === null || _a === void 0 ? void 0 : _a.readAt);
216
+ const answer = {
217
+ requestedAt: new Date(requestedAt).toISOString(),
218
+ isProbeReading: readers.isProbePolled,
219
+ isControllerReading: Boolean(readers.controller),
220
+ wasAlreadyRequested: true,
221
+ };
222
+ const standing = getNetworkDeviceRefreshStanding({
223
+ answer: answer,
224
+ lastPolledAt: data.device.lastPolledAt,
225
+ isReachable: undefined,
226
+ controllerReadAt: controllerReadAt,
227
+ now: data.now,
228
+ });
229
+ return standing.progress === NetworkDeviceRefreshProgress.Waiting
230
+ ? answer
231
+ : undefined;
232
+ }
@@ -0,0 +1,16 @@
1
+ import commonJsModule from "./NetworkDeviceRefresh.js";
2
+ export const CONTROLLER_OFF_REASON = commonJsModule.CONTROLLER_OFF_REASON;
3
+ export const MONITOR_BACKED_REASON = commonJsModule.MONITOR_BACKED_REASON;
4
+ export const NETWORK_DEVICE_REFRESH_GIVE_UP_MS = commonJsModule.NETWORK_DEVICE_REFRESH_GIVE_UP_MS;
5
+ export const NETWORK_DEVICE_REFRESH_PENDING_MS = commonJsModule.NETWORK_DEVICE_REFRESH_PENDING_MS;
6
+ export const NETWORK_DEVICE_REFRESH_POLL_AT = commonJsModule.NETWORK_DEVICE_REFRESH_POLL_AT;
7
+ export const NO_PROBE_REASON = commonJsModule.NO_PROBE_REASON;
8
+ export const NetworkDeviceRefreshProgress = commonJsModule.NetworkDeviceRefreshProgress;
9
+ export const POLLING_OFF_REASON = commonJsModule.POLLING_OFF_REASON;
10
+ export const canRefreshNetworkDevice = commonJsModule.canRefreshNetworkDevice;
11
+ export const getNetworkDeviceRefreshReaders = commonJsModule.getNetworkDeviceRefreshReaders;
12
+ export const getNetworkDeviceRefreshStanding = commonJsModule.getNetworkDeviceRefreshStanding;
13
+ export const getPendingNetworkDeviceRefresh = commonJsModule.getPendingNetworkDeviceRefresh;
14
+ export const isFirstPollSinceRefresh = commonJsModule.isFirstPollSinceRefresh;
15
+ export const isNetworkDeviceRefreshPending = commonJsModule.isNetworkDeviceRefreshPending;
16
+ export const readNetworkDeviceRefreshAnswer = commonJsModule.readNetworkDeviceRefreshAnswer;
@@ -0,0 +1,20 @@
1
+ export interface NetworkAddressBlock {
2
+ family: 4 | 6;
3
+ groups: Array<number>;
4
+ prefixLength: number;
5
+ text: string;
6
+ }
7
+ export declare const MAX_NETWORK_ADDRESS_BLOCK_TEXT_LENGTH: number;
8
+ interface AddressGroups {
9
+ family: 4 | 6;
10
+ groups: Array<number>;
11
+ }
12
+ export default class NetworkAddressBlockUtil {
13
+ static readAddress(value: unknown): AddressGroups | null;
14
+ static canonicalAddress(value: unknown): string | null;
15
+ static parse(value: unknown): NetworkAddressBlock | null;
16
+ static isSingleAddress(block: NetworkAddressBlock): boolean;
17
+ static contains(block: NetworkAddressBlock, address: string): boolean;
18
+ static mostSpecific<T>(address: string, items: ReadonlyArray<T>, readBlock: (item: T) => NetworkAddressBlock | null): T | null;
19
+ }
20
+ export {};
@@ -0,0 +1,20 @@
1
+ export interface NetworkAddressBlock {
2
+ family: 4 | 6;
3
+ groups: Array<number>;
4
+ prefixLength: number;
5
+ text: string;
6
+ }
7
+ export declare const MAX_NETWORK_ADDRESS_BLOCK_TEXT_LENGTH: number;
8
+ interface AddressGroups {
9
+ family: 4 | 6;
10
+ groups: Array<number>;
11
+ }
12
+ export default class NetworkAddressBlockUtil {
13
+ static readAddress(value: unknown): AddressGroups | null;
14
+ static canonicalAddress(value: unknown): string | null;
15
+ static parse(value: unknown): NetworkAddressBlock | null;
16
+ static isSingleAddress(block: NetworkAddressBlock): boolean;
17
+ static contains(block: NetworkAddressBlock, address: string): boolean;
18
+ static mostSpecific<T>(address: string, items: ReadonlyArray<T>, readBlock: (item: T) => NetworkAddressBlock | null): T | null;
19
+ }
20
+ export {};
@@ -0,0 +1,264 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MAX_NETWORK_ADDRESS_BLOCK_TEXT_LENGTH = void 0;
7
+ const IP_1 = __importDefault(require("../../Types/IP/IP"));
8
+ const IpCanonicalUtil_1 = __importDefault(require("../IpCanonicalUtil"));
9
+ // The longest text a block is read from (an IPv6 subnet is at most 49 characters).
10
+ exports.MAX_NETWORK_ADDRESS_BLOCK_TEXT_LENGTH = 100;
11
+ function isDigits(text) {
12
+ if (!text) {
13
+ return false;
14
+ }
15
+ for (let index = 0; index < text.length; index++) {
16
+ const code = text.charCodeAt(index);
17
+ if (code < 48 || code > 57) {
18
+ return false;
19
+ }
20
+ }
21
+ return true;
22
+ }
23
+ function readIpv4Groups(text) {
24
+ const parts = text.split(".");
25
+ if (parts.length !== 4) {
26
+ return null;
27
+ }
28
+ const octets = [];
29
+ for (const part of parts) {
30
+ if (!isDigits(part) || part.length > 3) {
31
+ return null;
32
+ }
33
+ const octet = Number(part);
34
+ if (octet > 255) {
35
+ return null;
36
+ }
37
+ octets.push(octet);
38
+ }
39
+ return [octets[0] * 256 + octets[1], octets[2] * 256 + octets[3]];
40
+ }
41
+ function isHexDigits(text) {
42
+ if (!text || text.length > 4) {
43
+ return false;
44
+ }
45
+ for (let index = 0; index < text.length; index++) {
46
+ const code = text.charCodeAt(index);
47
+ const isHex = (code >= 48 && code <= 57) ||
48
+ (code >= 65 && code <= 70) ||
49
+ (code >= 97 && code <= 102);
50
+ if (!isHex) {
51
+ return false;
52
+ }
53
+ }
54
+ return true;
55
+ }
56
+ // The eight groups of an IPv6 literal IP.isIP accepted (no zone), or null.
57
+ function readIpv6Groups(text) {
58
+ const halves = text.split("::");
59
+ if (halves.length > 2) {
60
+ return null;
61
+ }
62
+ const readHalf = (half) => {
63
+ if (!half) {
64
+ return [];
65
+ }
66
+ const pieces = half.split(":");
67
+ const groups = [];
68
+ for (let index = 0; index < pieces.length; index++) {
69
+ const piece = pieces[index];
70
+ // An embedded IPv4 address ends the address: ::ffff:10.0.0.5.
71
+ if (index === pieces.length - 1 && piece.includes(".")) {
72
+ const ipv4 = readIpv4Groups(piece);
73
+ if (!ipv4) {
74
+ return null;
75
+ }
76
+ groups.push(...ipv4);
77
+ continue;
78
+ }
79
+ if (!isHexDigits(piece)) {
80
+ return null;
81
+ }
82
+ groups.push(parseInt(piece, 16));
83
+ }
84
+ return groups;
85
+ };
86
+ const head = readHalf(halves[0] || "");
87
+ if (halves.length === 1) {
88
+ return head && head.length === 8 ? head : null;
89
+ }
90
+ const tail = readHalf(halves[1] || "");
91
+ if (!head || !tail || head.length + tail.length > 7) {
92
+ return null;
93
+ }
94
+ return [
95
+ ...head,
96
+ ...new Array(8 - head.length - tail.length).fill(0),
97
+ ...tail,
98
+ ];
99
+ }
100
+ function groupsToIpv4Text(groups) {
101
+ return [
102
+ Math.floor(groups[0] / 256),
103
+ groups[0] % 256,
104
+ Math.floor(groups[1] / 256),
105
+ groups[1] % 256,
106
+ ].join(".");
107
+ }
108
+ function groupsToIpv6Text(groups) {
109
+ return IpCanonicalUtil_1.default.canonicalize(groups
110
+ .map((group) => {
111
+ return group.toString(16);
112
+ })
113
+ .join(":"));
114
+ }
115
+ function isIpv4Mapped(groups) {
116
+ return (groups.slice(0, 5).every((group) => {
117
+ return group === 0;
118
+ }) && groups[5] === 0xffff);
119
+ }
120
+ // The first `prefixLength` bits of the groups kept, the rest cleared.
121
+ function maskGroups(groups, prefixLength) {
122
+ return groups.map((group, index) => {
123
+ const bitsBefore = index * 16;
124
+ if (prefixLength >= bitsBefore + 16) {
125
+ return group;
126
+ }
127
+ if (prefixLength <= bitsBefore) {
128
+ return 0;
129
+ }
130
+ const kept = prefixLength - bitsBefore;
131
+ const mask = (0xffff << (16 - kept)) & 0xffff;
132
+ return group & mask;
133
+ });
134
+ }
135
+ class NetworkAddressBlockUtil {
136
+ /*
137
+ * An address as groups, or null when it is not one. Surrounding white
138
+ * space is forgiven; anything else - a zone ("fe80::1%eth0"), a port, a
139
+ * name - is not an address.
140
+ */
141
+ static readAddress(value) {
142
+ if (typeof value !== "string") {
143
+ return null;
144
+ }
145
+ const text = value.trim();
146
+ if (!text ||
147
+ text.length > exports.MAX_NETWORK_ADDRESS_BLOCK_TEXT_LENGTH ||
148
+ text.includes("%") ||
149
+ !IP_1.default.isIP(text)) {
150
+ return null;
151
+ }
152
+ const ipv4 = readIpv4Groups(text);
153
+ if (ipv4) {
154
+ return { family: 4, groups: ipv4 };
155
+ }
156
+ const ipv6 = readIpv6Groups(text.toLowerCase());
157
+ if (!ipv6) {
158
+ return null;
159
+ }
160
+ if (isIpv4Mapped(ipv6)) {
161
+ return { family: 4, groups: ipv6.slice(6, 8) };
162
+ }
163
+ return { family: 6, groups: ipv6 };
164
+ }
165
+ // An address written the one way blocks are, or null when it is not one.
166
+ static canonicalAddress(value) {
167
+ const address = NetworkAddressBlockUtil.readAddress(value);
168
+ if (!address) {
169
+ return null;
170
+ }
171
+ return address.family === 4
172
+ ? groupsToIpv4Text(address.groups)
173
+ : groupsToIpv6Text(address.groups);
174
+ }
175
+ /*
176
+ * "10.0.0.5", "10.18.167.0/24", "2001:db8::/32" as a block, or null when
177
+ * the text is neither an address nor a subnet. A subnet's length is a
178
+ * whole number of bits the family has (0 to 32, or 0 to 128).
179
+ */
180
+ static parse(value) {
181
+ if (typeof value !== "string") {
182
+ return null;
183
+ }
184
+ const text = value.trim();
185
+ if (!text || text.length > exports.MAX_NETWORK_ADDRESS_BLOCK_TEXT_LENGTH) {
186
+ return null;
187
+ }
188
+ const slash = text.indexOf("/");
189
+ if (slash !== -1 && slash !== text.lastIndexOf("/")) {
190
+ return null;
191
+ }
192
+ const addressText = slash === -1 ? text : text.slice(0, slash);
193
+ const prefixText = slash === -1 ? null : text.slice(slash + 1).trim();
194
+ // A mapped address with a length is an IPv6 subnet, read as one.
195
+ const isMappedSubnet = prefixText !== null &&
196
+ addressText.trim().toLowerCase().includes("::ffff:");
197
+ let address = NetworkAddressBlockUtil.readAddress(addressText);
198
+ if (address && isMappedSubnet && address.family === 4) {
199
+ const ipv6 = readIpv6Groups(addressText.trim().toLowerCase());
200
+ address = ipv6 ? { family: 6, groups: ipv6 } : null;
201
+ }
202
+ if (!address) {
203
+ return null;
204
+ }
205
+ const maxPrefix = address.family === 4 ? 32 : 128;
206
+ let prefixLength = maxPrefix;
207
+ if (prefixText !== null) {
208
+ if (!isDigits(prefixText) || prefixText.length > 3) {
209
+ return null;
210
+ }
211
+ prefixLength = Number(prefixText);
212
+ if (prefixLength > maxPrefix) {
213
+ return null;
214
+ }
215
+ }
216
+ const groups = maskGroups(address.groups, prefixLength);
217
+ const addressPart = address.family === 4
218
+ ? groupsToIpv4Text(groups)
219
+ : groupsToIpv6Text(groups);
220
+ return {
221
+ family: address.family,
222
+ groups: groups,
223
+ prefixLength: prefixLength,
224
+ text: prefixLength === maxPrefix
225
+ ? addressPart
226
+ : `${addressPart}/${prefixLength}`,
227
+ };
228
+ }
229
+ // Whether the block is one address rather than a subnet.
230
+ static isSingleAddress(block) {
231
+ return block.prefixLength === (block.family === 4 ? 32 : 128);
232
+ }
233
+ // Whether an address is in the block (of the same family; IPv4-mapped is IPv4).
234
+ static contains(block, address) {
235
+ const read = NetworkAddressBlockUtil.readAddress(address);
236
+ if (!read || read.family !== block.family) {
237
+ return false;
238
+ }
239
+ const masked = maskGroups(read.groups, block.prefixLength);
240
+ return masked.every((group, index) => {
241
+ return group === block.groups[index];
242
+ });
243
+ }
244
+ /*
245
+ * Of these items, the one whose block holds the address most narrowly
246
+ * (the longest subnet): a /24 named "Mumbai office" says more about
247
+ * 10.18.167.35 than a /8 named "Corporate". The first such item on a tie.
248
+ */
249
+ static mostSpecific(address, items, readBlock) {
250
+ let best = null;
251
+ let bestPrefix = -1;
252
+ for (const item of items) {
253
+ const block = readBlock(item);
254
+ if (block &&
255
+ block.prefixLength > bestPrefix &&
256
+ NetworkAddressBlockUtil.contains(block, address)) {
257
+ best = item;
258
+ bestPrefix = block.prefixLength;
259
+ }
260
+ }
261
+ return best;
262
+ }
263
+ }
264
+ exports.default = NetworkAddressBlockUtil;
@@ -0,0 +1,3 @@
1
+ import commonJsModule from "./NetworkAddressBlock.js";
2
+ export default commonJsModule.default;
3
+ export const MAX_NETWORK_ADDRESS_BLOCK_TEXT_LENGTH = commonJsModule.MAX_NETWORK_ADDRESS_BLOCK_TEXT_LENGTH;