pub struct Runlight(/* private fields */);Expand description
Privacy friendly web analytics that lives inside your app. A cheap handle to clone.
Implementations§
Source§impl Runlight
impl Runlight
Sourcepub fn link_router<S: Clone + Send + Sync + 'static>(&self) -> Router<S>
pub fn link_router<S: Clone + Send + Sync + 'static>(&self) -> Router<S>
A Router serving short links at {link_path}/{slug}, through LinkService: a slug with
no link is Runlight’s own 404, since a matched route cannot reach the app’s fallback.
Source§impl Runlight
impl Runlight
Sourcepub fn link_service(&self) -> LinkService
pub fn link_service(&self) -> LinkService
Short links on the app’s own domain as a tower Service: mount it at {link_path}/{slug}.
Source§impl Runlight
impl Runlight
Sourcepub fn new(options: RunlightOptions) -> Result<Runlight, String>
pub fn new(options: RunlightOptions) -> Result<Runlight, String>
A Runlight over a store. Refuses a site whose timezone or id is not one, several sites without hostnames, and two sites with one id.
Sourcepub fn app_mailer(&self) -> Option<&AppMailer>
pub fn app_mailer(&self) -> Option<&AppMailer>
The app’s own mailer, used while no service is saved in the dashboard.
Sourcepub fn mail_services(&self) -> Vec<&'static Service>
pub fn mail_services(&self) -> Vec<&'static Service>
The mail services Settings offers and saves, in their usual order: every one, unless
mail_services names fewer.
Sourcepub fn fetcher(&self) -> &SharedFetcher
pub fn fetcher(&self) -> &SharedFetcher
The fetcher everything that calls out goes through.
Sourcepub fn local_installs(&self) -> bool
pub fn local_installs(&self) -> bool
Whether a connected install may be on this machine, at http://localhost or http://127.0.0.1.
Sourcepub fn managed_sites(&self) -> bool
pub fn managed_sites(&self) -> bool
Whether sites are managed in the dashboard.
Sourcepub fn secret(&self) -> Option<&str>
pub fn secret(&self) -> Option<&str>
The secret the keys in the database are sealed with, if any.
Sourcepub async fn freshen_statistics(&self)
pub async fn freshen_statistics(&self)
Gathers planner statistics again if the events have outgrown them, at most once an hour, so an app that never runs the scheduled check still reads its reports with statistics that fit its data.
Sourcepub async fn init(&self) -> Result<(), Error>
pub async fn init(&self) -> Result<(), Error>
Creates tables and records the configured sites. Runs once.
Sourcepub fn sites(&self) -> Vec<SiteRow>
pub fn sites(&self) -> Vec<SiteRow>
The sites, with any settings changed in the dashboard applied.
Sourcepub fn remote(&self, id: &str) -> Option<Remote>
pub fn remote(&self, id: &str) -> Option<Remote>
The install a site is read from, when it is counted elsewhere.
Sourcepub async fn remote_last_seen(&self, id: &str) -> Option<f64>
pub async fn remote_last_seen(&self, id: &str) -> Option<f64>
When a connected install’s site last had a visit, asked at most once a minute.
Sourcepub async fn remote_info(&self, id: &str) -> Option<RemoteInfo>
pub async fn remote_info(&self, id: &str) -> Option<RemoteInfo>
What a connected install says about its site, asked at most once a minute.
Sourcepub fn forget_remote_info(&self, id: &str)
pub fn forget_remote_info(&self, id: &str)
Forgets what a connected install said, after a change made through it.
Sourcepub async fn add_site(&self, input: &Value) -> Result<SiteRow, Error>
pub async fn add_site(&self, input: &Value) -> Result<SiteRow, Error>
Adds a site, when sites are managed in the dashboard: one counted here, or one connected from another install.
Sourcepub async fn delete_site(&self, id: &str) -> Result<(), Error>
pub async fn delete_site(&self, id: &str) -> Result<(), Error>
Deletes a site and everything recorded for it, when sites are managed in the dashboard.
Sourcepub async fn update_site(
&self,
id: &str,
patch: &Value,
) -> Result<SiteRow, Error>
pub async fn update_site( &self, id: &str, patch: &Value, ) -> Result<SiteRow, Error>
Changes a site’s name, timezone, retention, or (when managed) hostnames from the dashboard. Every field is checked before anything changes, and pruning starts only once the change is saved.
Sourcepub async fn retention(&self, site: &str) -> Result<Option<i64>, Error>
pub async fn retention(&self, site: &str) -> Result<Option<i64>, Error>
How many months of visits a site keeps, or None to keep everything (the default).
Sourcepub async fn set_retention(
&self,
site: &str,
months: Option<i64>,
) -> Result<(), Error>
pub async fn set_retention( &self, site: &str, months: Option<i64>, ) -> Result<(), Error>
Sets how many months of visits a site keeps; the deleting runs after the answer.
Sourcepub fn later<F>(&self, work: F)
pub fn later<F>(&self, work: F)
Runs work after the answer, such as an email that must not slow a sign-in down. idle() waits for it.
Sourcepub async fn idle(&self)
pub async fn idle(&self)
Waits for retention work still running; the scheduled check and tests wait for it.
Sourcepub async fn build_rollups(&self) -> Result<usize, Error>
pub async fn build_rollups(&self) -> Result<usize, Error>
Adds up each site’s finished days, so long ranges read a row a day instead of every visit.
Sourcepub async fn retention_cutoff(&self, site: &str) -> Result<Option<i64>, Error>
pub async fn retention_cutoff(&self, site: &str) -> Result<Option<i64>, Error>
The oldest moment a site keeps visits from, or None when it keeps everything.
Sourcepub fn site(&self, id: Option<&str>) -> Option<SiteRow>
pub fn site(&self, id: Option<&str>) -> Option<SiteRow>
A site by id, or the first site when no id is given.
Sourcepub fn site_for(&self, hostname: &str, id: Option<&str>) -> Option<SiteRow>
pub fn site_for(&self, hostname: &str, id: Option<&str>) -> Option<SiteRow>
The site a page belongs to, or None if it belongs to none.
Sourcepub fn client_ip(&self, request: &Request) -> String
pub fn client_ip(&self, request: &Request) -> String
The visitor’s address, for the daily visitor hash and the rate limit.
Sourcepub async fn collect(&self, request: &Request) -> Result<(), Error>
pub async fn collect(&self, request: &Request) -> Result<(), Error>
Handles one tracker request. Always succeeds unless the database fails; bad input is dropped quietly.
Sourcepub fn forget_link_domains(&self)
pub fn forget_link_domains(&self)
Clears the cached link domains after one is added or removed.
Sourcepub async fn link_response(&self, request: &Request) -> Result<Response, Error>
pub async fn link_response(&self, request: &Request) -> Result<Response, Error>
Handles {link_path}/{slug} on the app’s own domain.
Sourcepub async fn link_domain_response(
&self,
request: &Request,
) -> Result<Option<Response>, Error>
pub async fn link_domain_response( &self, request: &Request, ) -> Result<Option<Response>, Error>
For middleware: when a request arrives on a link domain added in Settings (such as
t.example.com), answers /{slug} there with the redirect, and anything else with a 404. None
for every other host, so the app carries on as normal, and for the dashboard’s own paths.
Sourcepub async fn redirect(
&self,
request: &Request,
slug: &str,
domain: &str,
) -> Result<Option<Response>, Error>
pub async fn redirect( &self, request: &Request, slug: &str, domain: &str, ) -> Result<Option<Response>, Error>
Answers a request for a short link: a redirect to its destination, with the click recorded like
a visit but kept out of visitor and pageview counts. None when no link fits.
Sourcepub async fn observe(&self, request: &Request, at: Option<f64>) -> bool
pub async fn observe(&self, request: &Request, at: Option<f64>) -> bool
Records a request from a known AI agent. Call it from middleware for every page request; it
ignores everything else and never fails. at is when a log reader saw the page served.
The request’s address (its remote address, or a trusted proxy header, as for tracker hits) is checked against the list the agent’s company publishes and then dropped: only “verified”, “mismatch”, or “” is kept with the fetch.
Sourcepub async fn observe_with(
&self,
request: &Request,
at: Option<f64>,
agent_ip: Option<&str>,
) -> bool
pub async fn observe_with( &self, request: &Request, at: Option<f64>, agent_ip: Option<&str>, ) -> bool
Runlight::observe for a fetch a log reader or plugin reports, with the address the agent’s
request came from (agent_ip), which is checked in place of the request’s own and then dropped.
Source§impl Runlight
impl Runlight
Sourcepub async fn mail_settings(
&self,
) -> Result<Option<(Object, &'static str)>, Error>
pub async fn mail_settings( &self, ) -> Result<Option<(Object, &'static str)>, Error>
The mail Runlight sends with: a service from code, or as saved in the dashboard, or else the app’s
own mailer, as service “app” with its via, with where it came from (code, dashboard, or app).
Sourcepub async fn save_mail_settings(
&self,
input: Option<&Value>,
) -> Result<(), Error>
pub async fn save_mail_settings( &self, input: Option<&Value>, ) -> Result<(), Error>
Saves the mail service from the dashboard. A secret field left blank keeps the saved value, so the
browser never needs to see it. None removes it.
Sourcepub async fn send_mail(&self, message: Message) -> Result<(), Error>
pub async fn send_mail(&self, message: Message) -> Result<(), Error>
Sends one email through the mail service, or the app’s own mailer when no service is saved.
Sourcepub async fn send_reports(&self) -> Result<(i64, i64), Error>
pub async fn send_reports(&self) -> Result<(i64, i64), Error>
Sends every report that is due: last week’s on Monday from 8am, last month’s on the 1st, in each site’s timezone. Safe to run often; each period goes out once. Gives how many went and failed.
Sourcepub async fn deliver_report(
&self,
r: &ReportRow,
site: &SiteRow,
period: Option<&ReportPeriod>,
) -> Result<(), Error>
pub async fn deliver_report( &self, r: &ReportRow, site: &SiteRow, period: Option<&ReportPeriod>, ) -> Result<(), Error>
Builds and sends one report. Also used by “Send a sample now”.
Sourcepub async fn assistant_settings(
&self,
) -> Result<Option<AssistantSettings>, Error>
pub async fn assistant_settings( &self, ) -> Result<Option<AssistantSettings>, Error>
The dashboard assistant’s provider, model, and key, kept sealed like the mail keys.