@oneuptime/common 12.0.13 → 12.0.14
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.
- package/Models/DatabaseModels/OnCallDutyPolicySchedule.ts +14 -0
- package/Models/DatabaseModels/UserCall.ts +94 -3
- package/Models/DatabaseModels/UserEmail.ts +94 -3
- package/Models/DatabaseModels/UserIncomingCallNumber.ts +94 -3
- package/Models/DatabaseModels/UserPush.ts +37 -0
- package/Models/DatabaseModels/UserSMS.ts +94 -3
- package/Models/DatabaseModels/UserWhatsApp.ts +93 -2
- package/Server/API/BaseAPI.ts +79 -14
- package/Server/API/UserCallAPI.ts +53 -45
- package/Server/API/UserEmailAPI.ts +53 -44
- package/Server/API/UserIncomingCallNumberAPI.ts +48 -38
- package/Server/API/UserNotificationMethodAdminAPI.ts +481 -0
- package/Server/API/UserPushAPI.ts +126 -2
- package/Server/API/UserSmsAPI.ts +53 -44
- package/Server/API/UserWhatsAppAPI.ts +53 -50
- package/Server/Infrastructure/Postgres/SchemaMigrations/1787142779538-MigrationName.ts +154 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1787156982416-MigrationName.ts +17 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1787700000000-FixTotpOtpUrlAlgorithm.ts +45 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +6 -0
- package/Server/Middleware/VerificationCodeRateLimit.ts +586 -0
- package/Server/Services/AnalyticsDatabaseService.ts +169 -0
- package/Server/Services/DatabaseService.ts +101 -0
- package/Server/Services/LogAggregationService.ts +5 -0
- package/Server/Services/PushNotificationService.ts +127 -12
- package/Server/Services/TeamMemberService.ts +53 -13
- package/Server/Services/UserCallService.ts +55 -24
- package/Server/Services/UserEmailService.ts +83 -17
- package/Server/Services/UserIncomingCallNumberService.ts +49 -85
- package/Server/Services/UserNotificationMethodAdminService.ts +1527 -0
- package/Server/Services/UserNotificationRuleService.ts +26 -0
- package/Server/Services/UserPushService.ts +89 -0
- package/Server/Services/UserSmsService.ts +50 -17
- package/Server/Services/UserWhatsAppService.ts +48 -15
- package/Server/Types/Database/QueryHelper.ts +30 -0
- package/Server/Utils/AnalyticsDatabase/QuerySettingsHelper.ts +59 -0
- package/Server/Utils/ChannelVerification.ts +510 -0
- package/Server/Utils/Monitor/Criteria/IncomingRequestCriteria.ts +13 -16
- package/Server/Utils/Monitor/MonitorAlert.ts +24 -21
- package/Server/Utils/Monitor/MonitorIncident.ts +21 -18
- package/Server/Utils/Monitor/MonitorResourceContext.ts +107 -0
- package/Server/Utils/Monitor/MonitorStepResourceIdentity.ts +442 -0
- package/Server/Utils/Monitor/SeriesResourceLabels.ts +3 -3
- package/Server/Utils/Monitor/SeriesResourceLinker.ts +96 -28
- package/Server/Utils/TotpAuth.ts +137 -9
- package/Server/Utils/UserRegistrationToken.ts +182 -0
- package/Server/Utils/VerificationCode.ts +134 -0
- package/Tests/App/Dashboard/AdminNotificationRulesPage.test.tsx +173 -94
- package/Tests/App/Dashboard/AdminUserNotificationMethodsPage.test.tsx +1151 -0
- package/Tests/App/Dashboard/AdminUserOnCallPages.test.tsx +905 -0
- package/Tests/App/Dashboard/DashboardCommandPalette.test.tsx +338 -0
- package/Tests/App/Dashboard/InvestigationPanel.test.tsx +1 -1
- package/Tests/App/Dashboard/MonitorTypePicker.test.tsx +28 -0
- package/Tests/Models/UserPushCriticalAlertColumn.test.ts +172 -0
- package/Tests/Server/API/BaseAPIGetListParallel.test.ts +519 -0
- package/Tests/Server/API/NotificationChannelVerificationAPI.test.ts +543 -0
- package/Tests/Server/API/UserIncomingCallNumberApi.test.ts +108 -18
- package/Tests/Server/API/UserNotificationMethodAdminAPI.test.ts +963 -0
- package/Tests/Server/API/UserPushCriticalAlertsApi.test.ts +114 -0
- package/Tests/Server/API/UserSmsApi.test.ts +107 -14
- package/Tests/Server/API/UserTotpAuthAPI.test.ts +427 -0
- package/Tests/Server/Infrastructure/Postgres/FixTotpOtpUrlAlgorithmMigration.test.ts +315 -0
- package/Tests/Server/Middleware/VerificationCodeRateLimit.test.ts +775 -0
- package/Tests/Server/Services/AddNetworkDeviceReachabilityColumnsMigration.test.ts +10 -62
- package/Tests/Server/Services/AnalyticsDatabasePaginationStability.test.ts +33 -13
- package/Tests/Server/Services/AnalyticsDatabaseSortKeyBoundary.test.ts +658 -0
- package/Tests/Server/Services/CriticalOnCallAlertDelivery.test.ts +458 -0
- package/Tests/Server/Services/CriticalPushAlertPayload.test.ts +301 -0
- package/Tests/Server/Services/DatabaseServiceAtomicIncrement.test.ts +143 -0
- package/Tests/Server/Services/DeliverNotificationForRuleExtraction.test.ts +1 -0
- package/Tests/Server/Services/LogAggregationScanMemory.test.ts +421 -0
- package/Tests/Server/Services/LogAggregationService.test.ts +2 -2
- package/Tests/Server/Services/NotificationChannelCodeIssuance.test.ts +401 -0
- package/Tests/Server/Services/PushNotificationDeliveryOptions.test.ts +204 -0
- package/Tests/Server/Services/TeamMemberAutoAcceptInvitation.test.ts +21 -1
- package/Tests/Server/Services/TeamMemberInviteRegistrationToken.test.ts +290 -0
- package/Tests/Server/Services/UserNotificationMethodAdminService.test.ts +948 -0
- package/Tests/Server/Services/UserNotificationRuleExecuteItem.test.ts +1 -0
- package/Tests/Server/Services/UserPushCriticalAlertToggle.test.ts +255 -0
- package/Tests/Server/Services/UserTotpAuthEnrolment.test.ts +218 -0
- package/Tests/Server/TestingUtils/AuthenticatorApp.ts +248 -0
- package/Tests/Server/Types/Database/Permissions/NotificationChannelVerificationColumns.test.ts +135 -0
- package/Tests/Server/Types/Database/Permissions/OnCallScheduleRelationSelect.test.ts +504 -0
- package/Tests/Server/Types/Database/QueryHelperFindWithSameTextAnyOf.test.ts +91 -0
- package/Tests/Server/Types/Workflow/Components/JsonToText.test.ts +384 -0
- package/Tests/Server/Types/Workflow/Components/MergeJson.test.ts +403 -0
- package/Tests/Server/Utils/Browser.test.ts +162 -0
- package/Tests/Server/Utils/ChannelVerification.test.ts +689 -0
- package/Tests/Server/Utils/Express.test.ts +371 -0
- package/Tests/Server/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.test.ts +707 -0
- package/Tests/Server/Utils/Monitor/Criteria/DnsMonitorCriteria.test.ts +698 -0
- package/Tests/Server/Utils/Monitor/Criteria/IncomingEmailBodyCriteria.test.ts +243 -0
- package/Tests/Server/Utils/Monitor/Criteria/IncomingRequestBodyCriteria.test.ts +278 -0
- package/Tests/Server/Utils/Monitor/MonitorAlertResourceLinking.test.ts +160 -20
- package/Tests/Server/Utils/Monitor/MonitorDependencySuppressionCreatorSkip.test.ts +13 -8
- package/Tests/Server/Utils/Monitor/MonitorIncidentResourceLinking.test.ts +162 -18
- package/Tests/Server/Utils/Monitor/MonitorResourceContext.test.ts +349 -0
- package/Tests/Server/Utils/Monitor/MonitorStepResourceIdentity.test.ts +690 -0
- package/Tests/Server/Utils/Monitor/MonitorSummaryPersistence.test.ts +7 -2
- package/Tests/Server/Utils/Monitor/SeriesResourceLinker.test.ts +92 -18
- package/Tests/Server/Utils/PushNotificationUtilCreators.test.ts +267 -0
- package/Tests/Server/Utils/Telemetry/OneuptimeLabel.test.ts +439 -0
- package/Tests/Server/Utils/TotpAuth.test.ts +719 -0
- package/Tests/Server/Utils/UserRegistrationToken.test.ts +322 -0
- package/Tests/Server/Utils/VerificationCode.test.ts +296 -0
- package/Tests/Types/AutoRemediation/AutoRemediationSuggestionStatus.test.ts +192 -0
- package/Tests/Types/Call/CallRequest.test.ts +189 -0
- package/Tests/Types/Dashboard/DashboardSize.test.ts +226 -0
- package/Tests/Types/Incident/IncidentSlaStatus.test.ts +191 -0
- package/Tests/Types/Metrics/MetricDashboardMetricType.test.ts +278 -0
- package/Tests/Types/Metrics/MetricPipelineRuleType.test.ts +517 -0
- package/Tests/Types/Monitor/IncomingMonitorDefaultCriteria.test.ts +470 -0
- package/Tests/Types/Monitor/MonitorCriteriaInstance.test.ts +6 -4
- package/Tests/Types/Monitor/Recommendation/MonitorRecommendationCatalog.test.ts +262 -5
- package/Tests/Types/Monitor/Recommendation/MonitorRecommendationCoverage.test.ts +1 -1
- package/Tests/Types/Monitor/Recommendation/MonitorRecommendationNotificationMode.test.ts +1 -1
- package/Tests/Types/Monitor/ServiceAlertTemplates.test.ts +905 -0
- package/Tests/Types/Service/ServiceLanguage.test.ts +255 -0
- package/Tests/Types/TextRandomGeneration.test.ts +211 -0
- package/Tests/UI/Components/Button.test.tsx +175 -1
- package/Tests/UI/Components/CodeBlockLanguages.test.tsx +236 -0
- package/Tests/UI/Components/CommandPalette/CommandPalette.test.tsx +568 -0
- package/Tests/UI/Components/CommandPalette/CommandPaletteKeyboard.test.tsx +239 -0
- package/Tests/UI/Components/CommandPalette/CommandPaletteProviders.test.tsx +400 -0
- package/Tests/UI/Components/CommandPalette/PaletteFilter.test.ts +234 -0
- package/Tests/UI/Components/CommandPalette/RecentCommands.test.ts +97 -0
- package/Tests/UI/Components/CountModelSideMenuItemGuard.test.tsx +198 -0
- package/Tests/UI/Components/FeedItemSafeMode.test.tsx +1 -1
- package/Tests/UI/Components/Forms/Utils/FormFieldSchemaTypeUtil.test.ts +267 -0
- package/Tests/UI/Components/List.test.tsx +9 -2
- package/Tests/UI/Components/ListLoadingStates.test.tsx +173 -0
- package/Tests/UI/Components/MarkdownLazy.test.tsx +113 -0
- package/Tests/UI/Components/MarkdownMermaidRetry.test.tsx +110 -0
- package/Tests/UI/Components/ModelTable/useCustomFieldColumns.test.tsx +8 -0
- package/Tests/UI/Components/MonitorTemplateVariables/TemplateVariablesCatalog.test.ts +692 -0
- package/Tests/UI/Components/MoreMenuMotion.test.tsx +118 -0
- package/Tests/UI/Components/NavBarCommandKGating.test.tsx +178 -0
- package/Tests/UI/Components/OrderedStatesList.test.tsx +19 -2
- package/Tests/UI/Components/SideOverMotion.test.tsx +109 -0
- package/Tests/UI/Components/Skeleton.test.tsx +71 -0
- package/Tests/UI/Components/TableLoadingStates.test.tsx +279 -0
- package/Tests/UI/Components/Tabs.test.tsx +24 -0
- package/Tests/UI/Components/Toast.test.tsx +130 -7
- package/Tests/UI/Components/ToastStacking.test.tsx +198 -0
- package/Tests/UI/Utils/Dropdown.test.ts +423 -0
- package/Tests/UI/Utils/ModelAPITenantHeader.test.ts +122 -0
- package/Tests/UI/Utils/ModelListCache.test.ts +338 -0
- package/Tests/UI/Utils/ProjectListCacheInvalidation.test.ts +225 -0
- package/Tests/Utils/API.test.ts +16 -2
- package/Tests/Utils/Dashboard/Components/DashboardKubernetesResourceListShared.test.ts +347 -0
- package/Tests/Utils/Dashboard/Components/DashboardListSharedArgs.test.ts +259 -0
- package/Tests/Utils/Dashboard/Components/DashboardMonitorListComponent.test.ts +466 -0
- package/Tests/Utils/Rum/UrlScrubberSegments.test.ts +362 -0
- package/Types/Email/EmailTemplateType.ts +1 -0
- package/Types/Monitor/MonitorCriteriaInstance.ts +41 -20
- package/Types/Monitor/Recommendation/MonitorRecommendationCatalog.ts +131 -8
- package/Types/Monitor/Recommendation/MonitorRecommendationTypes.ts +48 -8
- package/Types/Monitor/ServiceAlertTemplates.ts +1352 -0
- package/Types/Permission.ts +35 -0
- package/Types/PushNotification/AndroidNotificationChannel.ts +26 -0
- package/Types/PushNotification/PushNotificationMessage.ts +15 -0
- package/Types/PushNotification/PushNotificationRequest.ts +8 -16
- package/Types/Service/ServiceLanguage.ts +144 -0
- package/Types/Text.ts +111 -19
- package/UI/Components/Button/Button.tsx +27 -14
- package/UI/Components/CodeBlock/CodeBlock.tsx +54 -7
- package/UI/Components/CodeBlock/LanguageRegistry.ts +103 -0
- package/UI/Components/CommandPalette/CommandPalette.tsx +790 -0
- package/UI/Components/CommandPalette/PaletteFilter.ts +196 -0
- package/UI/Components/CommandPalette/PaletteRow.tsx +173 -0
- package/UI/Components/CommandPalette/RecentCommands.ts +57 -0
- package/UI/Components/CommandPalette/Types.ts +49 -0
- package/UI/Components/CommandPalette/UseProviderSearch.ts +129 -0
- package/UI/Components/Dropdown/Dropdown.tsx +6 -1
- package/UI/Components/Feed/FeedItem.tsx +1 -1
- package/UI/Components/List/List.tsx +37 -5
- package/UI/Components/List/ListSkeleton.tsx +54 -0
- package/UI/Components/Markdown.tsx/LazyMarkdownViewer.tsx +6 -1
- package/UI/Components/Markdown.tsx/MarkdownViewer.tsx +71 -26
- package/UI/Components/Modal/Modal.tsx +2 -2
- package/UI/Components/ModelTable/BaseModelTable.tsx +1 -1
- package/UI/Components/ModelTable/useCustomFieldColumns.ts +11 -5
- package/UI/Components/MoreMenu/MoreMenu.tsx +39 -1
- package/UI/Components/Navbar/NavBar.tsx +14 -1
- package/UI/Components/OrderedStatesList/OrderedStatesList.tsx +50 -5
- package/UI/Components/SideMenu/CountModelSideMenuItem.tsx +40 -1
- package/UI/Components/SideOver/SideOver.tsx +37 -2
- package/UI/Components/Skeleton/Skeleton.tsx +53 -0
- package/UI/Components/Table/Table.tsx +74 -44
- package/UI/Components/Table/TableSkeletonRows.tsx +141 -0
- package/UI/Components/Tabs/Tab.tsx +1 -1
- package/UI/Components/Toast/Toast.tsx +118 -53
- package/UI/Components/Toast/ToastInit.tsx +82 -32
- package/UI/Styles/Theme.css +40 -0
- package/UI/Utils/ModelAPI/ModelAPI.ts +20 -10
- package/UI/Utils/ModelListCache.ts +188 -0
- package/UI/Utils/Project.ts +29 -0
- package/Utils/API.ts +6 -1
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicySchedule.js +14 -0
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicySchedule.js.map +1 -1
- package/build/dist/Models/DatabaseModels/UserCall.js +101 -3
- package/build/dist/Models/DatabaseModels/UserCall.js.map +1 -1
- package/build/dist/Models/DatabaseModels/UserEmail.js +101 -3
- package/build/dist/Models/DatabaseModels/UserEmail.js.map +1 -1
- package/build/dist/Models/DatabaseModels/UserIncomingCallNumber.js +101 -3
- package/build/dist/Models/DatabaseModels/UserIncomingCallNumber.js.map +1 -1
- package/build/dist/Models/DatabaseModels/UserPush.js +38 -0
- package/build/dist/Models/DatabaseModels/UserPush.js.map +1 -1
- package/build/dist/Models/DatabaseModels/UserSMS.js +101 -3
- package/build/dist/Models/DatabaseModels/UserSMS.js.map +1 -1
- package/build/dist/Models/DatabaseModels/UserWhatsApp.js +100 -2
- package/build/dist/Models/DatabaseModels/UserWhatsApp.js.map +1 -1
- package/build/dist/Server/API/BaseAPI.js +69 -13
- package/build/dist/Server/API/BaseAPI.js.map +1 -1
- package/build/dist/Server/API/UserCallAPI.js +42 -38
- package/build/dist/Server/API/UserCallAPI.js.map +1 -1
- package/build/dist/Server/API/UserEmailAPI.js +42 -38
- package/build/dist/Server/API/UserEmailAPI.js.map +1 -1
- package/build/dist/Server/API/UserIncomingCallNumberAPI.js +37 -32
- package/build/dist/Server/API/UserIncomingCallNumberAPI.js.map +1 -1
- package/build/dist/Server/API/UserNotificationMethodAdminAPI.js +341 -0
- package/build/dist/Server/API/UserNotificationMethodAdminAPI.js.map +1 -0
- package/build/dist/Server/API/UserPushAPI.js +95 -2
- package/build/dist/Server/API/UserPushAPI.js.map +1 -1
- package/build/dist/Server/API/UserSmsAPI.js +42 -38
- package/build/dist/Server/API/UserSmsAPI.js.map +1 -1
- package/build/dist/Server/API/UserWhatsAppAPI.js +42 -40
- package/build/dist/Server/API/UserWhatsAppAPI.js.map +1 -1
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1787142779538-MigrationName.js +89 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1787142779538-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1787156982416-MigrationName.js +12 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1787156982416-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1787700000000-FixTotpOtpUrlAlgorithm.js +40 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1787700000000-FixTotpOtpUrlAlgorithm.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +6 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Middleware/VerificationCodeRateLimit.js +393 -0
- package/build/dist/Server/Middleware/VerificationCodeRateLimit.js.map +1 -0
- package/build/dist/Server/Services/AnalyticsDatabaseService.js +136 -0
- package/build/dist/Server/Services/AnalyticsDatabaseService.js.map +1 -1
- package/build/dist/Server/Services/DatabaseService.js +74 -0
- package/build/dist/Server/Services/DatabaseService.js.map +1 -1
- package/build/dist/Server/Services/LogAggregationService.js +5 -0
- package/build/dist/Server/Services/LogAggregationService.js.map +1 -1
- package/build/dist/Server/Services/PushNotificationService.js +69 -30
- package/build/dist/Server/Services/PushNotificationService.js.map +1 -1
- package/build/dist/Server/Services/TeamMemberService.js +43 -7
- package/build/dist/Server/Services/TeamMemberService.js.map +1 -1
- package/build/dist/Server/Services/UserCallService.js +54 -22
- package/build/dist/Server/Services/UserCallService.js.map +1 -1
- package/build/dist/Server/Services/UserEmailService.js +78 -17
- package/build/dist/Server/Services/UserEmailService.js.map +1 -1
- package/build/dist/Server/Services/UserIncomingCallNumberService.js +45 -74
- package/build/dist/Server/Services/UserIncomingCallNumberService.js.map +1 -1
- package/build/dist/Server/Services/UserNotificationMethodAdminService.js +1117 -0
- package/build/dist/Server/Services/UserNotificationMethodAdminService.js.map +1 -0
- package/build/dist/Server/Services/UserNotificationRuleService.js +20 -0
- package/build/dist/Server/Services/UserNotificationRuleService.js.map +1 -1
- package/build/dist/Server/Services/UserPushService.js +77 -0
- package/build/dist/Server/Services/UserPushService.js.map +1 -1
- package/build/dist/Server/Services/UserSmsService.js +50 -17
- package/build/dist/Server/Services/UserSmsService.js.map +1 -1
- package/build/dist/Server/Services/UserWhatsAppService.js +48 -15
- package/build/dist/Server/Services/UserWhatsAppService.js.map +1 -1
- package/build/dist/Server/Types/Database/QueryHelper.js +27 -0
- package/build/dist/Server/Types/Database/QueryHelper.js.map +1 -1
- package/build/dist/Server/Utils/AnalyticsDatabase/QuerySettingsHelper.js +46 -0
- package/build/dist/Server/Utils/AnalyticsDatabase/QuerySettingsHelper.js.map +1 -1
- package/build/dist/Server/Utils/ChannelVerification.js +348 -0
- package/build/dist/Server/Utils/ChannelVerification.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/Criteria/IncomingRequestCriteria.js +13 -12
- package/build/dist/Server/Utils/Monitor/Criteria/IncomingRequestCriteria.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorAlert.js +20 -17
- package/build/dist/Server/Utils/Monitor/MonitorAlert.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorIncident.js +17 -14
- package/build/dist/Server/Utils/Monitor/MonitorIncident.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorResourceContext.js +95 -0
- package/build/dist/Server/Utils/Monitor/MonitorResourceContext.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/MonitorStepResourceIdentity.js +313 -0
- package/build/dist/Server/Utils/Monitor/MonitorStepResourceIdentity.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/SeriesResourceLabels.js +3 -3
- package/build/dist/Server/Utils/Monitor/SeriesResourceLinker.js +67 -26
- package/build/dist/Server/Utils/Monitor/SeriesResourceLinker.js.map +1 -1
- package/build/dist/Server/Utils/TotpAuth.js +127 -8
- package/build/dist/Server/Utils/TotpAuth.js.map +1 -1
- package/build/dist/Server/Utils/UserRegistrationToken.js +170 -0
- package/build/dist/Server/Utils/UserRegistrationToken.js.map +1 -0
- package/build/dist/Server/Utils/VerificationCode.js +120 -0
- package/build/dist/Server/Utils/VerificationCode.js.map +1 -0
- package/build/dist/Types/Email/EmailTemplateType.js +1 -0
- package/build/dist/Types/Email/EmailTemplateType.js.map +1 -1
- package/build/dist/Types/Monitor/MonitorCriteriaInstance.js +42 -21
- package/build/dist/Types/Monitor/MonitorCriteriaInstance.js.map +1 -1
- package/build/dist/Types/Monitor/Recommendation/MonitorRecommendationCatalog.js +77 -5
- package/build/dist/Types/Monitor/Recommendation/MonitorRecommendationCatalog.js.map +1 -1
- package/build/dist/Types/Monitor/Recommendation/MonitorRecommendationTypes.js +18 -6
- package/build/dist/Types/Monitor/Recommendation/MonitorRecommendationTypes.js.map +1 -1
- package/build/dist/Types/Monitor/ServiceAlertTemplates.js +1028 -0
- package/build/dist/Types/Monitor/ServiceAlertTemplates.js.map +1 -0
- package/build/dist/Types/Permission.js +33 -0
- package/build/dist/Types/Permission.js.map +1 -1
- package/build/dist/Types/PushNotification/AndroidNotificationChannel.js +27 -0
- package/build/dist/Types/PushNotification/AndroidNotificationChannel.js.map +1 -0
- package/build/dist/Types/Service/ServiceLanguage.js +96 -0
- package/build/dist/Types/Service/ServiceLanguage.js.map +1 -0
- package/build/dist/Types/Text.js +82 -17
- package/build/dist/Types/Text.js.map +1 -1
- package/build/dist/UI/Components/Button/Button.js +22 -14
- package/build/dist/UI/Components/Button/Button.js.map +1 -1
- package/build/dist/UI/Components/CodeBlock/CodeBlock.js +35 -3
- package/build/dist/UI/Components/CodeBlock/CodeBlock.js.map +1 -1
- package/build/dist/UI/Components/CodeBlock/LanguageRegistry.js +57 -0
- package/build/dist/UI/Components/CodeBlock/LanguageRegistry.js.map +1 -0
- package/build/dist/UI/Components/CommandPalette/CommandPalette.js +439 -0
- package/build/dist/UI/Components/CommandPalette/CommandPalette.js.map +1 -0
- package/build/dist/UI/Components/CommandPalette/PaletteFilter.js +135 -0
- package/build/dist/UI/Components/CommandPalette/PaletteFilter.js.map +1 -0
- package/build/dist/UI/Components/CommandPalette/PaletteRow.js +83 -0
- package/build/dist/UI/Components/CommandPalette/PaletteRow.js.map +1 -0
- package/build/dist/UI/Components/CommandPalette/RecentCommands.js +47 -0
- package/build/dist/UI/Components/CommandPalette/RecentCommands.js.map +1 -0
- package/build/dist/UI/Components/CommandPalette/Types.js +2 -0
- package/build/dist/UI/Components/CommandPalette/Types.js.map +1 -0
- package/build/dist/UI/Components/CommandPalette/UseProviderSearch.js +88 -0
- package/build/dist/UI/Components/CommandPalette/UseProviderSearch.js.map +1 -0
- package/build/dist/UI/Components/Dropdown/Dropdown.js +6 -1
- package/build/dist/UI/Components/Dropdown/Dropdown.js.map +1 -1
- package/build/dist/UI/Components/Feed/FeedItem.js +1 -1
- package/build/dist/UI/Components/Feed/FeedItem.js.map +1 -1
- package/build/dist/UI/Components/List/List.js +19 -5
- package/build/dist/UI/Components/List/List.js.map +1 -1
- package/build/dist/UI/Components/List/ListSkeleton.js +21 -0
- package/build/dist/UI/Components/List/ListSkeleton.js.map +1 -0
- package/build/dist/UI/Components/Markdown.tsx/LazyMarkdownViewer.js.map +1 -1
- package/build/dist/UI/Components/Markdown.tsx/MarkdownViewer.js +52 -25
- package/build/dist/UI/Components/Markdown.tsx/MarkdownViewer.js.map +1 -1
- package/build/dist/UI/Components/Modal/Modal.js +2 -2
- package/build/dist/UI/Components/ModelTable/BaseModelTable.js +1 -1
- package/build/dist/UI/Components/ModelTable/BaseModelTable.js.map +1 -1
- package/build/dist/UI/Components/ModelTable/useCustomFieldColumns.js +9 -2
- package/build/dist/UI/Components/ModelTable/useCustomFieldColumns.js.map +1 -1
- package/build/dist/UI/Components/MoreMenu/MoreMenu.js +32 -1
- package/build/dist/UI/Components/MoreMenu/MoreMenu.js.map +1 -1
- package/build/dist/UI/Components/Navbar/NavBar.js +5 -1
- package/build/dist/UI/Components/Navbar/NavBar.js.map +1 -1
- package/build/dist/UI/Components/OrderedStatesList/OrderedStatesList.js +29 -5
- package/build/dist/UI/Components/OrderedStatesList/OrderedStatesList.js.map +1 -1
- package/build/dist/UI/Components/SideMenu/CountModelSideMenuItem.js +23 -1
- package/build/dist/UI/Components/SideMenu/CountModelSideMenuItem.js.map +1 -1
- package/build/dist/UI/Components/SideOver/SideOver.js +23 -2
- package/build/dist/UI/Components/SideOver/SideOver.js.map +1 -1
- package/build/dist/UI/Components/Skeleton/Skeleton.js +23 -0
- package/build/dist/UI/Components/Skeleton/Skeleton.js.map +1 -0
- package/build/dist/UI/Components/Table/Table.js +35 -24
- package/build/dist/UI/Components/Table/Table.js.map +1 -1
- package/build/dist/UI/Components/Table/TableSkeletonRows.js +52 -0
- package/build/dist/UI/Components/Table/TableSkeletonRows.js.map +1 -0
- package/build/dist/UI/Components/Tabs/Tab.js +1 -1
- package/build/dist/UI/Components/Tabs/Tab.js.map +1 -1
- package/build/dist/UI/Components/Toast/Toast.js +77 -23
- package/build/dist/UI/Components/Toast/Toast.js.map +1 -1
- package/build/dist/UI/Components/Toast/ToastInit.js +37 -15
- package/build/dist/UI/Components/Toast/ToastInit.js.map +1 -1
- package/build/dist/UI/Utils/ModelAPI/ModelAPI.js +18 -9
- package/build/dist/UI/Utils/ModelAPI/ModelAPI.js.map +1 -1
- package/build/dist/UI/Utils/ModelListCache.js +126 -0
- package/build/dist/UI/Utils/ModelListCache.js.map +1 -0
- package/build/dist/UI/Utils/Project.js +24 -1
- package/build/dist/UI/Utils/Project.js.map +1 -1
- package/build/dist/Utils/API.js +6 -1
- package/build/dist/Utils/API.js.map +1 -1
- package/jest.config.json +1 -1
- package/package.json +2 -3
- package/Server/Utils/Monitor/MonitorClusterContext.ts +0 -182
- package/Tests/__mocks__/otpauth.js +0 -30
- package/build/dist/Server/Utils/Monitor/MonitorClusterContext.js +0 -141
- package/build/dist/Server/Utils/Monitor/MonitorClusterContext.js.map +0 -1
|
@@ -9,6 +9,7 @@ import ProxmoxCluster from "../../../Models/DatabaseModels/ProxmoxCluster";
|
|
|
9
9
|
import Service from "../../../Models/DatabaseModels/Service";
|
|
10
10
|
import Includes from "../../../Types/BaseDatabase/Includes";
|
|
11
11
|
import { LIMIT_PER_PROJECT } from "../../../Types/Database/LimitMax";
|
|
12
|
+
import MonitorType from "../../../Types/Monitor/MonitorType";
|
|
12
13
|
import CephClusterService from "../../Services/CephClusterService";
|
|
13
14
|
import DockerHostService from "../../Services/DockerHostService";
|
|
14
15
|
import DockerSwarmClusterService from "../../Services/DockerSwarmClusterService";
|
|
@@ -18,6 +19,7 @@ import KubernetesClusterService from "../../Services/KubernetesClusterService";
|
|
|
18
19
|
import PodmanHostService from "../../Services/PodmanHostService";
|
|
19
20
|
import ProxmoxClusterService from "../../Services/ProxmoxClusterService";
|
|
20
21
|
import ServiceService from "../../Services/ServiceService";
|
|
22
|
+
import QueryHelper from "../../Types/Database/QueryHelper";
|
|
21
23
|
import SeriesResourceLabels from "./SeriesResourceLabels";
|
|
22
24
|
export default class SeriesResourceLinker {
|
|
23
25
|
/*
|
|
@@ -29,6 +31,42 @@ export default class SeriesResourceLinker {
|
|
|
29
31
|
*/
|
|
30
32
|
static async resolveResourcesFromSeriesLabels(input) {
|
|
31
33
|
const refs = SeriesResourceLabels.extractResourceRefs(input.seriesLabels);
|
|
34
|
+
/*
|
|
35
|
+
* On a Docker or Podman monitor, `resource.host.name` names the
|
|
36
|
+
* DockerHost / PodmanHost the containers run on — the agent stamps
|
|
37
|
+
* the container runtime's host under the generic key. The label key
|
|
38
|
+
* map hands that key to Host, which would attach an unrelated Host
|
|
39
|
+
* row and surface the event on that host's Activity tab. The
|
|
40
|
+
* step-config path links the right model instead
|
|
41
|
+
* (MonitorStepResourceIdentity), so drop the host refs here rather
|
|
42
|
+
* than linking a resource the event is not about.
|
|
43
|
+
*/
|
|
44
|
+
if (input.monitorType === MonitorType.Docker ||
|
|
45
|
+
input.monitorType === MonitorType.Podman) {
|
|
46
|
+
refs.hostIds = [];
|
|
47
|
+
refs.hostNames = [];
|
|
48
|
+
}
|
|
49
|
+
/*
|
|
50
|
+
* Series labels are ingest-written, so they match the resource
|
|
51
|
+
* rows' identifier columns byte for byte. See resolveResourceIds
|
|
52
|
+
* for why that rules out case-insensitive matching here.
|
|
53
|
+
*/
|
|
54
|
+
return this.resolveResourceRefs({
|
|
55
|
+
refs: refs,
|
|
56
|
+
projectId: input.projectId,
|
|
57
|
+
nameMatch: "exact",
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/*
|
|
61
|
+
* The one place that turns identifiers into database ids, shared by
|
|
62
|
+
* the series-label path and the monitor-step-config path
|
|
63
|
+
* (MonitorStepResourceIdentity). Keeping the nine-way lookup table,
|
|
64
|
+
* the project scoping and the `Includes` batching in a single
|
|
65
|
+
* function is what stops the two paths from resolving the same
|
|
66
|
+
* identifier to different rows.
|
|
67
|
+
*/
|
|
68
|
+
static async resolveResourceRefs(input) {
|
|
69
|
+
const refs = input.refs;
|
|
32
70
|
/*
|
|
33
71
|
* Proxmox / Ceph / Docker Swarm / IoT carry no `oneuptime.*.id`
|
|
34
72
|
* stamp at ingest — they are addressable by name only — so their
|
|
@@ -96,6 +134,7 @@ export default class SeriesResourceLinker {
|
|
|
96
134
|
names: spec.names,
|
|
97
135
|
nameColumn: spec.nameColumn,
|
|
98
136
|
projectId: input.projectId,
|
|
137
|
+
nameMatch: input.nameMatch,
|
|
99
138
|
findBy: spec.findBy,
|
|
100
139
|
});
|
|
101
140
|
}));
|
|
@@ -113,9 +152,10 @@ export default class SeriesResourceLinker {
|
|
|
113
152
|
}
|
|
114
153
|
/*
|
|
115
154
|
* Resolve the series' resources and MERGE them onto the alert/incident.
|
|
116
|
-
* Merging (rather than assigning) matters because
|
|
117
|
-
* writes the same
|
|
118
|
-
* config; whichever runs second must not erase the
|
|
155
|
+
* Merging (rather than assigning) matters because
|
|
156
|
+
* attachResolvedResources writes the same relations from the
|
|
157
|
+
* monitor's step config; whichever runs second must not erase the
|
|
158
|
+
* other's work.
|
|
119
159
|
*
|
|
120
160
|
* Relations the series says nothing about are left untouched —
|
|
121
161
|
* `undefined`, not `[]` — so an ungrouped event and an event whose
|
|
@@ -130,6 +170,7 @@ export default class SeriesResourceLinker {
|
|
|
130
170
|
const resolved = await this.resolveResourcesFromSeriesLabels({
|
|
131
171
|
seriesLabels: input.seriesLabels,
|
|
132
172
|
projectId: input.projectId,
|
|
173
|
+
monitorType: input.monitorType,
|
|
133
174
|
});
|
|
134
175
|
this.mergeResolvedIdsIntoModel({
|
|
135
176
|
model: input.model,
|
|
@@ -137,27 +178,19 @@ export default class SeriesResourceLinker {
|
|
|
137
178
|
});
|
|
138
179
|
}
|
|
139
180
|
/*
|
|
140
|
-
* Attach the
|
|
141
|
-
* (
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
181
|
+
* Attach the resources resolved from the monitor's own step config
|
|
182
|
+
* (MonitorResourceContext), merging with — never overwriting —
|
|
183
|
+
* anything the series-label path already linked. Both paths can
|
|
184
|
+
* resolve the same resource, so this dedupes by id.
|
|
185
|
+
*
|
|
186
|
+
* Unlike the label path this runs for ungrouped events too, and that
|
|
187
|
+
* is the whole point: an ungrouped monitor has no series labels, so
|
|
188
|
+
* before this existed it linked nothing at all.
|
|
146
189
|
*/
|
|
147
|
-
static
|
|
190
|
+
static attachResolvedResources(input) {
|
|
148
191
|
this.mergeResolvedIdsIntoModel({
|
|
149
192
|
model: input.model,
|
|
150
|
-
resolved:
|
|
151
|
-
hostIds: [],
|
|
152
|
-
dockerHostIds: [],
|
|
153
|
-
podmanHostIds: [],
|
|
154
|
-
kubernetesClusterIds: [],
|
|
155
|
-
serviceIds: [],
|
|
156
|
-
proxmoxClusterIds: input.clusterContext.proxmoxClusterIds,
|
|
157
|
-
cephClusterIds: input.clusterContext.cephClusterIds,
|
|
158
|
-
dockerSwarmClusterIds: input.clusterContext.dockerSwarmClusterIds,
|
|
159
|
-
iotFleetIds: input.clusterContext.iotFleetIds,
|
|
160
|
-
},
|
|
193
|
+
resolved: input.resolved,
|
|
161
194
|
});
|
|
162
195
|
}
|
|
163
196
|
static mergeResolvedIdsIntoModel(input) {
|
|
@@ -236,10 +269,16 @@ export default class SeriesResourceLinker {
|
|
|
236
269
|
* Costs zero round-trips when the series carries neither, which is the
|
|
237
270
|
* common case for most of the nine types on any given series.
|
|
238
271
|
*
|
|
239
|
-
*
|
|
240
|
-
* by ingest from the same attribute the series
|
|
241
|
-
* identifiers are canonicalized on both sides —
|
|
242
|
-
* what keeps a lookup from straying onto a
|
|
272
|
+
* `nameMatch: "exact"` is for series labels. Every identifier column
|
|
273
|
+
* read here is written by ingest from the same attribute the series
|
|
274
|
+
* label carries — host identifiers are canonicalized on both sides —
|
|
275
|
+
* so exact matching is what keeps a lookup from straying onto a
|
|
276
|
+
* neighbouring row.
|
|
277
|
+
*
|
|
278
|
+
* `nameMatch: "caseInsensitive"` is for monitor step configs, where
|
|
279
|
+
* the identifier was typed by a user and the row's name was stamped
|
|
280
|
+
* by an agent; the two legitimately differ by case. This mirrors what
|
|
281
|
+
* ingest discovery itself does when it keys a row by name.
|
|
243
282
|
*/
|
|
244
283
|
static async resolveResourceIds(input) {
|
|
245
284
|
if (input.ids.length === 0 && input.names.length === 0) {
|
|
@@ -263,7 +302,9 @@ export default class SeriesResourceLinker {
|
|
|
263
302
|
lookups.push(input.findBy({
|
|
264
303
|
query: {
|
|
265
304
|
projectId: input.projectId,
|
|
266
|
-
[input.nameColumn]:
|
|
305
|
+
[input.nameColumn]: input.nameMatch === "caseInsensitive"
|
|
306
|
+
? QueryHelper.findWithSameTextAnyOf(input.names)
|
|
307
|
+
: new Includes(input.names),
|
|
267
308
|
},
|
|
268
309
|
select: { _id: true },
|
|
269
310
|
skip: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SeriesResourceLinker.js","sourceRoot":"","sources":["../../../../../Server/Utils/Monitor/SeriesResourceLinker.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,4CAA4C,CAAC;AACrE,OAAO,UAAU,MAAM,2CAA2C,CAAC;AACnE,OAAO,kBAAkB,MAAM,mDAAmD,CAAC;AACnF,OAAO,IAAI,MAAM,qCAAqC,CAAC;AACvD,OAAO,QAAQ,MAAM,yCAAyC,CAAC;AAC/D,OAAO,iBAAiB,MAAM,kDAAkD,CAAC;AACjF,OAAO,UAAU,MAAM,2CAA2C,CAAC;AACnE,OAAO,cAAc,MAAM,+CAA+C,CAAC;AAC3E,OAAO,OAAO,MAAM,wCAAwC,CAAC;AAC7D,OAAO,QAAQ,MAAM,sCAAsC,CAAC;AAC5D,OAAO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 var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
import * as OTPAuth from "otpauth";
|
|
11
11
|
import CaptureSpan from "./Telemetry/CaptureSpan";
|
|
12
|
+
/**
|
|
13
|
+
* The HMAC algorithm every new enrolment is issued with.
|
|
14
|
+
*
|
|
15
|
+
* RFC 6238 fixes SHA1 as the default and every authenticator implements it.
|
|
16
|
+
* The `algorithm` parameter in an otpauth:// URI is, in practice, advisory:
|
|
17
|
+
* Google Authenticator and Microsoft Authenticator parse the URI, ignore the
|
|
18
|
+
* parameter, and compute SHA1 anyway. A server that issues `algorithm=SHA256`
|
|
19
|
+
* therefore hands those apps a QR code they will silently mis-implement — the
|
|
20
|
+
* app shows a confident six digits, the server computes a completely different
|
|
21
|
+
* six digits, and enrolment can never succeed no matter how many codes the
|
|
22
|
+
* user tries. That is the failure this constant exists to prevent.
|
|
23
|
+
*
|
|
24
|
+
* SHA1 is not a weakness here. HMAC-SHA1 is unaffected by the collision
|
|
25
|
+
* attacks that retired SHA1 for signatures (RFC 6234 / RFC 2104), and the
|
|
26
|
+
* output is truncated to six digits over a 30 second window regardless — the
|
|
27
|
+
* brute-force surface is the 10^6 code space, not the hash.
|
|
28
|
+
*/
|
|
29
|
+
export const DefaultTotpAlgorithm = "SHA1";
|
|
30
|
+
/**
|
|
31
|
+
* Algorithms a submitted token is checked against, in order.
|
|
32
|
+
*
|
|
33
|
+
* OneUptime issued `SHA256` enrolments before this was understood. Those
|
|
34
|
+
* secrets are still in the database and still work in the minority of apps
|
|
35
|
+
* that do honour the parameter (1Password, Bitwarden, Aegis, FreeOTP), so
|
|
36
|
+
* dropping SHA256 from verification would lock those accounts out of their
|
|
37
|
+
* own logins.
|
|
38
|
+
*
|
|
39
|
+
* The cost is exactly one bit: two algorithms across the validation window
|
|
40
|
+
* means twice as many six-digit strings are accepted at any instant. Against
|
|
41
|
+
* a 10^6 code space that is still a vanishing fraction, and the tests pin the
|
|
42
|
+
* bound so it cannot quietly grow.
|
|
43
|
+
*
|
|
44
|
+
* Retiring SHA256 needs more than time passing. Nothing on the row records
|
|
45
|
+
* which algorithm the user's app actually computes, so "no legacy rows remain"
|
|
46
|
+
* is not a question the database can answer today — removing it means either
|
|
47
|
+
* storing the algorithm that verified, or accepting that some long-dormant
|
|
48
|
+
* account re-enrols instead of logging in.
|
|
49
|
+
*/
|
|
50
|
+
export const SupportedTotpAlgorithms = ["SHA1", "SHA256"];
|
|
51
|
+
/**
|
|
52
|
+
* Number of 30 second steps either side of now that a token is accepted for.
|
|
53
|
+
*
|
|
54
|
+
* Three steps is +/- 90 seconds, which absorbs ordinary phone/server clock
|
|
55
|
+
* drift and the user typing the last digit as the code rolls over.
|
|
56
|
+
*/
|
|
57
|
+
export const TotpValidationWindow = 3;
|
|
58
|
+
/**
|
|
59
|
+
* Number of digits in a token, and the length of the time step in seconds.
|
|
60
|
+
* Both are the values Google Authenticator assumes, and — like `algorithm` —
|
|
61
|
+
* both are parameters it ignores when told anything else.
|
|
62
|
+
*/
|
|
63
|
+
export const TotpDigits = 6;
|
|
64
|
+
export const TotpPeriodInSeconds = 30;
|
|
12
65
|
/**
|
|
13
66
|
* Utility class for handling TOTP authentication.
|
|
14
67
|
*/
|
|
@@ -32,26 +85,82 @@ export default class TotpAuth {
|
|
|
32
85
|
email: data.email,
|
|
33
86
|
}),
|
|
34
87
|
// Algorithm used for the HMAC function.
|
|
35
|
-
algorithm:
|
|
88
|
+
algorithm: data.algorithm || DefaultTotpAlgorithm,
|
|
36
89
|
// Length of the generated tokens.
|
|
37
|
-
digits:
|
|
90
|
+
digits: TotpDigits,
|
|
38
91
|
// Interval of time for which a token is valid, in seconds.
|
|
39
|
-
period:
|
|
92
|
+
period: TotpPeriodInSeconds,
|
|
40
93
|
// Arbitrary key encoded in Base32 or OTPAuth.Secret instance.
|
|
41
94
|
secret: data.secret,
|
|
42
95
|
});
|
|
43
96
|
return totp;
|
|
44
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Strips the formatting authenticator apps add for readability.
|
|
100
|
+
*
|
|
101
|
+
* Google Authenticator renders a code as "123 456" and both the iOS and
|
|
102
|
+
* Android clipboards keep that space when the user copies it. Rejecting the
|
|
103
|
+
* paste is a self-inflicted "Invalid code" for a user who supplied exactly
|
|
104
|
+
* the right secret material, so the separators are removed before the token
|
|
105
|
+
* is compared. Anything that is not a digit is dropped, which also covers
|
|
106
|
+
* the hyphen some apps use and stray whitespace from a trimmed paste.
|
|
107
|
+
*
|
|
108
|
+
* @param token - The raw token as submitted.
|
|
109
|
+
* @returns The token reduced to its digits.
|
|
110
|
+
*/
|
|
111
|
+
static normalizeToken(token) {
|
|
112
|
+
/*
|
|
113
|
+
* The token arrives straight off a JSON body, so it is only a string
|
|
114
|
+
* because the client chose to send one. A number or an object here must
|
|
115
|
+
* fail verification, not throw out of `.replace` and surface as a 500.
|
|
116
|
+
*/
|
|
117
|
+
if (typeof token !== "string" || !token) {
|
|
118
|
+
return "";
|
|
119
|
+
}
|
|
120
|
+
return token.replace(/\D/g, "");
|
|
121
|
+
}
|
|
45
122
|
/**
|
|
46
123
|
* Verifies if a given token matches the provided secret key.
|
|
47
124
|
* @param data - The data object containing the secret key and token.
|
|
48
125
|
* @returns A boolean indicating whether the token is valid or not.
|
|
49
126
|
*/
|
|
50
127
|
static verifyToken(data) {
|
|
51
|
-
const { secret,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
128
|
+
const { secret, email } = data;
|
|
129
|
+
if (!secret) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
const token = this.normalizeToken(data.token);
|
|
133
|
+
/*
|
|
134
|
+
* otpauth compares the submitted string against the codes it generates,
|
|
135
|
+
* so a token of the wrong length can never match — but it would still be
|
|
136
|
+
* run through one HMAC per algorithm per window step first. Reject it up
|
|
137
|
+
* front instead.
|
|
138
|
+
*/
|
|
139
|
+
if (token.length !== TotpDigits) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
for (const algorithm of SupportedTotpAlgorithms) {
|
|
143
|
+
let totp;
|
|
144
|
+
try {
|
|
145
|
+
totp = this.getTotp({ secret, email, algorithm });
|
|
146
|
+
}
|
|
147
|
+
catch (_a) {
|
|
148
|
+
/*
|
|
149
|
+
* A secret that is not valid base32 throws in the OTPAuth.Secret
|
|
150
|
+
* constructor. That is a corrupt row, not a wrong code, and it fails
|
|
151
|
+
* identically for every algorithm — so stop rather than repeat it.
|
|
152
|
+
*/
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
const delta = totp.validate({
|
|
156
|
+
token,
|
|
157
|
+
window: TotpValidationWindow,
|
|
158
|
+
});
|
|
159
|
+
if (delta !== null) {
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
55
164
|
}
|
|
56
165
|
/**
|
|
57
166
|
* Generates a URI for the given secret key and user email, which can be used to set up two-factor authentication.
|
|
@@ -60,7 +169,11 @@ export default class TotpAuth {
|
|
|
60
169
|
*/
|
|
61
170
|
static generateUri(data) {
|
|
62
171
|
const { secret, userEmail } = data;
|
|
63
|
-
const totp = this.getTotp({
|
|
172
|
+
const totp = this.getTotp({
|
|
173
|
+
secret,
|
|
174
|
+
email: userEmail,
|
|
175
|
+
algorithm: DefaultTotpAlgorithm,
|
|
176
|
+
});
|
|
64
177
|
return totp.toString();
|
|
65
178
|
}
|
|
66
179
|
}
|
|
@@ -82,6 +195,12 @@ __decorate([
|
|
|
82
195
|
__metadata("design:paramtypes", [Object]),
|
|
83
196
|
__metadata("design:returntype", OTPAuth.TOTP)
|
|
84
197
|
], TotpAuth, "getTotp", null);
|
|
198
|
+
__decorate([
|
|
199
|
+
CaptureSpan(),
|
|
200
|
+
__metadata("design:type", Function),
|
|
201
|
+
__metadata("design:paramtypes", [String]),
|
|
202
|
+
__metadata("design:returntype", String)
|
|
203
|
+
], TotpAuth, "normalizeToken", null);
|
|
85
204
|
__decorate([
|
|
86
205
|
CaptureSpan(),
|
|
87
206
|
__metadata("design:type", Function),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TotpAuth.js","sourceRoot":"","sources":["../../../../Server/Utils/TotpAuth.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,WAAW,MAAM,yBAAyB,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B;;;OAGG;IAEW,AAAP,MAAM,CAAC,cAAc;QAC1B,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC;IACrC,CAAC;IAGa,AAAP,MAAM,CAAC,QAAQ,CAAC,IAAsB;QAC3C,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;IAGa,AAAP,MAAM,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"TotpAuth.js","sourceRoot":"","sources":["../../../../Server/Utils/TotpAuth.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,WAAW,MAAM,yBAAyB,CAAC;AAElD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAW,MAAM,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAW,CAAC,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAW,CAAC,CAAC;AACpC,MAAM,CAAC,MAAM,mBAAmB,GAAW,EAAE,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B;;;OAGG;IAEW,AAAP,MAAM,CAAC,cAAc;QAC1B,OAAO,IAAI,OAAO,CAAC,MAAM,EA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E,CAAC;YAChC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,KAAK,MAAM,SAAS,IAAI,uBAAuB,EAAE,CAAC;YAChD,IAAI,IAAkB,CAAC;YAEvB,IAAI,CAAC;gBACH,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;YACpD,CAAC;YAAC,WAAM,CAAC;gBACP;;;;mBAIG;gBACH,OAAO,KAAK,CAAC;YACf,CAAC;YAED,MAAM,KAAK,GAAkB,IAAI,CAAC,QAAQ,CAAC;gBACzC,KAAK;gBACL,MAAM,EAAE,oBAAoB;aAC7B,CAAC,CAAC;YAEH,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;OAIG;IAEW,AAAP,MAAM,CAAC,WAAW,CAAC,IAGzB;QACC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAEnC,MAAM,IAAI,GAAiB,IAAI,CAAC,OAAO,CAAC;YACtC,MAAM;YACN,KAAK,EAAE,SAAS;YAChB,SAAS,EAAE,oBAAoB;SAChC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;CACF;AA1Ie;IADb,WAAW,EAAE;;;;oCAGb;AAGa;IADb,WAAW,EAAE;;;;8BAGb;AAGa;IADb,WAAW,EAAE;;;oCAKV,OAAO,CAAC,IAAI;6BAmBf;AAgBa;IADb,WAAW,EAAE;;;;oCAYb;AAQa;IADb,WAAW,EAAE;;;;iCAiDb;AAQa;IADb,WAAW,EAAE;;;;iCAcb"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { AccountsRoute } from "../../ServiceRoute";
|
|
11
|
+
import Route from "../../Types/API/Route";
|
|
12
|
+
import URL from "../../Types/API/URL";
|
|
13
|
+
import OneUptimeDate from "../../Types/Date";
|
|
14
|
+
import ObjectID from "../../Types/ObjectID";
|
|
15
|
+
import EmailVerificationToken from "../../Models/DatabaseModels/EmailVerificationToken";
|
|
16
|
+
import DatabaseConfig from "../DatabaseConfig";
|
|
17
|
+
import EmailVerificationTokenService from "../Services/EmailVerificationTokenService";
|
|
18
|
+
import CaptureSpan from "./Telemetry/CaptureSpan";
|
|
19
|
+
/*
|
|
20
|
+
* An invited user exists in the database before they have ever authenticated.
|
|
21
|
+
* TeamMemberService creates the row so the membership has something to point
|
|
22
|
+
* at, and that row carries no password until the person registers.
|
|
23
|
+
*
|
|
24
|
+
* /signup is what hands that unclaimed row over, so the hand-over has to be
|
|
25
|
+
* gated on something only the mailbox owner can hold. Knowing the address is
|
|
26
|
+
* not enough: addresses at a company are guessable by construction, which is
|
|
27
|
+
* exactly how GHSA-qg84-6hrg-mr5g turned a pending invitation into an account
|
|
28
|
+
* takeover -- the guard there was `if (alreadySavedUser.password)`, and an
|
|
29
|
+
* unclaimed row's password is null, which is falsy.
|
|
30
|
+
*
|
|
31
|
+
* This token is that gate. It is minted when the invitation is sent, travels
|
|
32
|
+
* only inside the invitation email, and is spent the first time it is used.
|
|
33
|
+
*
|
|
34
|
+
* It reuses EmailVerificationToken rather than adding a table of its own: the
|
|
35
|
+
* shape is identical (user, email, opaque token, expiry) and the semantics are
|
|
36
|
+
* the same claim -- "the holder of this controls this mailbox". Spending one is
|
|
37
|
+
* therefore also proof of address ownership, which is why the signup path marks
|
|
38
|
+
* the account verified on the way through.
|
|
39
|
+
*/
|
|
40
|
+
/*
|
|
41
|
+
* Invitations are read when the person gets round to them, not when they are
|
|
42
|
+
* sent, so these live longer than the 24 hours an email-verification link gets.
|
|
43
|
+
* Expiring in a week still bounds how long a leaked invite mail stays useful.
|
|
44
|
+
*/
|
|
45
|
+
export const REGISTRATION_TOKEN_EXPIRY_IN_DAYS = 7;
|
|
46
|
+
export default class UserRegistrationToken {
|
|
47
|
+
/*
|
|
48
|
+
* Mint a token for `email` and return it. The caller is responsible for
|
|
49
|
+
* putting it somewhere only the mailbox owner will see -- which in practice
|
|
50
|
+
* means a link in an email addressed to that same mailbox, and nowhere else.
|
|
51
|
+
* It must never be written into an API response.
|
|
52
|
+
*/
|
|
53
|
+
static async generateRegistrationToken(data) {
|
|
54
|
+
const token = ObjectID.generate();
|
|
55
|
+
const emailVerificationToken = new EmailVerificationToken();
|
|
56
|
+
emailVerificationToken.userId = data.userId;
|
|
57
|
+
emailVerificationToken.email = data.email;
|
|
58
|
+
emailVerificationToken.token = token;
|
|
59
|
+
emailVerificationToken.expires = OneUptimeDate.getSomeDaysAfter(REGISTRATION_TOKEN_EXPIRY_IN_DAYS);
|
|
60
|
+
await EmailVerificationTokenService.create({
|
|
61
|
+
data: emailVerificationToken,
|
|
62
|
+
props: {
|
|
63
|
+
isRoot: true,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
return token;
|
|
67
|
+
}
|
|
68
|
+
/*
|
|
69
|
+
* The /accounts/register link an invited person follows. The email is carried
|
|
70
|
+
* alongside the token only to prefill (and lock) the form field; the token is
|
|
71
|
+
* the part that authorizes anything.
|
|
72
|
+
*/
|
|
73
|
+
static async getRegistrationLink(data) {
|
|
74
|
+
const host = await DatabaseConfig.getHost();
|
|
75
|
+
const httpProtocol = await DatabaseConfig.getHttpProtocol();
|
|
76
|
+
return URL.fromString(new URL(httpProtocol, host, new Route(AccountsRoute.toString())).toString())
|
|
77
|
+
.addRoute("/register")
|
|
78
|
+
.addQueryParam("email", data.email.toString(), true)
|
|
79
|
+
.addQueryParam("token", data.token.toString(), true);
|
|
80
|
+
}
|
|
81
|
+
// Mint a token and build the link that carries it, in one step.
|
|
82
|
+
static async generateRegistrationLink(data) {
|
|
83
|
+
const token = await this.generateRegistrationToken({
|
|
84
|
+
userId: data.userId,
|
|
85
|
+
email: data.email,
|
|
86
|
+
});
|
|
87
|
+
return await this.getRegistrationLink({
|
|
88
|
+
email: data.email,
|
|
89
|
+
token: token,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/*
|
|
93
|
+
* Spend a token. Returns true only if it exists, was minted for this exact
|
|
94
|
+
* address, has not expired, and had not already been spent.
|
|
95
|
+
*
|
|
96
|
+
* The delete is what makes it single-use, and it is deliberately the last
|
|
97
|
+
* word: `deleteOneBy` reports how many rows it removed, so two requests
|
|
98
|
+
* racing on the same token produce exactly one winner (the loser deletes
|
|
99
|
+
* nothing and gets false back) rather than two callers who both read a live
|
|
100
|
+
* token and both proceed.
|
|
101
|
+
*
|
|
102
|
+
* Every failure returns the same `false`. The caller must not report which
|
|
103
|
+
* check failed -- "expired" and "no such token" would tell someone probing
|
|
104
|
+
* with guessed tokens which of them had ever been real.
|
|
105
|
+
*/
|
|
106
|
+
static async consumeRegistrationToken(data) {
|
|
107
|
+
const savedToken = await EmailVerificationTokenService.findOneBy({
|
|
108
|
+
query: {
|
|
109
|
+
token: data.token,
|
|
110
|
+
},
|
|
111
|
+
select: {
|
|
112
|
+
_id: true,
|
|
113
|
+
email: true,
|
|
114
|
+
expires: true,
|
|
115
|
+
},
|
|
116
|
+
props: {
|
|
117
|
+
isRoot: true,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
if (!savedToken || !savedToken.email || !savedToken.expires) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
/*
|
|
124
|
+
* A token is bound to the address it was mailed to. Without this, a token
|
|
125
|
+
* from any invitation the attacker had legitimately received would claim
|
|
126
|
+
* any other unclaimed account. Email lowercases on construction, so the
|
|
127
|
+
* string comparison is already case-insensitive.
|
|
128
|
+
*/
|
|
129
|
+
if (savedToken.email.toString() !== data.email.toString()) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (OneUptimeDate.hasExpired(savedToken.expires)) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
const deletedCount = await EmailVerificationTokenService.deleteOneBy({
|
|
136
|
+
query: {
|
|
137
|
+
_id: savedToken._id,
|
|
138
|
+
},
|
|
139
|
+
props: {
|
|
140
|
+
isRoot: true,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
return deletedCount === 1;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
__decorate([
|
|
147
|
+
CaptureSpan(),
|
|
148
|
+
__metadata("design:type", Function),
|
|
149
|
+
__metadata("design:paramtypes", [Object]),
|
|
150
|
+
__metadata("design:returntype", Promise)
|
|
151
|
+
], UserRegistrationToken, "generateRegistrationToken", null);
|
|
152
|
+
__decorate([
|
|
153
|
+
CaptureSpan(),
|
|
154
|
+
__metadata("design:type", Function),
|
|
155
|
+
__metadata("design:paramtypes", [Object]),
|
|
156
|
+
__metadata("design:returntype", Promise)
|
|
157
|
+
], UserRegistrationToken, "getRegistrationLink", null);
|
|
158
|
+
__decorate([
|
|
159
|
+
CaptureSpan(),
|
|
160
|
+
__metadata("design:type", Function),
|
|
161
|
+
__metadata("design:paramtypes", [Object]),
|
|
162
|
+
__metadata("design:returntype", Promise)
|
|
163
|
+
], UserRegistrationToken, "generateRegistrationLink", null);
|
|
164
|
+
__decorate([
|
|
165
|
+
CaptureSpan(),
|
|
166
|
+
__metadata("design:type", Function),
|
|
167
|
+
__metadata("design:paramtypes", [Object]),
|
|
168
|
+
__metadata("design:returntype", Promise)
|
|
169
|
+
], UserRegistrationToken, "consumeRegistrationToken", null);
|
|
170
|
+
//# sourceMappingURL=UserRegistrationToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserRegistrationToken.js","sourceRoot":"","sources":["../../../../Server/Utils/UserRegistrationToken.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,KAAK,MAAM,uBAAuB,CAAC;AAC1C,OAAO,GAAG,MAAM,qBAAqB,CAAC;AACtC,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAC5C,OAAO,sBAAsB,MAAM,oDAAoD,CAAC;AACxF,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,OAAO,6BAA6B,MAAM,2CAA2C,CAAC;AACtF,OAAO,WAAW,MAAM,yBAAyB,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAW,CAAC,CAAC;AAE3D,MAAM,CAAC,OAAO,OAAO,qBAAqB;IACxC;;;;;OAKG;IAEiB,AAAb,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,IAG7C;QACC,MAAM,KAAK,GAAa,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAE5C,MAAM,sBAAsB,GAC1B,IAAI,sBAAsB,EAAE,CAAC;QAC/B,sBAAsB,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC5C,sBAAsB,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAC1C,sBAAsB,CAAC,KAAK,GAAG,KAAK,CAAC;QACrC,sBAAsB,CAAC,OAAO,GAAG,aAAa,CAAC,gBAAgB,CAC7D,iCAAiC,CAClC,CAAC;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