Skip to main content

Runlight

Struct Runlight 

Source
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

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

Short links on the app’s own domain as a tower Service: mount it at {link_path}/{slug}.

Source§

impl Runlight

Short links: create, change, delete, and import.

Source§

impl Runlight

Source

pub fn routes(&self, options: RoutesOptions) -> Result<Routes, String>

The dashboard, its API, the tracker endpoint, and the pages around them.

Source§

impl Runlight

Source

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.

Source

pub fn app_mailer(&self) -> Option<&AppMailer>

The app’s own mailer, used while no service is saved in the dashboard.

Source

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.

Source

pub fn store(&self) -> &SqlStore

The store.

Source

pub fn now(&self) -> i64

The clock’s time, in epoch milliseconds.

Source

pub fn fetcher(&self) -> &SharedFetcher

The fetcher everything that calls out goes through.

Source

pub fn local_installs(&self) -> bool

Whether a connected install may be on this machine, at http://localhost or http://127.0.0.1.

Source

pub fn managed_sites(&self) -> bool

Whether sites are managed in the dashboard.

Source

pub fn secret(&self) -> Option<&str>

The secret the keys in the database are sealed with, if any.

Where links on the app’s own domain are served, such as “/go”.

Source

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.

Source

pub async fn init(&self) -> Result<(), Error>

Creates tables and records the configured sites. Runs once.

Source

pub fn sites(&self) -> Vec<SiteRow>

The sites, with any settings changed in the dashboard applied.

Source

pub fn is_remote(&self, id: &str) -> bool

Whether a site is counted by another install.

Source

pub fn remote(&self, id: &str) -> Option<Remote>

The install a site is read from, when it is counted elsewhere.

Source

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.

Source

pub async fn remote_info(&self, id: &str) -> Option<RemoteInfo>

What a connected install says about its site, asked at most once a minute.

Source

pub fn forget_remote_info(&self, id: &str)

Forgets what a connected install said, after a change made through it.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn later<F>(&self, work: F)
where F: Future<Output = ()> + Send + 'static,

Runs work after the answer, such as an email that must not slow a sign-in down. idle() waits for it.

Source

pub async fn idle(&self)

Waits for retention work still running; the scheduled check and tests wait for it.

Source

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.

Source

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.

Source

pub fn site(&self, id: Option<&str>) -> Option<SiteRow>

A site by id, or the first site when no id is given.

Source

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.

Source

pub fn client_ip(&self, request: &Request) -> String

The visitor’s address, for the daily visitor hash and the rate limit.

Source

pub async fn collect(&self, request: &Request) -> Result<(), Error>

Handles one tracker request. Always succeeds unless the database fails; bad input is dropped quietly.

Clears the cached link domains after one is added or removed.

Handles {link_path}/{slug} on the app’s own domain.

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.

Source

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.

Source

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.

Source

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

pub async fn check(&self) -> Result<Value, Error>

Scheduled upkeep, safe to run every minute: salts, retention, rollups, and the email reports that are due. Also rereads sites and their dashboard settings, so a change made by another process sharing the database shows up here too.

Source§

impl Runlight

Source

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).

Source

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.

Source

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.

Source

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.

Source

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”.

Source

pub async fn assistant_settings( &self, ) -> Result<Option<AssistantSettings>, Error>

The dashboard assistant’s provider, model, and key, kept sealed like the mail keys.

Source

pub async fn save_assistant_settings( &self, input: Option<&Value>, ) -> Result<(), Error>

Saves the assistant’s settings; an empty key keeps the one saved for the same provider. None removes them.

Trait Implementations§

Source§

impl Clone for Runlight

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more