diff --git a/src/Pages/BodyWrapper.hs b/src/Pages/BodyWrapper.hs index 5b25d295c..66c05c524 100644 --- a/src/Pages/BodyWrapper.hs +++ b/src/Pages/BodyWrapper.hs @@ -10,8 +10,8 @@ import Models.Projects.Projects qualified as Projects import Models.Users.Sessions qualified as Sessions import Models.Users.Users qualified as Users import NeatInterpolation (text) -import Pkg.THUtils import Pkg.Components.ExternalHeadScripts (externalHeadScripts_) +import Pkg.THUtils import PyF import Relude import Utils (faSprite_) diff --git a/src/Pages/Dashboard.hs b/src/Pages/Dashboard.hs index af84f12f7..c5979b2da 100644 --- a/src/Pages/Dashboard.hs +++ b/src/Pages/Dashboard.hs @@ -115,8 +115,8 @@ dashboardPage pid paramInput currTime projectStats newEndpoints reqLatenciesRoll let bulkActionBase = "/p/" <> pid.toText <> "/anomalies/bulk_actions" section_ [class_ " mx-auto px-6 w-full space-y-12 pb-24 overflow-y-scroll h-full"] do when exceededFreeTier $ freeTierLimitExceededBanner pid.toText - unless (null newEndpoints) $ - div_ [id_ "modalContainer"] do + unless (null newEndpoints) + $ div_ [id_ "modalContainer"] do input_ [type_ "checkbox", id_ "newEndpointsModal", class_ "modal-toggle"] div_ [class_ "modal", role_ "dialog", hxSwap_ "outerHTML"] do form_ @@ -196,8 +196,8 @@ dStats pid projReqStats@Projects.ProjectRequestStats{..} reqLatenciesRolledBySte p_ "You're currently not sending any data to APItoolkit from your backends yet." a_ [href_ $ "/p/" <> pid.toText <> "/integration_guides", class_ "w-max btn btn-indigo -ml-1 text-md"] "Read the setup guide" div_ [class_ "flex justify-between mt-4"] $ div_ [class_ "flex flex-row"] do - a_ [class_ "cursor-pointer", [__|on click toggle .neg-rotate-90 on me then toggle .hidden on (next .reqResSubSection)|]] $ - faSprite_ "chevron-down" "regular" "h-4 w-4 mr-3 inline-block" + a_ [class_ "cursor-pointer", [__|on click toggle .neg-rotate-90 on me then toggle .hidden on (next .reqResSubSection)|]] + $ faSprite_ "chevron-down" "regular" "h-4 w-4 mr-3 inline-block" span_ [class_ "text-lg text-slate-700"] "Analytics" div_ [class_ "reqResSubSection space-y-5"] do diff --git a/src/Pages/Log.hs b/src/Pages/Log.hs index ebf0d8352..761be76ce 100644 --- a/src/Pages/Log.hs +++ b/src/Pages/Log.hs @@ -41,6 +41,7 @@ import Models.Users.Sessions qualified as Sessions import NeatInterpolation (text) import Pages.BodyWrapper (BWConfig (..), PageCtx (..), currProject, pageActions, pageTitle, sessM) import Pages.Components qualified as Components + -- import Pages.Monitors.Alerts qualified as Alerts import Pkg.Components qualified as Components import Pkg.Parser (pSource) diff --git a/src/Pages/Monitors/Alerts.hs b/src/Pages/Monitors/Alerts.hs index c5ca26877..352d4b93c 100644 --- a/src/Pages/Monitors/Alerts.hs +++ b/src/Pages/Monitors/Alerts.hs @@ -288,8 +288,8 @@ editAlert_ pid monitorM = do forM_ monitor.alertConfig.slackChannels addRecipientSlackTmpl_ div_ [class_ "py-5"] do - button_ [type_ "submit", class_ "btn btn-success"] $ - if isNewMonitor + button_ [type_ "submit", class_ "btn btn-success"] + $ if isNewMonitor then "Create Alert" else "Update Alert" @@ -431,6 +431,7 @@ instance ToHtml MonitorCreate where toHtml (MCMetric pid metricType) = toHtml $ monitorMetric_ pid Nothing toHtml (MCAPITests pid metricType) = toHtml $ monitorAPITests_ pid Nothing + monitorAPITests_ :: Projects.ProjectId -> Maybe Monitors.QueryMonitor -> Html () monitorAPITests_ pid monitorM = do div_ "api tests" @@ -572,7 +573,6 @@ monitorMetric_ pid monitorM = section_ [class_ "px-8 py-5 space-y-5 group/pg ove button_ [class_ "btn btn-sm btn-secondary"] "Create" - monitorSelectType_ :: Html () monitorSelectType_ = section_ [class_ "px-8 py-5 space-y-5 group/pg"] do h2_ [class_ "text-2xl py-3"] "Select a Monitor type" @@ -684,7 +684,7 @@ monitorCreatePostH pid monitorType = do { sessM = Just sess.persistentSession , currProject = Just project , pageTitle = "Create Monitor" - , pageActions = Just $ Components.timepicker_ (Just "log_explorer_form") Nothing + , pageActions = Just $ Components.timepicker_ (Just "log_explorer_form") Nothing } case monitorType of Just "errors" -> addRespHeaders $ PageCtx bwconf (MCMetric pid "errors") diff --git a/src/Pages/Monitors/MetricMonitors.hs b/src/Pages/Monitors/MetricMonitors.hs index 65472856a..566940469 100644 --- a/src/Pages/Monitors/MetricMonitors.hs +++ b/src/Pages/Monitors/MetricMonitors.hs @@ -144,13 +144,13 @@ errorLogsContent = timelineSteps :: Projects.ProjectId -> Components.TimelineSteps timelineSteps pid = - Components.TimelineSteps $ - [ Components.TimelineStep "Choose the detection method" chooseDetectionMethod_ - , Components.TimelineStep "Define the metric" (defineTheMetric_ pid) - , Components.TimelineStep "Set alert conditions" alertConditions_ - , Components.TimelineStep "Configure notification message" configureNotificationMessage_ - , Components.TimelineStep "Configure notification Channels" configureNotificationChannels_ - ] + Components.TimelineSteps + $ [ Components.TimelineStep "Choose the detection method" chooseDetectionMethod_ + , Components.TimelineStep "Define the metric" (defineTheMetric_ pid) + , Components.TimelineStep "Set alert conditions" alertConditions_ + , Components.TimelineStep "Configure notification message" configureNotificationMessage_ + , Components.TimelineStep "Configure notification Channels" configureNotificationChannels_ + ] -- Content placeholders for TimelineSteps diff --git a/src/Pages/Monitors/Routes.hs b/src/Pages/Monitors/Routes.hs index f59daa128..3763655a7 100644 --- a/src/Pages/Monitors/Routes.hs +++ b/src/Pages/Monitors/Routes.hs @@ -6,6 +6,7 @@ import Models.Projects.Projects qualified as Projects import Models.Tests.Testing qualified as TestingM import Pages.BodyWrapper (PageCtx (..)) import Pages.Monitors.Alerts qualified as Alerts +import Pages.Monitors.MetricMonitors qualified as MetricMonitors import Pages.Monitors.TestCollectionEditor qualified as TestCollectionEditor import Pages.Monitors.TestCollectionEditor qualified as Testing import Pages.Monitors.Testing qualified as Testing @@ -16,39 +17,42 @@ import Servant (Capture, FormUrlEncoded, GenericMode (type (:-)), Get, JSON, Nam import Servant qualified import Servant.HTML.Lucid (HTML) import System.Types (ATAuthCtx, RespHeaders) -import Pages.Monitors.MetricMonitors qualified as MetricMonitors + type Routes = NamedRoutes Routes' + type role Routes' nominal + data Routes' mode = Routes' - { alertUpsertPost :: mode :- "alerts" :> ReqBody '[FormUrlEncoded] Alerts.AlertUpsertForm :> Post '[HTML] (RespHeaders Alerts.Alert), - alertListGet :: mode :- "alerts" :> Get '[HTML] (RespHeaders Alerts.Alert), - alertSingleGet :: mode :- "alerts" :> Capture "alert_id" Monitors.QueryMonitorId :> Get '[HTML] (RespHeaders Alerts.Alert), - alertSingleToggleActive :: mode :- "alerts" :> Capture "alert_id" Monitors.QueryMonitorId :> "toggle_active" :> Post '[HTML] (RespHeaders Alerts.Alert), - monitorListGet :: mode :- "monitors" :> QueryParam "filter" Text :> Get '[HTML] (RespHeaders (PageCtx (ItemsList.ItemsPage Testing.CollectionListItemVM))), - monitorCreatePost :: mode :- "monitors" :> "create" :> QPT "monitor-type" :> Get '[HTML] (RespHeaders (PageCtx MetricMonitors.MonitorCreate)), - newCollectionPost :: mode :- "testing" :> ReqBody '[JSON] Testing.CollectionStepUpdateForm :> Post '[HTML] (RespHeaders (PageCtx (ItemsList.ItemsPage Testing.CollectionListItemVM))), - collectionGet :: mode :- "testing" :> Capture "collection_id" TestingM.CollectionId :> Get '[HTML] (RespHeaders Testing.CollectionGet), - collectionDashboardGet :: mode :- "testing" :> Capture "collection_id" TestingM.CollectionId :> "overview" :> Get '[HTML] (RespHeaders (PageCtx (Html ()))), - collectionStepsUpdate :: mode :- "testing" :> Capture "collection_id" TestingM.CollectionId :> ReqBody '[JSON] Testing.CollectionStepUpdateForm :> Post '[HTML] (RespHeaders Testing.CollectionMut), - collectionRunTests :: mode :- "testing" :> Capture "collection_id" TestingM.CollectionId :> QueryParam "step_index" Int :> ReqBody '[JSON] Testing.CollectionStepUpdateForm :> Patch '[HTML] (RespHeaders Testing.CollectionRunTest) + { alertUpsertPost :: mode :- "alerts" :> ReqBody '[FormUrlEncoded] Alerts.AlertUpsertForm :> Post '[HTML] (RespHeaders Alerts.Alert) + , alertListGet :: mode :- "alerts" :> Get '[HTML] (RespHeaders Alerts.Alert) + , alertSingleGet :: mode :- "alerts" :> Capture "alert_id" Monitors.QueryMonitorId :> Get '[HTML] (RespHeaders Alerts.Alert) + , alertSingleToggleActive :: mode :- "alerts" :> Capture "alert_id" Monitors.QueryMonitorId :> "toggle_active" :> Post '[HTML] (RespHeaders Alerts.Alert) + , monitorListGet :: mode :- "monitors" :> QueryParam "filter" Text :> Get '[HTML] (RespHeaders (PageCtx (ItemsList.ItemsPage Testing.CollectionListItemVM))) + , monitorCreatePost :: mode :- "monitors" :> "create" :> QPT "monitor-type" :> Get '[HTML] (RespHeaders (PageCtx MetricMonitors.MonitorCreate)) + , newCollectionPost :: mode :- "testing" :> ReqBody '[JSON] Testing.CollectionStepUpdateForm :> Post '[HTML] (RespHeaders (PageCtx (ItemsList.ItemsPage Testing.CollectionListItemVM))) + , collectionGet :: mode :- "testing" :> Capture "collection_id" TestingM.CollectionId :> Get '[HTML] (RespHeaders Testing.CollectionGet) + , collectionDashboardGet :: mode :- "testing" :> Capture "collection_id" TestingM.CollectionId :> "overview" :> Get '[HTML] (RespHeaders (PageCtx (Html ()))) + , collectionStepsUpdate :: mode :- "testing" :> Capture "collection_id" TestingM.CollectionId :> ReqBody '[JSON] Testing.CollectionStepUpdateForm :> Post '[HTML] (RespHeaders Testing.CollectionMut) + , collectionRunTests :: mode :- "testing" :> Capture "collection_id" TestingM.CollectionId :> QueryParam "step_index" Int :> ReqBody '[JSON] Testing.CollectionStepUpdateForm :> Patch '[HTML] (RespHeaders Testing.CollectionRunTest) } deriving stock (Generic) + server :: Projects.ProjectId -> Servant.ServerT Routes ATAuthCtx server pid = Routes' - { alertUpsertPost = Alerts.alertUpsertPostH pid, - alertListGet = Alerts.alertListGetH pid, - alertSingleGet = Alerts.alertSingleGetH pid, - alertSingleToggleActive = Alerts.alertSingleToggleActiveH pid, - monitorListGet = Testing.testingGetH pid, - monitorCreatePost = MetricMonitors.monitorCreateGetH pid, - newCollectionPost = Testing.testingPostH pid, - collectionGet = TestCollectionEditor.collectionGetH pid, - collectionStepsUpdate = TestCollectionEditor.collectionStepsUpdateH pid, - collectionRunTests = TestCollectionEditor.collectionRunTestsH pid, - collectionDashboardGet = Testing.collectionDashboard pid + { alertUpsertPost = Alerts.alertUpsertPostH pid + , alertListGet = Alerts.alertListGetH pid + , alertSingleGet = Alerts.alertSingleGetH pid + , alertSingleToggleActive = Alerts.alertSingleToggleActiveH pid + , monitorListGet = Testing.testingGetH pid + , monitorCreatePost = MetricMonitors.monitorCreateGetH pid + , newCollectionPost = Testing.testingPostH pid + , collectionGet = TestCollectionEditor.collectionGetH pid + , collectionStepsUpdate = TestCollectionEditor.collectionStepsUpdateH pid + , collectionRunTests = TestCollectionEditor.collectionRunTestsH pid + , collectionDashboardGet = Testing.collectionDashboard pid } diff --git a/src/Pages/Monitors/TestCollectionEditor.hs b/src/Pages/Monitors/TestCollectionEditor.hs index 9ecb381db..a74f10b18 100644 --- a/src/Pages/Monitors/TestCollectionEditor.hs +++ b/src/Pages/Monitors/TestCollectionEditor.hs @@ -201,13 +201,13 @@ testSettingsModalContent_ isUpdate col = div_ [class_ "space-y-5 w-96"] do timelineSteps :: Projects.ProjectId -> Components.TimelineSteps timelineSteps pid = - Components.TimelineSteps $ - [ Components.TimelineStep "Define API test" defineTestSteps_ - , Components.TimelineStep "Name and tag your test" nameOfTest_ - , -- , Components.TimelineStep "Select locations" (defineTheMetric_ pid) - Components.TimelineStep "Define retry conditions" (MetricMonitors.configureNotificationMessage_) - , Components.TimelineStep "Define Scheduling and alert conditions" (MetricMonitors.configureNotificationChannels_) - ] + Components.TimelineSteps + $ [ Components.TimelineStep "Define API test" defineTestSteps_ + , Components.TimelineStep "Name and tag your test" nameOfTest_ + , -- , Components.TimelineStep "Select locations" (defineTheMetric_ pid) + Components.TimelineStep "Define retry conditions" (MetricMonitors.configureNotificationMessage_) + , Components.TimelineStep "Define Scheduling and alert conditions" (MetricMonitors.configureNotificationChannels_) + ] nameOfTest_ :: Html () @@ -366,13 +366,13 @@ collectionStepResult_ idx stepResult = section_ [class_ "p-1"] do p_ [class_ $ "block badge badge-sm " <> getStatusColor stepResult.request.resp.status, term "data-tippy-content" "status"] $ show stepResult.request.resp.status div_ [role_ "tablist", class_ "tabs tabs-lifted"] do input_ [type_ "radio", name_ $ "step-result-tabs-" <> show idx, role_ "tab", class_ "tab", Aria.label_ "Response Log", checked_] - div_ [role_ "tabpanel", class_ "tab-content bg-base-100 border-base-300 rounded-box p-6"] $ - toHtmlRaw $ - textToHTML stepResult.stepLog + div_ [role_ "tabpanel", class_ "tab-content bg-base-100 border-base-300 rounded-box p-6"] + $ toHtmlRaw + $ textToHTML stepResult.stepLog input_ [type_ "radio", name_ $ "step-result-tabs-" <> show idx, role_ "tab", class_ "tab", Aria.label_ "Response Headers"] - div_ [role_ "tabpanel", class_ "tab-content bg-base-100 border-base-300 rounded-box p-6 "] $ - table_ [class_ "table table-xs"] do + div_ [role_ "tabpanel", class_ "tab-content bg-base-100 border-base-300 rounded-box p-6 "] + $ table_ [class_ "table table-xs"] do thead_ [] $ tr_ [] $ th_ [] "Name" >> th_ [] "Value" tbody_ $ forM_ (M.toList stepResult.request.resp.headers) $ \(k, v) -> tr_ [] do td_ [] $ toHtml k diff --git a/src/Pkg/Components/ItemsList.hs b/src/Pkg/Components/ItemsList.hs index 35089499a..5f2a9695c 100644 --- a/src/Pkg/Components/ItemsList.hs +++ b/src/Pkg/Components/ItemsList.hs @@ -161,8 +161,8 @@ itemsList_ listCfg items = , hxIndicator_ "#sortLoader" ] do - div_ [class_ "flex flex-col items-center justify-center px-3"] $ - if isActive then faSprite_ "icon-checkmark4" "solid" "w-4 h-5" else div_ [class_ "w-4 h-5"] "" + div_ [class_ "flex flex-col items-center justify-center px-3"] + $ if isActive then faSprite_ "icon-checkmark4" "solid" "w-4 h-5" else div_ [class_ "w-4 h-5"] "" div_ [class_ "grow space-y-1"] do span_ [class_ "block text-lg"] $ toHtml title span_ [class_ "block "] $ toHtml desc @@ -209,8 +209,8 @@ itemRows_ :: (Monad m, ToHtml a) => Maybe Text -> V.Vector a -> HtmlT m () itemRows_ nextFetchUrl items = do mapM_ toHtml items whenJust nextFetchUrl \url -> - when (length items > 9) $ - a_ + when (length items > 9) + $ a_ [ class_ "cursor-pointer flex justify-center items-center p-1 blue-800 bg-blue-100 hover:bg-blue-200 text-center" , hxTrigger_ "click, intersect once" , hxSwap_ "outerHTML" diff --git a/src/Pkg/RouteUtils.hs b/src/Pkg/RouteUtils.hs index 3fe40e1f7..f99ff0983 100644 --- a/src/Pkg/RouteUtils.hs +++ b/src/Pkg/RouteUtils.hs @@ -1,10 +1,11 @@ -module Pkg.RouteUtils (QPT , QP, QPU,QPB, QPI, QEID, ProjectId, GetRedirect ) where +module Pkg.RouteUtils (QPT, QP, QPU, QPB, QPI, QEID, ProjectId, GetRedirect) where +import Data.Time (UTCTime) +import Models.Apis.Endpoints qualified as Endpoints +import Models.Projects.Projects qualified as Projects import Relude import Servant -import Models.Apis.Endpoints qualified as Endpoints -import Data.Time (UTCTime) -import Models.Projects.Projects qualified as Projects + type QPT a = QueryParam a Text diff --git a/src/Web/Routes.hs b/src/Web/Routes.hs index 11f876dd8..dbb089578 100644 --- a/src/Web/Routes.hs +++ b/src/Web/Routes.hs @@ -60,41 +60,44 @@ import Web.ClientMetadata qualified as ClientMetadata import Web.Cookie (SetCookie) import Web.Error + type role Routes nominal + data Routes mode = Routes - { public :: mode :- "public" :> Servant.Raw, - cookieProtected :: mode :- AuthProtect "optional-cookie-auth" :> Servant.NamedRoutes CookieProtectedRoutes, - ping :: mode :- "ping" :> Get '[PlainText] Text, - status :: mode :- "status" :> Get '[JSON] Status, - login :: mode :- "login" :> GetRedirect '[HTML] (Headers '[Header "Location" Text, Header "Set-Cookie" SetCookie] NoContent), - toLogin :: mode :- "to_login" :> GetRedirect '[HTML] (Headers '[Header "Location" Text, Header "Set-Cookie" SetCookie] NoContent), - logout :: mode :- "logout" :> GetRedirect '[HTML] (Headers '[Header "Location" Text, Header "Set-Cookie" SetCookie] NoContent), - authCallback :: mode :- "auth_callback" :> QPT "code" :> QPT "state" :> GetRedirect '[HTML] (Headers '[Header "Location" Text, Header "Set-Cookie" SetCookie] (Html ())), - shareLinkGet :: mode :- "share" :> "r" :> Capture "shareID" UUID.UUID :> Get '[HTML] Share.ShareLinkGet, - slackLinkProjectGet :: mode :- "slack" :> "oauth" :> "callback" :> Capture "project_id" Projects.ProjectId :> QPT "code" :> Get '[HTML] SlackInstall.SlackLink, - clientMetadata :: mode :- "api" :> "client_metadata" :> Header "Authorization" Text :> Get '[JSON] ClientMetadata.ClientMetadata, - lemonWebhook :: mode :- "webhook" :> "lemon-squeezy" :> Header "X-Signature" Text :> ReqBody '[JSON] LemonSqueezy.WebhookData :> Post '[HTML] (Html ()) + { public :: mode :- "public" :> Servant.Raw + , cookieProtected :: mode :- AuthProtect "optional-cookie-auth" :> Servant.NamedRoutes CookieProtectedRoutes + , ping :: mode :- "ping" :> Get '[PlainText] Text + , status :: mode :- "status" :> Get '[JSON] Status + , login :: mode :- "login" :> GetRedirect '[HTML] (Headers '[Header "Location" Text, Header "Set-Cookie" SetCookie] NoContent) + , toLogin :: mode :- "to_login" :> GetRedirect '[HTML] (Headers '[Header "Location" Text, Header "Set-Cookie" SetCookie] NoContent) + , logout :: mode :- "logout" :> GetRedirect '[HTML] (Headers '[Header "Location" Text, Header "Set-Cookie" SetCookie] NoContent) + , authCallback :: mode :- "auth_callback" :> QPT "code" :> QPT "state" :> GetRedirect '[HTML] (Headers '[Header "Location" Text, Header "Set-Cookie" SetCookie] (Html ())) + , shareLinkGet :: mode :- "share" :> "r" :> Capture "shareID" UUID.UUID :> Get '[HTML] Share.ShareLinkGet + , slackLinkProjectGet :: mode :- "slack" :> "oauth" :> "callback" :> Capture "project_id" Projects.ProjectId :> QPT "code" :> Get '[HTML] SlackInstall.SlackLink + , clientMetadata :: mode :- "api" :> "client_metadata" :> Header "Authorization" Text :> Get '[JSON] ClientMetadata.ClientMetadata + , lemonWebhook :: mode :- "webhook" :> "lemon-squeezy" :> Header "X-Signature" Text :> ReqBody '[JSON] LemonSqueezy.WebhookData :> Post '[HTML] (Html ()) } deriving stock (Generic) -server :: - Pool PG.Connection -> - Routes (AsServerT ATBaseCtx) + +server + :: Pool PG.Connection + -> Routes (AsServerT ATBaseCtx) server pool = Routes - { public = Servant.serveDirectoryWebApp "./static/public", - ping = pingH, - status = statusH, - login = Auth.loginH, - toLogin = Auth.loginRedirectH, - logout = Auth.logoutH, - authCallback = Auth.authCallbackH, - shareLinkGet = Share.shareLinkGetH, - slackLinkProjectGet = SlackInstall.linkProjectGetH, - clientMetadata = ClientMetadata.clientMetadataH, - lemonWebhook = LemonSqueezy.webhookPostH, - cookieProtected = \sessionWithCookies -> + { public = Servant.serveDirectoryWebApp "./static/public" + , ping = pingH + , status = statusH + , login = Auth.loginH + , toLogin = Auth.loginRedirectH + , logout = Auth.logoutH + , authCallback = Auth.authCallbackH + , shareLinkGet = Share.shareLinkGetH + , slackLinkProjectGet = SlackInstall.linkProjectGetH + , clientMetadata = ClientMetadata.clientMetadataH + , lemonWebhook = LemonSqueezy.webhookPostH + , cookieProtected = \sessionWithCookies -> Servant.hoistServerWithContext (Proxy @(Servant.NamedRoutes CookieProtectedRoutes)) (Proxy @'[APItoolkitAuthContext]) @@ -107,8 +110,10 @@ server pool = cookieProtectedServer } + type role CookieProtectedRoutes nominal + data CookieProtectedRoutes mode = CookieProtectedRoutes { dashboardGet :: mode :- "p" :> ProjectId :> QPT "from" :> QPT "to" :> QPT "since" :> Get '[HTML] (RespHeaders (PageCtx Dashboard.DashboardGet)) , projects :: mode :- ProjectsRoutes.Routes @@ -139,46 +144,50 @@ data CookieProtectedRoutes mode = CookieProtectedRoutes } deriving stock (Generic) + cookieProtectedServer :: Servant.ServerT (Servant.NamedRoutes CookieProtectedRoutes) ATAuthCtx cookieProtectedServer = CookieProtectedRoutes - { dashboardGet = Dashboard.dashboardGetH, - projects = ProjectsRoutes.server, - onboardingGet = Onboarding.onboardingGetH, - logExplorer = LogExplorerRoutes.server, - anomalies = AnomaliesRoutes.server, - endpoints = EndpointsRoutes.server, - monitors = MonitorsRoutes.server, - specification = SpecificationRoutes.server, - traces = TracesRoutes.server, - apiGet = Api.apiGetH, - apiDelete = Api.apiDeleteH, - apiPost = Api.apiPostH, - slackInstallPost = SlackInstall.postH, - slackUpdateWebhook = SlackInstall.updateWebHook, - reportsGet = Reports.reportsGetH, - reportsSingleGet = Reports.singleReportGetH, - reportsPost = Reports.reportsPostH, - shareLinkPost = Share.shareLinkPostH, - queryBuilderAutocomplete = AutoComplete.getH, - swaggerGenerateGet = GenerateSwagger.generateGetH, - chartsGet = Charts.chartsGetH, - surveyPut = Survey.surveyPutH, - surveyGet = Survey.surveyGetH, - editField = FieldDetails.fieldPutH, - integrationGuides = IntegrationGuides.getH, - manageBillingGet = LemonSqueezy.manageBillingGetH + { dashboardGet = Dashboard.dashboardGetH + , projects = ProjectsRoutes.server + , onboardingGet = Onboarding.onboardingGetH + , logExplorer = LogExplorerRoutes.server + , anomalies = AnomaliesRoutes.server + , endpoints = EndpointsRoutes.server + , monitors = MonitorsRoutes.server + , specification = SpecificationRoutes.server + , traces = TracesRoutes.server + , apiGet = Api.apiGetH + , apiDelete = Api.apiDeleteH + , apiPost = Api.apiPostH + , slackInstallPost = SlackInstall.postH + , slackUpdateWebhook = SlackInstall.updateWebHook + , reportsGet = Reports.reportsGetH + , reportsSingleGet = Reports.singleReportGetH + , reportsPost = Reports.reportsPostH + , shareLinkPost = Share.shareLinkPostH + , queryBuilderAutocomplete = AutoComplete.getH + , swaggerGenerateGet = GenerateSwagger.generateGetH + , chartsGet = Charts.chartsGetH + , surveyPut = Survey.surveyPutH + , surveyGet = Survey.surveyGetH + , editField = FieldDetails.fieldPutH + , integrationGuides = IntegrationGuides.getH + , manageBillingGet = LemonSqueezy.manageBillingGetH } + -- | The context that will be made available to request handlers. We supply the -- "cookie-auth"-tagged request handler defined above, so that the 'HasServer' instance -- of 'AuthProtect' can extract the handler and run it on the request. genAuthServerContext :: Logger -> AuthContext -> Servant.Context '[APItoolkitAuthContext, Servant.ErrorFormatters] genAuthServerContext logger env = authHandler logger env :. errorFormatters env :. EmptyContext + errorFormatters :: AuthContext -> Servant.ErrorFormatters errorFormatters env = - Servant.defaultErrorFormatters {Servant.notFoundErrorFormatter = notFoundPage env} + Servant.defaultErrorFormatters{Servant.notFoundErrorFormatter = notFoundPage env} + notFoundPage :: AuthContext -> Servant.NotFoundErrorFormatter notFoundPage env _req = @@ -187,16 +196,18 @@ notFoundPage env _req = Left err -> err Right _ -> Servant.err404 + data Status = Status - { dbVersion :: Maybe Text, - gitHash :: Text, - gitCommitDate :: Text + { dbVersion :: Maybe Text + , gitHash :: Text + , gitCommitDate :: Text } deriving stock (Generic) deriving (FromJSON, ToJSON) via DAE.CustomJSON '[DAE.OmitNothingFields, DAE.FieldLabelModifier '[DAE.CamelToSnake]] Status + statusH :: ATBaseCtx Status statusH = do let query = [sql| select version(); |] @@ -205,15 +216,17 @@ statusH = do let gi = $$tGitInfoCwd pure Status - { dbVersion = version, - gitHash = toText $ giHash gi, - gitCommitDate = toText $ giCommitDate gi + { dbVersion = version + , gitHash = toText $ giHash gi + , gitCommitDate = toText $ giCommitDate gi } + pingH :: ATBaseCtx Text pingH = do pure "pong" + -- When bystring is returned for json, simply return the bytestring instance Servant.MimeRender JSON ByteString where mimeRender _ = fromStrict