import { AxiosInstance } from 'axios'; type TimeUnit = "year" | "month" | "day" | "hour"; type MetricType = "url" | "referrer" | "browser" | "os" | "device" | "country" | "event" | "language" | "utm_source" | "utm_medium" | "utm_campaign" | "utm_content" | "utm_term" | "ref"; interface Stats { pageviews: { value: number; change: number; }; uniques: { value: number; change: number; }; bounces: { value: number; change: number; }; totaltime: { value: number; change: number; }; } interface PageViews { /** * @param t The time period of the data * @param y The amount of page views in the time period */ pageviews: { t: string; y: number; }[]; /** * @param t The time period of the data * @param y The amount of sessions in the time period */ sessions: { t: string; y: number; }[]; } /** * @param x The name of the event * @param t The time period of the data * @param y The amount of events in the time period */ interface Event { x: string; t: string; y: number; } /** * @param x The metric's value * @param y The amount of this metric's value in the period of time */ interface Metric { x: string | null; y: number; } interface ActiveVisitor { x: number; } declare const HOUR_PERIODS: readonly ["1h", "1hour", "60min", "60minutes"]; type HourPeriod = (typeof HOUR_PERIODS)[number]; declare const DAY_PERIODS: readonly ["1d", "1day", "24h", "24hours"]; type DayPeriod = (typeof DAY_PERIODS)[number]; declare const WEEK_PERIODS: readonly ["7d", "7days", "1w", "1week"]; type WeekPeriod = (typeof WEEK_PERIODS)[number]; declare const MONTH_PERIODS: readonly ["31d", "31days", "1m", "1month"]; type MonthPeriod = (typeof MONTH_PERIODS)[number]; type TimePeriod = HourPeriod | DayPeriod | WeekPeriod | MonthPeriod; interface WebsiteData { id: number; websiteUuid: string; userId: number; name: string; domain: string; shareId: string | null; createdAt: string; } declare class Website implements WebsiteData { private readonly _apiClient; private readonly _axios; readonly id: number; readonly websiteUuid: string; userId: number; name: string; domain: string; shareId: string | null; createdAt: string; constructor(apiClient: UmamiApiClient, axios: AxiosInstance, data: WebsiteData); /** * Updates the website. * @param options.domain The domain name of the website (e.g. umami.is) * @param options.name The name of the website (usually the same as the domain) * @param options.owner The website's owner's ID (by default, the logged-in's user's) * @param options.enableShareUrl Whether or not to enable public sharing. * @returns * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/websites/[id]/index.js#L23-L57 Relevant Umami source code} */ update(options: { domain: string; name: string; owner?: number; enableShareUrl?: boolean; }): Promise; /** * Deletes the website * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/websites/[id]/index.js#L59-L67 Relevant Umami source code} */ delete(): Promise; /** * Gets the stats of the website from a specified time period * @param options.period The time period of stats to return * @param options.url Filter stats by URL * @param options.referrer Filter stats by referrer * @param options.os Filter stats by OS * @param options.browser Filter stats by browser * @param options.device Filter stats by device * @param options.country Filter stats by country * @returns The website's stats from the specified time period * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/websites/[id]/stats.js Relevant Umami source code} */ getStats(options?: { period?: TimePeriod; url?: string; referrer?: string; os?: string; browser?: string; device?: string; country?: string; }): Promise; /** * Resets the website's stats * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/websites/[id]/reset.js Relevant Umami source code} */ resetStats(): Promise; /** * Gets the pageviews of the website from a specified time period * @param options.period The time period of pageviews to return * @param options.unit The interval of time/precision of the returned pageviews * @param options.tz The timezone you're in (defaults to "America/Toronto") * @param options.url Filter pageviews by URL * @param options.referrer Filter pageviews by referrer * @param options.os Filter pageviews by OS * @param options.browser Filter pageviews by browser * @param options.device Filter pageviews by device * @param options.country Filter pageviews by country * @returns The website's pageviews from the specified time period * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/websites/[id]/pageviews.js Relevant Umami source code} */ getPageviews(options?: { period?: TimePeriod; unit?: TimeUnit; tz?: string; url?: string; referrer?: string; os?: string; browser?: string; device?: string; country?: string; }): Promise; /** * Gets the events of the website from a specified time period * @param options.period The time period of events to return * @param options.unit The interval of time/precision of the returned events * @param options.tz The timezone you're in (defaults to "America/Toronto") * @param options.url The url where the event happened. * @param options.event_type The type of event to request. * @returns An array of events from the specified time period * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/website/[id]/events.js Relevant Umami source code} */ getEvents(options?: { period?: TimePeriod; unit?: TimeUnit; tz?: string; url?: string; event_type?: string; }): Promise; /** * Gets a type of metrics of the website from a specified time period * @param options.period The time period of events to return * @param options.type The type of metric to get. Defaults to url * @param options.url Filter metrics by URL * @param options.referrer Filter metrics by referrer * @param options.os Filter metrics by OS * @param options.browser Filter metrics by browser * @param options.device Filter metrics by device * @param options.country Filter metrics by country * @returns An array of metrics from the specified time period * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/websites/[id]/metrics.js Relevant Umami source code} */ getMetrics(options?: { period?: TimePeriod; type?: MetricType; url?: string; referrer?: string; os?: string; browser?: string; device?: string; country?: string; }): Promise; /** * Gets the active visitors of a website * @returns * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/websites/[id]/active.js Relevant Umami source code} */ getActiveVisitors(): Promise; } interface UserAccountData { id: number; username: string; isAdmin: boolean; createdAt: string; updatedAt: string; accountUuid: string; } declare class UserAccount implements UserAccountData { private readonly _axios; readonly id: number; username: string; isAdmin: boolean; readonly createdAt: string; updatedAt: string; accountUuid: string; constructor(axios: AxiosInstance, data: UserAccountData); /** * Updates a user account * @param options.username New username (admin only) * @param options.password New password * @returns The user account * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/accounts/[id]/index.js#L21-L53 Relevant Umami source code} */ update(options: { username: string; password: string; }): Promise; /** * Updates a user account password * @param options.current_password Current password * @param options.new_password New password * @returns The user account * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/accounts/[id]/password.js Relevant Umami source code} */ changePassword(options: { current_password: string; new_password: string; }): Promise; /** * Deletes the user account (admin only) * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/accounts/[id]/index.js#L55-L63 Relevant Umami source code} */ delete(): Promise; } interface PageViewPayload { website: string; url: string; referrer?: string; hostname: string; language?: string; screen?: string; } interface EventPayload { website: string; url: string; referrer?: string; hostname: string; language?: string; screen?: string; event_name: string; event_data: string; } declare class UmamiApiClient { private readonly _axios; private readonly _auth; private _lastAuthCheck; getCurrentUser(): Promise<{ userId: number; username: string; isAdmin: boolean; accountUuid: string; iat?: number | undefined; shareToken?: string | undefined; }>; /** * @param server The Umami installation hostname (e.g. app.umami.is). The protocol, if present, will be removed. * @param username Username of the user you want to use. * @param password Password of the user you want to use. * @returns An authenticated class instance * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/auth/login.js Relevant Umami source code} */ constructor(server: string, username: string, password: string); private _verifyAuth; /** * Collects a pageview * @param type The type of event to send * @param payload The payload of the pageview * @param userAgent Value of the User-Agent header. Necessary for platform detection. Defaults to Firefox on Mac OS on a laptop * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/collect.js#L75 Relevant Umami source code} */ collect(type: "pageview", payload: PageViewPayload, userAgent?: string): Promise; /** * Collects an event * @param type The type of event to send * @param payload The payload of the event * @param userAgent Value of the User-Agent header. Necessary for platform detection. Defaults to Firefox on Mac OS on a laptop * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/collect.js#L77 Relevant Umami source code} */ collect(type: "event", payload: EventPayload, userAgent?: string): Promise; /** * Collects a pageview * @param server The Umami installation hostname (e.g. app.umami.is). The protocol, if present, will be removed. * @param type The type of event to send * @param payload The payload of the pageview * @param userAgent Value of the User-Agent header. Necessary for platform detection. Defaults to Firefox on Mac OS on a laptop * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/collect.js#L75 Relevant Umami source code} */ static collect(server: string, type: "pageview", payload: PageViewPayload, userAgent?: string): Promise; /** * Collects an event * @param server The Umami installation hostname (e.g. app.umami.is). The protocol, if present, will be removed. * @param type The type of event to send * @param payload The payload of the event * @param userAgent Value of the User-Agent header. Necessary for platform detection. Defaults to Firefox on Mac OS on a laptop * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/collect.js#L77 Relevant Umami source code} */ static collect(server: string, type: "event", payload: EventPayload, userAgent?: string): Promise; /** * Gets tracked websites * @param options.include_all Whether or not to include all websites (admin only) * @param options.user_id The user to query websites from (admin only, if not your own user id) * @returns An array of tracked websites * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/websites/index.js#L20-L31 Relevant Umami source code} */ getWebsites(options?: { include_all?: boolean; user_id?: number; }): Promise; /** * Gets the first website that gets returned by Umami * @returns The first website * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/websites/index.js Relevant Umami source code} */ getWebsite(): Promise; /** * Gets a website by its UUID (not ID) * @param websiteUuid The website's UUID (not ID) * @returns The website * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/websites/[id]/index.js Relevant Umami source code} */ getWebsite(websiteUuid: string): Promise; /** * Gets a website by a property * @param key The property to check * @param value The value to check the property against * @returns The website * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/websites/index.js Relevant Umami source code} * * @example * Get a website by domain name * ```ts * const website = await instance.getWebsiteBy("domain", "example.com"); * ``` */ getWebsiteBy(key: keyof Website, value: string | number): Promise; /** * Creates a new website and returns its information. * @param options.domain The domain name of the website (e.g. umami.is) * @param options.name The name of the website (usually the same as the domain) * @param options.owner The website's owner's ID (by default, the logged-in's user's) * @param options.enableShareUrl Whether or not to enable public sharing. * @returns The new website's information * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/websites/index.js#L33-L47 Relevant Umami source code} */ createWebsite(options: { domain: string; name: string; owner?: number; enableShareUrl?: boolean; }): Promise; /** * Gets all the user accounts (admin only) * @returns An array of all the user accounts * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/accounts/index.js#L15-L19 Relevant Umami source code} */ getAccounts(): Promise; /** * Gets a user account (admin only) * @param userId The user ID * @returns The user account * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/accounts/[id]/index.js#L11-L19 Relevant Umami source code} */ getAccount(userId: number): Promise; /** * Creates a user account (admin only) * @param options.username The username * @param options.password The password * @returns The user account * @see {@link https://github.com/umami-software/umami/blob/master/pages/api/accounts/index.js#L21-L37 Relevant Umami source code} */ createAccount(options: { username: string; password: string; }): Promise; } export { UmamiApiClient as default };