@oneuptime/common 14.0.107 → 14.0.108

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 (129) hide show
  1. package/Models/DatabaseModels/DataBiConnection.d.mts +4 -0
  2. package/Models/DatabaseModels/DataBiConnection.d.ts +4 -0
  3. package/Models/DatabaseModels/DataBiConnection.js +59 -2
  4. package/Models/DatabaseModels/Index.js +2 -0
  5. package/Models/DatabaseModels/RumProductAnalyticsSavedView.d.mts +20 -0
  6. package/Models/DatabaseModels/RumProductAnalyticsSavedView.d.ts +20 -0
  7. package/Models/DatabaseModels/RumProductAnalyticsSavedView.js +353 -0
  8. package/Models/DatabaseModels/RumProductAnalyticsSavedView.mjs +2 -0
  9. package/Models/DatabaseModels/WhatsAppLog.d.mts +3 -0
  10. package/Models/DatabaseModels/WhatsAppLog.d.ts +3 -0
  11. package/Models/DatabaseModels/WhatsAppLog.js +62 -0
  12. package/Models/DatabaseModels/WorkspaceProjectAuthToken.d.mts +11 -0
  13. package/Models/DatabaseModels/WorkspaceProjectAuthToken.d.ts +11 -0
  14. package/Models/DatabaseModels/WorkspaceUserGroup.js +1 -1
  15. package/Server/Utils/Telemetry/NotificationDeliveryMetrics.d.mts +212 -0
  16. package/Server/Utils/Telemetry/NotificationDeliveryMetrics.d.ts +212 -0
  17. package/Server/Utils/Workspace/WorkspaceBase.d.mts +3 -0
  18. package/Server/Utils/Workspace/WorkspaceBase.d.ts +3 -0
  19. package/Types/AI/AIChatTypes.d.mts +2 -1
  20. package/Types/AI/AIChatTypes.d.ts +2 -1
  21. package/Types/AI/AIChatTypes.js +2 -0
  22. package/Types/AI/InvestigationNotStartedReason.d.mts +7 -0
  23. package/Types/AI/InvestigationNotStartedReason.d.ts +7 -0
  24. package/Types/CodeInSentence.d.mts +8 -0
  25. package/Types/CodeInSentence.d.ts +8 -0
  26. package/Types/CodeInSentence.js +875 -0
  27. package/Types/CodeInSentence.mjs +4 -0
  28. package/Types/Dashboard/DashboardComponentType.d.mts +2 -0
  29. package/Types/Dashboard/DashboardComponentType.d.ts +2 -0
  30. package/Types/Dashboard/DashboardComponentType.js +7 -0
  31. package/Types/Dashboard/DashboardComponents/ComponentArgument.d.mts +3 -1
  32. package/Types/Dashboard/DashboardComponents/ComponentArgument.d.ts +3 -1
  33. package/Types/Dashboard/DashboardComponents/ComponentArgument.js +3 -0
  34. package/Types/Dashboard/DashboardComponents/DashboardProductAnalyticsFunnelComponent.d.mts +11 -0
  35. package/Types/Dashboard/DashboardComponents/DashboardProductAnalyticsFunnelComponent.d.ts +11 -0
  36. package/Types/Dashboard/DashboardComponents/DashboardProductAnalyticsFunnelComponent.js +2 -0
  37. package/Types/Dashboard/DashboardComponents/DashboardProductAnalyticsFunnelComponent.mjs +1 -0
  38. package/Types/Dashboard/DashboardComponents/DashboardProductAnalyticsRetentionComponent.d.mts +11 -0
  39. package/Types/Dashboard/DashboardComponents/DashboardProductAnalyticsRetentionComponent.d.ts +11 -0
  40. package/Types/Dashboard/DashboardComponents/DashboardProductAnalyticsRetentionComponent.js +2 -0
  41. package/Types/Dashboard/DashboardComponents/DashboardProductAnalyticsRetentionComponent.mjs +1 -0
  42. package/Types/Dashboard/PublicDashboardServedSettings.js +15 -7
  43. package/Types/DataObservability/DataBiRefreshAlert.d.mts +44 -0
  44. package/Types/DataObservability/DataBiRefreshAlert.d.ts +44 -0
  45. package/Types/DataObservability/DataBiRefreshAlert.js +206 -0
  46. package/Types/DataObservability/DataBiRefreshAlert.mjs +12 -0
  47. package/Types/DataObservability/DataObservabilityApiTypes.d.mts +7 -0
  48. package/Types/DataObservability/DataObservabilityApiTypes.d.ts +7 -0
  49. package/Types/DataObservability/DataObservabilityApiTypes.js +12 -0
  50. package/Types/DataObservability/DataTableLineage.d.mts +22 -1
  51. package/Types/DataObservability/DataTableLineage.d.ts +22 -1
  52. package/Types/DataObservability/DataTableLineage.js +13 -5
  53. package/Types/DataObservability/DataTableLineage.mjs +2 -0
  54. package/Types/HashedString.js +9 -2
  55. package/Types/Monitor/CriteriaFilterValues.d.mts +16 -0
  56. package/Types/Monitor/CriteriaFilterValues.d.ts +16 -0
  57. package/Types/Monitor/CriteriaFilterValues.js +324 -0
  58. package/Types/Monitor/CriteriaFilterValues.mjs +2 -0
  59. package/Types/Monitor/DataBiRefreshMonitorStep.d.mts +13 -0
  60. package/Types/Monitor/DataBiRefreshMonitorStep.d.ts +13 -0
  61. package/Types/Monitor/DataBiRefreshMonitorStep.js +108 -0
  62. package/Types/Monitor/DataBiRefreshMonitorStep.mjs +3 -0
  63. package/Types/Monitor/IncomingEmailMonitor/IncomingEmailMonitorRequest.d.mts +1 -0
  64. package/Types/Monitor/IncomingEmailMonitor/IncomingEmailMonitorRequest.d.ts +1 -0
  65. package/Types/Monitor/MonitorCriteriaInstance.js +22 -2
  66. package/Types/Monitor/MonitorStep.js +28 -11
  67. package/Types/Monitor/MonitorStepMetricMonitor.js +6 -1
  68. package/Types/Monitor/MonitorStepRollingTime.d.mts +12 -0
  69. package/Types/Monitor/MonitorStepRollingTime.d.ts +12 -0
  70. package/Types/Monitor/MonitorStepRollingTime.js +117 -0
  71. package/Types/Monitor/MonitorStepRollingTime.mjs +2 -0
  72. package/Types/Monitor/SeriesContext/SeriesLabelDisplay.js +11 -0
  73. package/Types/Monitor/ServerMonitor/ServerMonitorResponse.d.mts +1 -0
  74. package/Types/Monitor/ServerMonitor/ServerMonitorResponse.d.ts +1 -0
  75. package/Types/Monitor/TelemetryAlertRule.js +7 -2
  76. package/Types/NotificationRule/NotificationRepeat.d.mts +10 -0
  77. package/Types/NotificationRule/NotificationRepeat.d.ts +10 -0
  78. package/Types/NotificationRule/NotificationRepeat.js +51 -0
  79. package/Types/NotificationRule/NotificationRepeat.mjs +2 -0
  80. package/Types/OnCallDutyPolicy/OnCallAcknowledgePage.d.mts +70 -0
  81. package/Types/OnCallDutyPolicy/OnCallAcknowledgePage.d.ts +70 -0
  82. package/Types/OnCallDutyPolicy/OnCallAcknowledgePage.js +276 -0
  83. package/Types/OnCallDutyPolicy/OnCallAcknowledgePage.mjs +12 -0
  84. package/Types/OnCallDutyPolicy/OnCallEscalationWait.d.mts +9 -0
  85. package/Types/OnCallDutyPolicy/OnCallEscalationWait.d.ts +9 -0
  86. package/Types/OnCallDutyPolicy/OnCallEscalationWait.js +44 -0
  87. package/Types/OnCallDutyPolicy/OnCallEscalationWait.mjs +5 -0
  88. package/Types/Probe/ProbeMonitorResponse.d.mts +1 -0
  89. package/Types/Probe/ProbeMonitorResponse.d.ts +1 -0
  90. package/Types/ReadingDirection.d.mts +2 -0
  91. package/Types/ReadingDirection.d.ts +2 -0
  92. package/Types/ReadingDirection.js +221 -25
  93. package/Types/ReadingDirection.mjs +2 -0
  94. package/Types/RollingTime/RollingTimeUtil.d.mts +7 -0
  95. package/Types/RollingTime/RollingTimeUtil.d.ts +7 -0
  96. package/Types/RollingTime/RollingTimeUtil.js +240 -71
  97. package/Types/Rum/ProductAnalyticsSavedViews.d.mts +56 -0
  98. package/Types/Rum/ProductAnalyticsSavedViews.d.ts +56 -0
  99. package/Types/Rum/ProductAnalyticsSavedViews.js +219 -0
  100. package/Types/Rum/ProductAnalyticsSavedViews.mjs +14 -0
  101. package/Types/SecurityEvent/Connectors/SecurityEventConnectorCatalog.js +8 -7
  102. package/Types/Telemetry/ServiceType.d.mts +1 -0
  103. package/Types/Telemetry/ServiceType.d.ts +1 -0
  104. package/Types/Telemetry/ServiceType.js +6 -0
  105. package/Utils/Crypto.js +10 -3
  106. package/Utils/Dashboard/Components/DashboardProductAnalyticsFunnelComponent.d.mts +7 -0
  107. package/Utils/Dashboard/Components/DashboardProductAnalyticsFunnelComponent.d.ts +7 -0
  108. package/Utils/Dashboard/Components/DashboardProductAnalyticsFunnelComponent.js +67 -0
  109. package/Utils/Dashboard/Components/DashboardProductAnalyticsFunnelComponent.mjs +2 -0
  110. package/Utils/Dashboard/Components/DashboardProductAnalyticsRetentionComponent.d.mts +7 -0
  111. package/Utils/Dashboard/Components/DashboardProductAnalyticsRetentionComponent.d.ts +7 -0
  112. package/Utils/Dashboard/Components/DashboardProductAnalyticsRetentionComponent.js +68 -0
  113. package/Utils/Dashboard/Components/DashboardProductAnalyticsRetentionComponent.mjs +2 -0
  114. package/Utils/Dashboard/DashboardWidgetIds.js +6 -1
  115. package/Utils/Metrics/MetricQueryCloudAggregation.js +2 -4
  116. package/Utils/Monitor/MonitorRootCauseWording.js +28 -24
  117. package/Utils/Monitor/MonitorStepMetricQueries.js +2 -1
  118. package/Utils/Monitor/MonitorStepsValuesUtil.d.mts +13 -0
  119. package/Utils/Monitor/MonitorStepsValuesUtil.d.ts +13 -0
  120. package/Utils/Monitor/MonitorStepsValuesUtil.js +80 -0
  121. package/Utils/Monitor/MonitorStepsValuesUtil.mjs +2 -0
  122. package/Utils/Slo/SloProjection.d.mts +18 -0
  123. package/Utils/Slo/SloProjection.d.ts +18 -0
  124. package/Utils/Slo/SloProjection.js +53 -12
  125. package/Utils/Slo/SloProjection.mjs +2 -0
  126. package/Utils/StatusPage/ResourceExplorer.d.mts +0 -10
  127. package/Utils/StatusPage/ResourceExplorer.d.ts +0 -10
  128. package/Utils/StatusPage/ResourceExplorer.js +0 -28
  129. package/package.json +1 -1
@@ -15,7 +15,7 @@
15
15
  * "ku-Latn"), the language otherwise.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getTextReadingDirection = exports.setApartInSentence = exports.isSetApartInSentence = exports.POP_DIRECTIONAL_ISOLATE = exports.FIRST_STRONG_ISOLATE = exports.getTextReadingDirectionByMostLetters = exports.TEXT_DIRECTION_SCAN_LENGTH = exports.isRightToLeftLanguage = exports.getReadingDirection = exports.RIGHT_TO_LEFT_SCRIPTS = exports.RIGHT_TO_LEFT_LANGUAGES = exports.RIGHT_TO_LEFT = exports.LEFT_TO_RIGHT = void 0;
18
+ exports.getTextReadingDirection = exports.setApartInSentence = exports.isSetApartInSentence = exports.POP_DIRECTIONAL_ISOLATE = exports.FIRST_STRONG_ISOLATE = exports.hasEnglishWords = exports.hasRightToLeftWords = exports.getTextReadingDirectionByMostLetters = exports.TEXT_DIRECTION_SCAN_LENGTH = exports.isRightToLeftLanguage = exports.getReadingDirection = exports.RIGHT_TO_LEFT_SCRIPTS = exports.RIGHT_TO_LEFT_LANGUAGES = exports.RIGHT_TO_LEFT = exports.LEFT_TO_RIGHT = void 0;
19
19
  exports.LEFT_TO_RIGHT = "ltr";
20
20
  exports.RIGHT_TO_LEFT = "rtl";
21
21
  // Languages written from right to left, by their primary subtag.
@@ -113,48 +113,244 @@ const FIRST_LETTER_REGEX = /\p{L}/u;
113
113
  const RIGHT_TO_LEFT_LETTER_REGEX = /[\p{Script=Arabic}\p{Script=Hebrew}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}\p{Script=Adlam}\p{Script=Hanifi_Rohingya}\p{Script=Mandaic}\p{Script=Samaritan}]/u;
114
114
  // One letter, of any script.
115
115
  const LETTER_REGEX = /^\p{L}$/u;
116
+ // Each isolate's opening mark: LRI, RLI, FSI.
117
+ const ISOLATE_INITIATOR_REGEX = /^[\u{2066}-\u{2068}]$/u;
116
118
  /*
117
- * WHICH WAY A TEXT SHOWN ON A PAGE IS READ: the way most of its letters
118
- * read. A name, a description or a paragraph of a note is shown, not typed,
119
- * so it can be read as a whole: "`kubectl` را اجرا کنید" and "API پرداخت از
120
- * کار افتاده" are Persian sentences that start with an English word, and
121
- * laid out from that first letter their Persian words came out in the
122
- * wrong order. "Checkout API (EU)" and "Rolled back v2.4.1." read left to
123
- * right, their full stop at their end. A tie goes to the first letter.
124
- * Null when there is no letter, so the text follows the page; only the
125
- * first TEXT_DIRECTION_SCAN_LENGTH characters are read.
119
+ * A web address: a scheme from the start of a word ("https://",
120
+ * "s3://"), up to the next space or isolate mark.
126
121
  */
127
- const getTextReadingDirectionByMostLetters = (text) => {
128
- if (!text) {
129
- return null;
122
+ const WEB_ADDRESS_REGEX = /(?<![A-Za-z0-9+.-])[A-Za-z][A-Za-z0-9+.-]{0,31}:\/\/[^\s\u{2066}-\u{2069}]*/gu;
123
+ const getDirectionByCount = (count) => {
124
+ if (count.rightToLeft === count.leftToRight) {
125
+ return count.first;
130
126
  }
131
- let rightToLeftLetters = 0;
132
- let leftToRightLetters = 0;
133
- let firstLetterDirection = null;
127
+ return count.rightToLeft > count.leftToRight ? exports.RIGHT_TO_LEFT : exports.LEFT_TO_RIGHT;
128
+ };
129
+ const countLetters = (text) => {
130
+ const outside = { rightToLeft: 0, leftToRight: 0, first: null };
131
+ const inside = { rightToLeft: 0, leftToRight: 0, first: null };
132
+ // How many isolates the scan is in.
133
+ let depth = 0;
134
+ // Each address counted as if it were set apart.
135
+ const scanned = text
136
+ .slice(0, exports.TEXT_DIRECTION_SCAN_LENGTH)
137
+ .replace(WEB_ADDRESS_REGEX, (address) => {
138
+ return `${exports.FIRST_STRONG_ISOLATE}${address}${exports.POP_DIRECTIONAL_ISOLATE}`;
139
+ });
134
140
  // By code point, so a letter outside the Basic Multilingual Plane counts once.
135
- for (const character of text.slice(0, exports.TEXT_DIRECTION_SCAN_LENGTH)) {
141
+ for (const character of scanned) {
142
+ if (ISOLATE_INITIATOR_REGEX.test(character)) {
143
+ depth++;
144
+ continue;
145
+ }
146
+ // A PDI with no isolate open closes nothing.
147
+ if (character === exports.POP_DIRECTIONAL_ISOLATE) {
148
+ depth = Math.max(0, depth - 1);
149
+ continue;
150
+ }
136
151
  if (!LETTER_REGEX.test(character)) {
137
152
  continue;
138
153
  }
139
154
  const direction = RIGHT_TO_LEFT_LETTER_REGEX.test(character)
140
155
  ? exports.RIGHT_TO_LEFT
141
156
  : exports.LEFT_TO_RIGHT;
157
+ const count = depth > 0 ? inside : outside;
142
158
  if (direction === exports.RIGHT_TO_LEFT) {
143
- rightToLeftLetters++;
159
+ count.rightToLeft++;
144
160
  }
145
161
  else {
146
- leftToRightLetters++;
162
+ count.leftToRight++;
147
163
  }
148
- firstLetterDirection = firstLetterDirection || direction;
164
+ count.first = count.first || direction;
149
165
  }
150
- if (rightToLeftLetters === leftToRightLetters) {
151
- return firstLetterDirection;
166
+ return { outside, inside };
167
+ };
168
+ const getTextReadingDirectionByMostLetters = (text) => {
169
+ if (!text) {
170
+ return null;
152
171
  }
153
- return rightToLeftLetters > leftToRightLetters
154
- ? exports.RIGHT_TO_LEFT
155
- : exports.LEFT_TO_RIGHT;
172
+ const counts = countLetters(text);
173
+ return (getDirectionByCount(counts.outside) || getDirectionByCount(counts.inside));
156
174
  };
157
175
  exports.getTextReadingDirectionByMostLetters = getTextReadingDirectionByMostLetters;
176
+ /*
177
+ * WHETHER A TEXT HAS WORDS OF A RIGHT-TO-LEFT SCRIPT OF ITS OWN: a letter
178
+ * of one outside what it sets apart - an isolate, a web address - counted
179
+ * as getTextReadingDirectionByMostLetters counts. An Arabic or Persian
180
+ * sentence has, however many names, paths and commands it gives in Latin
181
+ * letters ("Microsoft Teams غير متصل بعد!"); an English sentence has not,
182
+ * nor one that sets a Persian name apart. Only the first
183
+ * TEXT_DIRECTION_SCAN_LENGTH characters are read.
184
+ */
185
+ const hasRightToLeftWords = (text) => {
186
+ return Boolean(text) && countLetters(text).outside.rightToLeft > 0;
187
+ };
188
+ exports.hasRightToLeftWords = hasRightToLeftWords;
189
+ /*
190
+ * WHETHER A TEXT HAS ENGLISH WORDS OF ITS OWN: whether it is an English
191
+ * sentence, not a name or a label in Latin letters. An answer from the
192
+ * server is English, and it may quote a name someone typed in Arabic or
193
+ * Persian ("A custom channel named قناة الطوارئ already exists."), so it
194
+ * has right-to-left letters of its own too (hasRightToLeftWords). What
195
+ * tells it from an Arabic sentence that names products ("Microsoft Teams
196
+ * غير متصل بعد!") are the small words an English sentence is made of: "is",
197
+ * "the", "already", "not" (ENGLISH_SENTENCE_WORDS). One counts when it is
198
+ * written in lower case outside what the text sets apart in an isolate,
199
+ * quotes, marks as code or in bold, or leaves to a value ({{name}}), and
200
+ * is not inside a name written in Title Case ("Red Hat OpenStack Services
201
+ * on OpenShift", "Add an Integration"). Only the first
202
+ * TEXT_DIRECTION_SCAN_LENGTH characters are read.
203
+ */
204
+ const ENGLISH_SENTENCE_WORDS = new Set([
205
+ "already",
206
+ "also",
207
+ "an",
208
+ "and",
209
+ "another",
210
+ "any",
211
+ "are",
212
+ "aren't",
213
+ "as",
214
+ "at",
215
+ "be",
216
+ "been",
217
+ "but",
218
+ "by",
219
+ "can",
220
+ "can't",
221
+ "cannot",
222
+ "could",
223
+ "couldn't",
224
+ "did",
225
+ "do",
226
+ "does",
227
+ "doesn't",
228
+ "don't",
229
+ "each",
230
+ "every",
231
+ "for",
232
+ "from",
233
+ "had",
234
+ "has",
235
+ "have",
236
+ "here",
237
+ "how",
238
+ "if",
239
+ "in",
240
+ "into",
241
+ "is",
242
+ "isn't",
243
+ "it",
244
+ "it's",
245
+ "its",
246
+ "may",
247
+ "must",
248
+ "no",
249
+ "not",
250
+ "of",
251
+ "on",
252
+ "only",
253
+ "or",
254
+ "other",
255
+ "our",
256
+ "please",
257
+ "should",
258
+ "so",
259
+ "some",
260
+ "than",
261
+ "that",
262
+ "the",
263
+ "their",
264
+ "then",
265
+ "there",
266
+ "these",
267
+ "they",
268
+ "this",
269
+ "those",
270
+ "to",
271
+ "too",
272
+ "was",
273
+ "wasn't",
274
+ "we",
275
+ "were",
276
+ "what",
277
+ "when",
278
+ "where",
279
+ "which",
280
+ "who",
281
+ "will",
282
+ "with",
283
+ "won't",
284
+ "would",
285
+ "yet",
286
+ "you",
287
+ "your",
288
+ ]);
289
+ /*
290
+ * What a text quotes, marks as code or in bold, or leaves to a value: not
291
+ * its own words. Each kind opens with its own sign and is read no further
292
+ * than 256 characters for its close.
293
+ */
294
+ const QUOTED_OR_CODE_REGEX = /\{\{[^{}]{0,256}\}\}|`[^`]{0,256}`|\*\*[^*]{0,256}\*\*|\u{00AB}[^\u{00AB}\u{00BB}]{0,256}\u{00BB}|\u{201C}[^\u{201C}\u{201D}]{0,256}\u{201D}|"[^"]{0,256}"/gu;
295
+ const SPACES_REGEX = /\s+/u;
296
+ const CURLY_APOSTROPHE_REGEX = /\u{2019}/gu;
297
+ // A Latin letter, or an apostrophe inside a word ("isn't", "it’s").
298
+ const isWordCharacter = (character) => {
299
+ return ((character >= "a" && character <= "z") ||
300
+ (character >= "A" && character <= "Z") ||
301
+ character === "'" ||
302
+ character === "\u{2019}");
303
+ };
304
+ // A piece of text between spaces without the signs round it: "exists." is "exists".
305
+ const getWordOf = (piece) => {
306
+ let start = 0;
307
+ let end = piece.length;
308
+ while (start < end && !isWordCharacter(piece.charAt(start))) {
309
+ start++;
310
+ }
311
+ while (end > start && !isWordCharacter(piece.charAt(end - 1))) {
312
+ end--;
313
+ }
314
+ return piece.slice(start, end).replace(CURLY_APOSTROPHE_REGEX, "'");
315
+ };
316
+ const isTitleCaseWord = (word) => {
317
+ const first = word ? word.charAt(0) : "";
318
+ return first >= "A" && first <= "Z";
319
+ };
320
+ const hasEnglishWords = (text) => {
321
+ if (!text) {
322
+ return false;
323
+ }
324
+ /*
325
+ * The text outside its isolates, with a space where each was. A web
326
+ * address holds no word of its own: it runs to the next space.
327
+ */
328
+ let ownText = "";
329
+ let depth = 0;
330
+ for (const character of text.slice(0, exports.TEXT_DIRECTION_SCAN_LENGTH)) {
331
+ if (ISOLATE_INITIATOR_REGEX.test(character)) {
332
+ ownText += depth === 0 ? " " : "";
333
+ depth++;
334
+ continue;
335
+ }
336
+ if (character === exports.POP_DIRECTIONAL_ISOLATE) {
337
+ depth = Math.max(0, depth - 1);
338
+ continue;
339
+ }
340
+ if (depth === 0) {
341
+ ownText += character;
342
+ }
343
+ }
344
+ const words = ownText
345
+ .replace(QUOTED_OR_CODE_REGEX, " ")
346
+ .split(SPACES_REGEX)
347
+ .map(getWordOf);
348
+ return words.some((word, index) => {
349
+ return (ENGLISH_SENTENCE_WORDS.has(word) &&
350
+ !(isTitleCaseWord(words[index - 1]) && isTitleCaseWord(words[index + 1])));
351
+ });
352
+ };
353
+ exports.hasEnglishWords = hasEnglishWords;
158
354
  /*
159
355
  * A VALUE PUT INTO A SENTENCE, SET APART FROM IT.
160
356
  *
@@ -9,6 +9,8 @@ export const TEXT_DIRECTION_SCAN_LENGTH = commonJsModule.TEXT_DIRECTION_SCAN_LEN
9
9
  export const getReadingDirection = commonJsModule.getReadingDirection;
10
10
  export const getTextReadingDirection = commonJsModule.getTextReadingDirection;
11
11
  export const getTextReadingDirectionByMostLetters = commonJsModule.getTextReadingDirectionByMostLetters;
12
+ export const hasEnglishWords = commonJsModule.hasEnglishWords;
13
+ export const hasRightToLeftWords = commonJsModule.hasRightToLeftWords;
12
14
  export const isRightToLeftLanguage = commonJsModule.isRightToLeftLanguage;
13
15
  export const isSetApartInSentence = commonJsModule.isSetApartInSentence;
14
16
  export const setApartInSentence = commonJsModule.setApartInSentence;
@@ -2,6 +2,13 @@ import InBetween from "../BaseDatabase/InBetween.mjs";
2
2
  import RollingTime from "./RollingTime.mjs";
3
3
  export default class RollingTimeUtil {
4
4
  static getDefault(): RollingTime;
5
+ static isRollingTime(value: unknown): value is RollingTime;
6
+ static fromValue(value: unknown): RollingTime | null;
7
+ static fromWindowInMs(windowInMs: number): RollingTime | null;
8
+ static fromValueOrDefault(value: unknown): RollingTime;
9
+ static getValuesText(): string;
5
10
  static convertToStartAndEndDate(rollingTime: RollingTime, endDate?: Date): InBetween<Date>;
6
11
  static getWindowInMs(rollingTime: RollingTime): number;
12
+ private static readIso8601Duration;
13
+ private static readLengthInWords;
7
14
  }
@@ -2,6 +2,13 @@ import InBetween from "../BaseDatabase/InBetween";
2
2
  import RollingTime from "./RollingTime";
3
3
  export default class RollingTimeUtil {
4
4
  static getDefault(): RollingTime;
5
+ static isRollingTime(value: unknown): value is RollingTime;
6
+ static fromValue(value: unknown): RollingTime | null;
7
+ static fromWindowInMs(windowInMs: number): RollingTime | null;
8
+ static fromValueOrDefault(value: unknown): RollingTime;
9
+ static getValuesText(): string;
5
10
  static convertToStartAndEndDate(rollingTime: RollingTime, endDate?: Date): InBetween<Date>;
6
11
  static getWindowInMs(rollingTime: RollingTime): number;
12
+ private static readIso8601Duration;
13
+ private static readLengthInWords;
7
14
  }
@@ -6,94 +6,263 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const InBetween_1 = __importDefault(require("../BaseDatabase/InBetween"));
7
7
  const Date_1 = __importDefault(require("../Date"));
8
8
  const RollingTime_1 = __importDefault(require("./RollingTime"));
9
+ const MINUTES_IN_A_DAY = 24 * 60;
10
+ /*
11
+ * How long each rolling time's window is, in minutes. A Record over the
12
+ * enum, so a rolling time added without a length does not compile: a value
13
+ * this did not know read as a window of no length at all, which finds no
14
+ * data on any check.
15
+ *
16
+ * Days are fixed lengths, 24 hours a day, not calendar days: in a zone
17
+ * whose clocks change inside the window, N calendar days back is an hour
18
+ * more or less than N days. Past 1, 3 and 7 Days and Past 180 Days sit
19
+ * exactly on the edge of a bucket width (AggregationIntervalUtil), so in
20
+ * London after the clocks went back on 2026-10-25 Past 3 Days was bucketed
21
+ * by the hour instead of every 30 minutes - in the browser, and on any
22
+ * server not in UTC - and getWindowInMs, which stepped back from
23
+ * 1970-01-01, read Past 90 and 180 Days an hour long in New York.
24
+ */
25
+ const WINDOW_IN_MINUTES = {
26
+ [RollingTime_1.default.Past1Minute]: 1,
27
+ [RollingTime_1.default.Past5Minutes]: 5,
28
+ [RollingTime_1.default.Past10Minutes]: 10,
29
+ [RollingTime_1.default.Past15Minutes]: 15,
30
+ [RollingTime_1.default.Past30Minutes]: 30,
31
+ [RollingTime_1.default.Past1Hour]: 60,
32
+ [RollingTime_1.default.Past2Hours]: 2 * 60,
33
+ [RollingTime_1.default.Past3Hours]: 3 * 60,
34
+ [RollingTime_1.default.Past6Hours]: 6 * 60,
35
+ [RollingTime_1.default.Past12Hours]: 12 * 60,
36
+ // "Past 1 Day": the key's name is older than its value.
37
+ [RollingTime_1.default.Past1Hours]: MINUTES_IN_A_DAY,
38
+ [RollingTime_1.default.Past2Days]: 2 * MINUTES_IN_A_DAY,
39
+ [RollingTime_1.default.Past3Days]: 3 * MINUTES_IN_A_DAY,
40
+ [RollingTime_1.default.Past7Days]: 7 * MINUTES_IN_A_DAY,
41
+ [RollingTime_1.default.Past14Days]: 14 * MINUTES_IN_A_DAY,
42
+ [RollingTime_1.default.Past30Days]: 30 * MINUTES_IN_A_DAY,
43
+ [RollingTime_1.default.Past60Days]: 60 * MINUTES_IN_A_DAY,
44
+ [RollingTime_1.default.Past90Days]: 90 * MINUTES_IN_A_DAY,
45
+ [RollingTime_1.default.Past180Days]: 180 * MINUTES_IN_A_DAY,
46
+ [RollingTime_1.default.Past365Days]: 365 * MINUTES_IN_A_DAY,
47
+ };
48
+ const ROLLING_TIMES = Object.values(RollingTime_1.default);
49
+ /*
50
+ * The longest text read as a length of time. The longest way of writing
51
+ * one ("previous 31536000 seconds", "P52W1DT0H0M0S") is a few dozen
52
+ * characters; a longer text is not one, and is never handed to a pattern.
53
+ */
54
+ const MAX_LENGTH_TEXT_LENGTH = 64;
55
+ /*
56
+ * The enum's own name for Past 1 Day, "Past1Hours", whose words say an
57
+ * hour. Whoever wrote it meant one or the other, and which is not for
58
+ * OneUptime to guess: it reads as neither.
59
+ */
60
+ const KEY_NAME_THAT_SAYS_ANOTHER_LENGTH = "past1hours";
61
+ /*
62
+ * A length written in words or short units - "15 minutes", "Past 15
63
+ * Minutes", "last 15m", "15min", "24h", "past hour" - read from text that
64
+ * is already lower case, with each run of spaces, dashes and underscores
65
+ * one space. Anchored at both ends, with every repeat bounded, so it reads
66
+ * in time in line with the text (as does ISO_8601_DURATION below) - and
67
+ * it is never handed more than MAX_LENGTH_TEXT_LENGTH characters.
68
+ */
69
+ const LENGTH_IN_WORDS = /^(?:(past|last|previous) ?)?(\d{1,9}(?:\.\d{1,9})?)? ?([a-z]{1,7})$/;
70
+ /*
71
+ * An ISO 8601 duration without years or months, which have no fixed
72
+ * length: "PT15M", "PT1H", "P1D", "P1W", "PT24H". Read lower case. Each
73
+ * part ends at its own letter.
74
+ */
75
+ const ISO_8601_DURATION = /^p(?:(\d{1,9})w)?(?:(\d{1,9})d)?(?:t(?:(\d{1,9})h)?(?:(\d{1,9})m)?(?:(\d{1,9})s)?)?$/;
76
+ // Each unit a length may be written in, in seconds.
77
+ const UNIT_IN_SECONDS = {
78
+ s: 1,
79
+ sec: 1,
80
+ secs: 1,
81
+ second: 1,
82
+ seconds: 1,
83
+ m: 60,
84
+ min: 60,
85
+ mins: 60,
86
+ minute: 60,
87
+ minutes: 60,
88
+ h: 60 * 60,
89
+ hr: 60 * 60,
90
+ hrs: 60 * 60,
91
+ hour: 60 * 60,
92
+ hours: 60 * 60,
93
+ d: 24 * 60 * 60,
94
+ day: 24 * 60 * 60,
95
+ days: 24 * 60 * 60,
96
+ w: 7 * 24 * 60 * 60,
97
+ wk: 7 * 24 * 60 * 60,
98
+ wks: 7 * 24 * 60 * 60,
99
+ week: 7 * 24 * 60 * 60,
100
+ weeks: 7 * 24 * 60 * 60,
101
+ };
102
+ // The units "past" or "last" may stand before with no number: "past hour".
103
+ const UNITS_WITHOUT_A_NUMBER = [
104
+ "minute",
105
+ "hour",
106
+ "day",
107
+ "week",
108
+ ];
9
109
  class RollingTimeUtil {
10
110
  static getDefault() {
11
111
  return RollingTime_1.default.Past1Minute;
12
112
  }
113
+ // Whether a value is a rolling time exactly as OneUptime writes it.
114
+ static isRollingTime(value) {
115
+ return ROLLING_TIMES.includes(value);
116
+ }
13
117
  /*
14
- * The window a rolling time covers, ending now - or at `endDate` when a
15
- * caller needs it to end earlier (a telemetry check while OneUptime's
16
- * ingest queue is behind, issue #2825).
118
+ * The rolling time a value means, or null when it means none.
119
+ *
120
+ * A monitor's steps are stored as JSON, and the API, Terraform, MCP, a
121
+ * workflow or an AI writing them can spell a rolling time its own way.
122
+ * A Metrics monitor created through the MCP server stored "15 minutes":
123
+ * nothing read it, so every check judged a window of no length, found
124
+ * no data, and its no-data rule opened an alert on every run - while its
125
+ * charts showed nothing in one place and data in another.
126
+ *
127
+ * Read here:
128
+ * - each rolling time as OneUptime writes it ("Past 15 Minutes"), in
129
+ * any case and spacing, with dashes or underscores between words;
130
+ * - a number and a unit, after "past", "last" or "previous" or not:
131
+ * "15 minutes", "15 mins", "15m", "last 15 minutes", "24h", "1 week";
132
+ * - "past" or "last" and a unit: "past hour", "last day";
133
+ * - an ISO 8601 duration: "PT15M", "PT1H", "P1D", "P1W".
134
+ *
135
+ * A length is read as the rolling time exactly as long: "60 minutes" is
136
+ * Past 1 Hour, "24 hours" Past 1 Day, "2 weeks" Past 14 Days. A length
137
+ * no rolling time is as long as ("20 minutes"), a month or a year (which
138
+ * have no fixed length), a number with no unit, the enum's key name
139
+ * "Past1Hours" (above), and anything else is null - for the caller to
140
+ * refuse, or to read as the default.
17
141
  */
18
- static convertToStartAndEndDate(rollingTime, endDate = Date_1.default.getCurrentDate()) {
19
- let startDate = endDate;
20
- if (rollingTime === RollingTime_1.default.Past1Minute) {
21
- startDate = Date_1.default.addRemoveMinutes(endDate, -1);
22
- }
23
- if (rollingTime === RollingTime_1.default.Past5Minutes) {
24
- startDate = Date_1.default.addRemoveMinutes(endDate, -5);
25
- }
26
- if (rollingTime === RollingTime_1.default.Past10Minutes) {
27
- startDate = Date_1.default.addRemoveMinutes(endDate, -10);
28
- }
29
- if (rollingTime === RollingTime_1.default.Past15Minutes) {
30
- startDate = Date_1.default.addRemoveMinutes(endDate, -15);
31
- }
32
- if (rollingTime === RollingTime_1.default.Past30Minutes) {
33
- startDate = Date_1.default.addRemoveMinutes(endDate, -30);
142
+ static fromValue(value) {
143
+ var _a;
144
+ if (RollingTimeUtil.isRollingTime(value)) {
145
+ return value;
34
146
  }
35
- if (rollingTime === RollingTime_1.default.Past1Hour) {
36
- startDate = Date_1.default.addRemoveHours(endDate, -1);
147
+ if (typeof value !== "string") {
148
+ return null;
37
149
  }
38
- if (rollingTime === RollingTime_1.default.Past2Hours) {
39
- startDate = Date_1.default.addRemoveHours(endDate, -2);
150
+ const trimmed = value.trim();
151
+ if (trimmed.length === 0 || trimmed.length > MAX_LENGTH_TEXT_LENGTH) {
152
+ return null;
40
153
  }
41
- if (rollingTime === RollingTime_1.default.Past3Hours) {
42
- startDate = Date_1.default.addRemoveHours(endDate, -3);
154
+ const text = trimmed
155
+ .toLowerCase()
156
+ .replace(/[\s_-]+/g, " ")
157
+ .trim();
158
+ if (text === KEY_NAME_THAT_SAYS_ANOTHER_LENGTH) {
159
+ return null;
43
160
  }
44
- if (rollingTime === RollingTime_1.default.Past6Hours) {
45
- startDate = Date_1.default.addRemoveHours(endDate, -6);
161
+ const lengthInSeconds = (_a = RollingTimeUtil.readIso8601Duration(text)) !== null && _a !== void 0 ? _a : RollingTimeUtil.readLengthInWords(text);
162
+ if (lengthInSeconds === null) {
163
+ return null;
46
164
  }
47
- if (rollingTime === RollingTime_1.default.Past12Hours) {
48
- startDate = Date_1.default.addRemoveHours(endDate, -12);
49
- }
50
- /*
51
- * Days are fixed lengths, 24 hours a day, not calendar days: in a zone
52
- * whose clocks change inside the window, N calendar days back is an hour
53
- * more or less than N days. Past 1, 3 and 7 Days and Past 180 Days sit
54
- * exactly on the edge of a bucket width (AggregationIntervalUtil), so in
55
- * London after the clocks went back on 2026-10-25 Past 3 Days was
56
- * bucketed by the hour instead of every 30 minutes - in the browser, and
57
- * on any server not in UTC - and getWindowInMs, which steps back from
58
- * 1970-01-01, read Past 90 and 180 Days an hour long in New York.
59
- */
60
- if (rollingTime === RollingTime_1.default.Past1Hours) {
61
- startDate = Date_1.default.addRemoveHours(endDate, -24);
62
- }
63
- if (rollingTime === RollingTime_1.default.Past2Days) {
64
- startDate = Date_1.default.addRemoveHours(endDate, -2 * 24);
65
- }
66
- if (rollingTime === RollingTime_1.default.Past3Days) {
67
- startDate = Date_1.default.addRemoveHours(endDate, -3 * 24);
68
- }
69
- if (rollingTime === RollingTime_1.default.Past7Days) {
70
- startDate = Date_1.default.addRemoveHours(endDate, -7 * 24);
71
- }
72
- if (rollingTime === RollingTime_1.default.Past14Days) {
73
- startDate = Date_1.default.addRemoveHours(endDate, -14 * 24);
165
+ return RollingTimeUtil.fromWindowInMs(Math.round(lengthInSeconds * 1000));
166
+ }
167
+ // The rolling time whose window is exactly this long, or null.
168
+ static fromWindowInMs(windowInMs) {
169
+ if (!Number.isFinite(windowInMs) || windowInMs <= 0) {
170
+ return null;
74
171
  }
75
- if (rollingTime === RollingTime_1.default.Past30Days) {
76
- startDate = Date_1.default.addRemoveHours(endDate, -30 * 24);
172
+ return (ROLLING_TIMES.find((rollingTime) => {
173
+ return WINDOW_IN_MINUTES[rollingTime] * 60 * 1000 === windowInMs;
174
+ }) || null);
175
+ }
176
+ /*
177
+ * The rolling time a value means, or the default (Past 1 Minute) - the
178
+ * window a step read with no rolling time has always had - when it means
179
+ * none. Never a window of no length.
180
+ */
181
+ static fromValueOrDefault(value) {
182
+ return RollingTimeUtil.fromValue(value) || RollingTimeUtil.getDefault();
183
+ }
184
+ /*
185
+ * Every rolling time, quoted and listed for a sentence: "Past 1 Minute",
186
+ * "Past 5 Minutes", ... or "Past 365 Days".
187
+ */
188
+ static getValuesText() {
189
+ const quoted = ROLLING_TIMES.map((rollingTime) => {
190
+ return `"${rollingTime}"`;
191
+ });
192
+ return `${quoted.slice(0, -1).join(", ")} or ${quoted[quoted.length - 1]}`;
193
+ }
194
+ /*
195
+ * The window a rolling time covers, ending now - or at `endDate` when a
196
+ * caller needs it to end earlier (a telemetry check while OneUptime's
197
+ * ingest queue is behind, issue #2825). A value that is no rolling time
198
+ * covers the default's window (fromValueOrDefault), never one of no
199
+ * length.
200
+ */
201
+ static convertToStartAndEndDate(rollingTime, endDate = Date_1.default.getCurrentDate()) {
202
+ const startDate = Date_1.default.addRemoveMinutes(endDate, -WINDOW_IN_MINUTES[RollingTimeUtil.fromValueOrDefault(rollingTime)]);
203
+ return new InBetween_1.default(startDate, endDate);
204
+ }
205
+ // How long a rolling time's window is, in milliseconds.
206
+ static getWindowInMs(rollingTime) {
207
+ return (WINDOW_IN_MINUTES[RollingTimeUtil.fromValueOrDefault(rollingTime)] *
208
+ 60 *
209
+ 1000);
210
+ }
211
+ static readIso8601Duration(text) {
212
+ const match = ISO_8601_DURATION.exec(text);
213
+ if (!match) {
214
+ return null;
77
215
  }
78
- if (rollingTime === RollingTime_1.default.Past60Days) {
79
- startDate = Date_1.default.addRemoveHours(endDate, -60 * 24);
216
+ // Weeks, days, hours, minutes and seconds, in the order they are written.
217
+ const partUnits = [
218
+ UNIT_IN_SECONDS["week"],
219
+ UNIT_IN_SECONDS["day"],
220
+ UNIT_IN_SECONDS["hour"],
221
+ UNIT_IN_SECONDS["minute"],
222
+ UNIT_IN_SECONDS["second"],
223
+ ];
224
+ let lengthInSeconds = 0;
225
+ let hasPart = false;
226
+ partUnits.forEach((unitInSeconds, index) => {
227
+ const part = match[index + 1];
228
+ if (part !== undefined) {
229
+ hasPart = true;
230
+ lengthInSeconds += Number(part) * unitInSeconds;
231
+ }
232
+ });
233
+ // "P" or "PT" alone is no length, nor is a "T" with no time after it.
234
+ const hasTimePart = match[3] !== undefined ||
235
+ match[4] !== undefined ||
236
+ match[5] !== undefined;
237
+ if (!hasPart || (text.includes("t") && !hasTimePart)) {
238
+ return null;
80
239
  }
81
- if (rollingTime === RollingTime_1.default.Past90Days) {
82
- startDate = Date_1.default.addRemoveHours(endDate, -90 * 24);
240
+ return lengthInSeconds;
241
+ }
242
+ static readLengthInWords(text) {
243
+ const match = LENGTH_IN_WORDS.exec(text);
244
+ if (!match) {
245
+ return null;
83
246
  }
84
- if (rollingTime === RollingTime_1.default.Past180Days) {
85
- startDate = Date_1.default.addRemoveHours(endDate, -180 * 24);
247
+ const lookBack = match[1];
248
+ const count = match[2];
249
+ const unit = match[3];
250
+ const unitInSeconds = Object.prototype.hasOwnProperty.call(UNIT_IN_SECONDS, unit)
251
+ ? UNIT_IN_SECONDS[unit]
252
+ : undefined;
253
+ if (unitInSeconds === undefined) {
254
+ return null;
86
255
  }
87
- if (rollingTime === RollingTime_1.default.Past365Days) {
88
- startDate = Date_1.default.addRemoveHours(endDate, -365 * 24);
256
+ if (count === undefined) {
257
+ /*
258
+ * "past hour" is an hour; "hour" alone, or "past h", is not
259
+ * written as a length.
260
+ */
261
+ return lookBack && UNITS_WITHOUT_A_NUMBER.includes(unit)
262
+ ? unitInSeconds
263
+ : null;
89
264
  }
90
- return new InBetween_1.default(startDate, endDate);
91
- }
92
- // How long a rolling time's window is, in milliseconds.
93
- static getWindowInMs(rollingTime) {
94
- const endDate = new Date(0);
95
- const window = this.convertToStartAndEndDate(rollingTime, endDate);
96
- return endDate.getTime() - window.startValue.getTime();
265
+ return Number(count) * unitInSeconds;
97
266
  }
98
267
  }
99
268
  exports.default = RollingTimeUtil;