umami-api-js 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -1,5 +1,4 @@
1
1
  A package to interact with [the API of self-hosted instances of Umami v2.19.0](https://umami.is/docs/api). It is a lightweight alternative to [@umami/api-client](https://github.com/umami-software/api-client), forked from [osu-api-v2-js](https://github.com/TTTaevas/osu-api-v2-js).
2
2
 
3
- Please note that this package is not expected to work with Umami Cloud, the instance of Umami hosted by its creators.
3
+ Please note that this package is expected to work with self-hosted instances of **Umami v2.19.0**, and is *not* expected to work with [Umami Cloud](https://umami.is/docs/cloud), the instance of Umami hosted by its creators.
4
4
 
5
- Please also note that this is currently being built mainly to serve as a component to my [taevas.xyz](https://codeberg.org/Taevas/taevas.xyz) project, meaning it currently doesn't perfectly cover the API!
package/dist/index.d.ts CHANGED
@@ -1,21 +1,53 @@
1
1
  import { Admin } from "./namespaces/Admin.js";
2
2
  import { Events } from "./namespaces/Events.js";
3
3
  import { Realtime } from "./namespaces/Realtime.js";
4
+ import { Reports } from "./namespaces/Reports.js";
5
+ import { Sessions } from "./namespaces/Sessions.js";
4
6
  import { Teams } from "./namespaces/Teams.js";
5
7
  import { Users } from "./namespaces/Users.js";
6
- export { Admin, Users, Teams, Events, Realtime };
8
+ import { Websites } from "./namespaces/Websites.js";
9
+ import { WebsiteStats } from "./namespaces/WebsiteStats.js";
10
+ export { Admin, Users, Teams, Events, Sessions, Websites, WebsiteStats, Realtime, Reports };
7
11
  export interface ValueAndPrev {
8
12
  /** The actual value for the given time period */
9
13
  value: number;
10
14
  /** The value for the same *timespan* for the time period that ends where the time period for value starts */
11
15
  prev: number;
12
16
  }
17
+ export interface MinimalUser {
18
+ id: string;
19
+ username: string;
20
+ }
13
21
  export interface GenericObject {
14
22
  id: string;
15
23
  createdAt: Date;
16
24
  updatedAt: Date | null;
17
25
  deletedAt: Date | null;
18
26
  }
27
+ export interface Website extends GenericObject {
28
+ name: string;
29
+ domain: string;
30
+ shareId: string | null;
31
+ resetAt: Date | null;
32
+ userId: string;
33
+ teamId: string | null;
34
+ createdBy: string;
35
+ }
36
+ export interface Report extends Omit<GenericObject, "deletedAt"> {
37
+ userId: string;
38
+ websiteId: string;
39
+ type: string;
40
+ name: string;
41
+ description: string;
42
+ parameters: {
43
+ type: string;
44
+ value: string;
45
+ };
46
+ }
47
+ export interface NameValue {
48
+ name: string;
49
+ value: number;
50
+ }
19
51
  export interface GenericRequestParameters {
20
52
  /** Search text */
21
53
  search?: string;
@@ -24,6 +56,54 @@ export interface GenericRequestParameters {
24
56
  /** Determines how many results to return **(default: 20)** */
25
57
  pageSize?: number;
26
58
  }
59
+ export interface Timestamps {
60
+ /** Timestamp of starting date */
61
+ startAt: Date | number;
62
+ /** Timestamp of end date */
63
+ endAt: Date | number;
64
+ }
65
+ export interface XTY {
66
+ /** Event name */
67
+ x: string;
68
+ /** Timestamp */
69
+ t: Date;
70
+ /** Number of events */
71
+ y: number;
72
+ }
73
+ /**
74
+ * Many endpoints can make use of the filters in this interface
75
+ * @remarks As defined in the server documentation for the Endpoints in: Events, Sessions, Website stats, Reports
76
+ */
77
+ export interface Filters {
78
+ /** Name of URL */
79
+ path?: string;
80
+ /** Name of referrer */
81
+ referrer?: string;
82
+ /** Name of page title */
83
+ title?: string;
84
+ /** Name of query parameter */
85
+ query?: string;
86
+ /** Name of browser */
87
+ browser?: string;
88
+ /** Name of operating system */
89
+ os?: string;
90
+ /** Name of device (ex. Mobile) */
91
+ device?: string;
92
+ /** Name of country */
93
+ country?: string;
94
+ /** Name of region/state/province */
95
+ region?: string;
96
+ /** Name of city */
97
+ city?: string;
98
+ /** Name of hostname */
99
+ hostname?: string;
100
+ /** Name of tag */
101
+ tag?: string;
102
+ /** UUID of segment */
103
+ segment?: string;
104
+ /** UUID of cohort */
105
+ cohort?: string;
106
+ }
27
107
  export type Role = "admin" | "user" | "view-only";
28
108
  export type TeamRole = "team-manager" | "team-member" | "team-view-only";
29
109
  /** If the {@link API} throws an error, it should always be an {@link APIError}! */
@@ -106,9 +186,9 @@ export declare class API {
106
186
  /** If {@link API.setNewToken} has been called, you can wait for it to be done through this promise */
107
187
  private token_promise;
108
188
  /**
109
- * This creates a new {@link API.token}, alongside a new {@link API.refresh_token} if arguments are provided or if a refresh_token already exists
189
+ * This contacts the server in order to get and set a new {@link API.token}!
110
190
  * @remarks The API object requires a {@link API.username} and a {@link API.password} to successfully get any token
111
- * @returns Whether or not the token has changed (this should never throw)
191
+ * @returns Whether or not the token has changed (**should be true** as otherwise the server would complain and an {@link APIError} would be thrown to give you some details)
112
192
  */
113
193
  setNewToken(): Promise<boolean>;
114
194
  private _set_token_on_401;
@@ -186,12 +266,12 @@ export declare class API {
186
266
  * @param method The type of request, each endpoint uses a specific one (if it uses multiple, the intent and parameters become different)
187
267
  * @param endpoint What comes in the URL after `api/`, **DO NOT USE TEMPLATE LITERALS (\`) OR THE ADDITION OPERATOR (+), put everything separately for type safety**
188
268
  * @param parameters The things to specify in the request, such as the beatmap_id when looking for a beatmap
189
- * @param settings Additional settings **to add** to the current settings of the `fetch()` request
190
269
  * @returns A Promise with the API's response
191
270
  */
192
271
  request(method: "get" | "post" | "put" | "delete", endpoint: Array<string | number>, parameters?: {
193
272
  [k: string]: any;
194
273
  }): Promise<any>;
274
+ /** @remarks To be replaced by {@link API.getWebsiteStats2}, no deprecation warning as the new method is unreliable */
195
275
  getWebsiteStats(website_id: string, startAt: Date, endAt: Date): Promise<{
196
276
  pageviews: ValueAndPrev;
197
277
  visitors: ValueAndPrev;
@@ -227,5 +307,39 @@ export declare class API {
227
307
  readonly getWebsiteEventsDataProperties: typeof Events.getWebsiteEventsDataProperties;
228
308
  readonly getWebsiteEventsDataValues: typeof Events.getWebsiteEventsDataValues;
229
309
  readonly getWebsiteEventsDataStats: typeof Events.getWebsiteEventsDataStats;
310
+ readonly getWebsiteSessions: typeof Sessions.getWebsiteSessions;
311
+ readonly getWebsiteSessionsStats: typeof Sessions.getWebsiteSessionsStats;
312
+ readonly getWebsiteSessionsWeekly: typeof Sessions.getWebsiteSessionsWeekly;
313
+ readonly getWebsiteSession: typeof Sessions.getWebsiteSession;
314
+ readonly getWebsiteSessionActivity: typeof Sessions.getWebsiteSessionActivity;
315
+ readonly getWebsiteSessionProperties: typeof Sessions.getWebsiteSessionProperties;
316
+ readonly getWebsiteSessionDataProperties: typeof Sessions.getWebsiteSessionDataProperties;
317
+ readonly getWebsiteSessionDataValues: typeof Sessions.getWebsiteSessionDataValues;
318
+ readonly getWebsites: typeof Websites.getWebsites;
319
+ readonly createWebsite: typeof Websites.createWebsite;
320
+ readonly getWebsite: typeof Websites.getWebsite;
321
+ readonly updateWebsite: typeof Websites.updateWebsite;
322
+ readonly deleteWebsite: typeof Websites.deleteWebsite;
323
+ readonly resetWebsite: typeof Websites.resetWebsite;
324
+ readonly getWebsiteActiveVisitors: typeof WebsiteStats.getWebsiteActiveVisitors;
325
+ readonly getWebsiteEventsStats: typeof WebsiteStats.getWebsiteEvents;
326
+ readonly getWebsiteMetrics: typeof WebsiteStats.getWebsiteMetrics;
327
+ readonly getWebsiteMetricsExpanded: typeof WebsiteStats.getWebsiteMetricsExpanded;
328
+ readonly getWebsitePageviews: typeof WebsiteStats.getWebsitePageviews;
329
+ /** @remarks Will replace {@link API.getWebsiteStats}, which you should use for a reliable experience */
330
+ readonly getWebsiteStats2: typeof WebsiteStats.getWebsiteStats;
230
331
  readonly getRealtime: typeof Realtime.getRealtime;
332
+ readonly getReports: typeof Reports.getReports;
333
+ readonly createReport: typeof Reports.createReport;
334
+ readonly getReport: typeof Reports.getReport;
335
+ readonly updateReport: typeof Reports.updateReport;
336
+ readonly deleteReport: typeof Reports.deleteReport;
337
+ readonly getReportsAttribution: typeof Reports.getReportsAttribution;
338
+ readonly getReportsBreakdown: typeof Reports.getReportsBreakdown;
339
+ readonly getReportsFunnel: typeof Reports.getReportsFunnel;
340
+ readonly getReportsGoals: typeof Reports.getReportsGoals;
341
+ readonly getReportsJourney: typeof Reports.getReportsJourney;
342
+ readonly getReportsRetention: typeof Reports.getReportsRetention;
343
+ readonly getReportsRevenue: typeof Reports.getReportsRevenue;
344
+ readonly getReportsUTM: typeof Reports.getReportsUTM;
231
345
  }
package/dist/index.js CHANGED
@@ -1,10 +1,14 @@
1
1
  import { Admin } from "./namespaces/Admin.js";
2
2
  import { Events } from "./namespaces/Events.js";
3
3
  import { Realtime } from "./namespaces/Realtime.js";
4
+ import { Reports } from "./namespaces/Reports.js";
5
+ import { Sessions } from "./namespaces/Sessions.js";
4
6
  import { Teams } from "./namespaces/Teams.js";
5
7
  import { Users } from "./namespaces/Users.js";
8
+ import { Websites } from "./namespaces/Websites.js";
9
+ import { WebsiteStats } from "./namespaces/WebsiteStats.js";
6
10
  import { adaptParametersForGETRequests, correctType } from "./utilities.js";
7
- export { Admin, Users, Teams, Events, Realtime };
11
+ export { Admin, Users, Teams, Events, Sessions, Websites, WebsiteStats, Realtime, Reports };
8
12
  /** If the {@link API} throws an error, it should always be an {@link APIError}! */
9
13
  export class APIError extends Error {
10
14
  message;
@@ -109,9 +113,9 @@ export class API {
109
113
  /** If {@link API.setNewToken} has been called, you can wait for it to be done through this promise */
110
114
  token_promise = new Promise(r => r);
111
115
  /**
112
- * This creates a new {@link API.token}, alongside a new {@link API.refresh_token} if arguments are provided or if a refresh_token already exists
116
+ * This contacts the server in order to get and set a new {@link API.token}!
113
117
  * @remarks The API object requires a {@link API.username} and a {@link API.password} to successfully get any token
114
- * @returns Whether or not the token has changed (this should never throw)
118
+ * @returns Whether or not the token has changed (**should be true** as otherwise the server would complain and an {@link APIError} would be thrown to give you some details)
115
119
  */
116
120
  async setNewToken() {
117
121
  const old_token = this.token;
@@ -265,6 +269,9 @@ export class API {
265
269
  let error_message = "no error message available";
266
270
  if (!is_token_related)
267
271
  await this.token_promise.catch(() => this.token_promise = new Promise(r => r));
272
+ for (const [p, v] of Object.entries(parameters)) {
273
+ parameters[p] = v instanceof Date ? Number(v) : v; // Convert Dates to ms
274
+ }
268
275
  let url = `${this.server}`;
269
276
  if (url.slice(-1) !== "/")
270
277
  url += "/";
@@ -346,7 +353,6 @@ export class API {
346
353
  * @param method The type of request, each endpoint uses a specific one (if it uses multiple, the intent and parameters become different)
347
354
  * @param endpoint What comes in the URL after `api/`, **DO NOT USE TEMPLATE LITERALS (\`) OR THE ADDITION OPERATOR (+), put everything separately for type safety**
348
355
  * @param parameters The things to specify in the request, such as the beatmap_id when looking for a beatmap
349
- * @param settings Additional settings **to add** to the current settings of the `fetch()` request
350
356
  * @returns A Promise with the API's response
351
357
  */
352
358
  async request(method, endpoint, parameters = {}) {
@@ -372,8 +378,9 @@ export class API {
372
378
  throw new APIError(`${e?.name} (${e?.message ?? e?.errno ?? e?.type})`, this.server, method, endpoint, parameters, undefined, e);
373
379
  }
374
380
  }
381
+ /** @remarks To be replaced by {@link API.getWebsiteStats2}, no deprecation warning as the new method is unreliable */
375
382
  async getWebsiteStats(website_id, startAt, endAt) {
376
- return await this.request("get", ["websites", website_id, "stats"], { startAt: Number(startAt), endAt: Number(endAt) });
383
+ return await this.request("get", ["websites", website_id, "stats"], { startAt, endAt });
377
384
  }
378
385
  // ADMIN
379
386
  getUsersAsAdmin = Admin.getUsers;
@@ -407,6 +414,44 @@ export class API {
407
414
  getWebsiteEventsDataProperties = Events.getWebsiteEventsDataProperties;
408
415
  getWebsiteEventsDataValues = Events.getWebsiteEventsDataValues;
409
416
  getWebsiteEventsDataStats = Events.getWebsiteEventsDataStats;
417
+ // SESSIONS
418
+ getWebsiteSessions = Sessions.getWebsiteSessions;
419
+ getWebsiteSessionsStats = Sessions.getWebsiteSessionsStats;
420
+ getWebsiteSessionsWeekly = Sessions.getWebsiteSessionsWeekly;
421
+ getWebsiteSession = Sessions.getWebsiteSession;
422
+ getWebsiteSessionActivity = Sessions.getWebsiteSessionActivity;
423
+ getWebsiteSessionProperties = Sessions.getWebsiteSessionProperties;
424
+ getWebsiteSessionDataProperties = Sessions.getWebsiteSessionDataProperties;
425
+ getWebsiteSessionDataValues = Sessions.getWebsiteSessionDataValues;
426
+ // WEBSITES
427
+ getWebsites = Websites.getWebsites;
428
+ createWebsite = Websites.createWebsite;
429
+ getWebsite = Websites.getWebsite;
430
+ updateWebsite = Websites.updateWebsite;
431
+ deleteWebsite = Websites.deleteWebsite;
432
+ resetWebsite = Websites.resetWebsite;
433
+ // WEBSITE STATS
434
+ getWebsiteActiveVisitors = WebsiteStats.getWebsiteActiveVisitors;
435
+ getWebsiteEventsStats = WebsiteStats.getWebsiteEvents;
436
+ getWebsiteMetrics = WebsiteStats.getWebsiteMetrics;
437
+ getWebsiteMetricsExpanded = WebsiteStats.getWebsiteMetricsExpanded;
438
+ getWebsitePageviews = WebsiteStats.getWebsitePageviews;
439
+ /** @remarks Will replace {@link API.getWebsiteStats}, which you should use for a reliable experience */
440
+ getWebsiteStats2 = WebsiteStats.getWebsiteStats;
410
441
  // REALTIME
411
442
  getRealtime = Realtime.getRealtime;
443
+ // REPORTS
444
+ getReports = Reports.getReports;
445
+ createReport = Reports.createReport;
446
+ getReport = Reports.getReport;
447
+ updateReport = Reports.updateReport;
448
+ deleteReport = Reports.deleteReport;
449
+ getReportsAttribution = Reports.getReportsAttribution;
450
+ getReportsBreakdown = Reports.getReportsBreakdown;
451
+ getReportsFunnel = Reports.getReportsFunnel;
452
+ getReportsGoals = Reports.getReportsGoals;
453
+ getReportsJourney = Reports.getReportsJourney;
454
+ getReportsRetention = Reports.getReportsRetention;
455
+ getReportsRevenue = Reports.getReportsRevenue;
456
+ getReportsUTM = Reports.getReportsUTM;
412
457
  }
@@ -1,4 +1,4 @@
1
- import { API, GenericObject, GenericRequestParameters, Role, Teams } from "../index.js";
1
+ import { API, GenericObject, GenericRequestParameters, MinimalUser, Role, Teams, Website } from "../index.js";
2
2
  /** For endpoints listed on: https://umami.is/docs/api/admin-api */
3
3
  export declare namespace Admin {
4
4
  /** Returns all users: https://umami.is/docs/api/admin-api#get-apiadminusers */
@@ -18,18 +18,8 @@ export declare namespace Admin {
18
18
  * Returns all websites: https://umami.is/docs/api/admin-api#get-apiadminwebsites
19
19
  * @remarks TODO Possibly doesn't work? (throws 400 on my end)
20
20
  */
21
- function getWebsites(this: API, parameters?: GenericRequestParameters): Promise<(GenericObject & {
22
- name: string;
23
- domain: string;
24
- shareId: number | null;
25
- resetAt: Date | null;
26
- userId: string;
27
- teamid: string | null;
28
- createdBy: string;
29
- user: {
30
- username: string;
31
- id: string;
32
- };
21
+ function getWebsites(this: API, parameters?: GenericRequestParameters): Promise<(Website & {
22
+ user: MinimalUser;
33
23
  /** @remarks TODO Documentation says it can be null but doesn't actually say what else it can be, ***presumed* to be string**, check */
34
24
  team: string | null;
35
25
  })[]>;
@@ -1,45 +1,8 @@
1
- import { API, GenericRequestParameters } from "../index.js";
1
+ import { API, Filters, GenericRequestParameters, Timestamps } from "../index.js";
2
2
  /** For endpoints listed on: https://umami.is/docs/api/events-api */
3
3
  export declare namespace Events {
4
- interface Timestamps {
5
- /** Timestamp of starting date */
6
- startAt: Date | number;
7
- /** Timestamp of end date */
8
- endAt: Date | number;
9
- }
10
- /** Many endpoints can make use of the filters in this interface: https://umami.is/docs/api/events-api#filters */
11
- interface FiltersAndTimestamps extends Timestamps {
12
- /** Name of URL */
13
- path?: string;
14
- /** Name of referrer */
15
- referrer?: string;
16
- /** Name of page title */
17
- title?: string;
18
- /** Name of query parameter */
19
- query?: string;
20
- /** Name of browser */
21
- browser?: string;
22
- /** Name of operating system */
23
- os?: string;
24
- /** Name of device (ex. Mobile) */
25
- device?: string;
26
- /** Name of country */
27
- country?: string;
28
- /** Name of region/state/province */
29
- region?: string;
30
- /** Name of city */
31
- city?: string;
32
- /** Name of hostname */
33
- hostname?: string;
34
- /** Name of tag */
35
- tag?: string;
36
- /** UUID of segment */
37
- segment?: string;
38
- /** UUID of cohort */
39
- cohort?: string;
40
- }
41
4
  /** Gets website event details within a given time range: https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevents (TODO UNTESTED) */
42
- function getWebsiteEvents(this: API, websiteId: string, parameters: FiltersAndTimestamps & GenericRequestParameters): Promise<{
5
+ function getWebsiteEvents(this: API, websiteId: string, parameters: Filters & Timestamps & GenericRequestParameters): Promise<{
43
6
  id: string;
44
7
  websiteId: string;
45
8
  sessionId: string;
@@ -75,7 +38,7 @@ export declare namespace Events {
75
38
  createdAt: Date;
76
39
  }[]>;
77
40
  /** Gets event data names, properties, and counts: https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevent-dataevents (TODO UNTESTED) */
78
- function getWebsiteEventsData(this: API, websiteId: string, parameters: FiltersAndTimestamps & {
41
+ function getWebsiteEventsData(this: API, websiteId: string, parameters: Filters & Timestamps & {
79
42
  /** Event name filter */
80
43
  event?: string;
81
44
  }): Promise<{
@@ -85,20 +48,20 @@ export declare namespace Events {
85
48
  total: number;
86
49
  }[]>;
87
50
  /** Gets event data property and value counts within a given time range: https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevent-datafields (TODO UNTESTED) */
88
- function getWebsiteEventsDataFields(this: API, websiteId: string, parameters: FiltersAndTimestamps): Promise<{
51
+ function getWebsiteEventsDataFields(this: API, websiteId: string, parameters: Filters & Timestamps): Promise<{
89
52
  propertyName: string;
90
53
  dataType: number;
91
54
  value: string;
92
55
  total: number;
93
56
  }[]>;
94
57
  /** Gets event name and property counts for a website: https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevent-dataproperties (TODO UNTESTED) */
95
- function getWebsiteEventsDataProperties(this: API, websiteId: string, parameters: FiltersAndTimestamps): Promise<{
58
+ function getWebsiteEventsDataProperties(this: API, websiteId: string, parameters: Filters & Timestamps): Promise<{
96
59
  eventName: string;
97
60
  propertyName: string;
98
61
  total: number;
99
62
  }[]>;
100
63
  /** Gets event data counts for a given event and property: https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevent-datavalues (TODO UNTESTED) */
101
- function getWebsiteEventsDataValues(this: API, websiteId: string, parameters: FiltersAndTimestamps & {
64
+ function getWebsiteEventsDataValues(this: API, websiteId: string, parameters: Filters & Timestamps & {
102
65
  /** Event name filter */
103
66
  event: string;
104
67
  /** Property name */
@@ -108,7 +71,7 @@ export declare namespace Events {
108
71
  total: number;
109
72
  }>;
110
73
  /** Gets aggregated website events, properties, and records within a given time range https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevent-datastats (TODO UNTESTED) */
111
- function getWebsiteEventsDataStats(this: API, websiteId: string, parameters: FiltersAndTimestamps): Promise<{
74
+ function getWebsiteEventsDataStats(this: API, websiteId: string, parameters: Filters & Timestamps): Promise<{
112
75
  events: number;
113
76
  properties: number;
114
77
  records: number;
@@ -3,10 +3,6 @@ export var Events;
3
3
  (function (Events) {
4
4
  /** Gets website event details within a given time range: https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevents (TODO UNTESTED) */
5
5
  async function getWebsiteEvents(websiteId, parameters) {
6
- if (parameters.startAt instanceof Date)
7
- parameters.startAt = Number(parameters.startAt);
8
- if (parameters.endAt instanceof Date)
9
- parameters.endAt = Number(parameters.endAt);
10
6
  const response = await this.request("get", ["websites", websiteId, "events"], parameters);
11
7
  return response.data;
12
8
  }
@@ -0,0 +1,146 @@
1
+ import { API, Filters, GenericRequestParameters, NameValue, Report, Timestamps, XTY } from "../index.js";
2
+ /** For endpoints listed on: https://umami.is/docs/api/reports-api */
3
+ export declare namespace Reports {
4
+ type ReportType = {
5
+ type: "attribution" | "breakdown" | "funnel" | "goal" | "journey" | "retention" | "revenue" | "utm";
6
+ };
7
+ interface UTM {
8
+ utm: string;
9
+ views: number;
10
+ }
11
+ /** Get all reports by website ID: https://umami.is/docs/api/reports-api#get-apireports (TODO UNTESTED) */
12
+ function getReports(this: API, websiteId: string, parameters: ReportType & Omit<GenericRequestParameters, "search">): Promise<Report[]>;
13
+ /** Creates a report: https://umami.is/docs/api/reports-api#post-apireports (TODO UNTESTED) */
14
+ function createReport(this: API, websiteId: string, parameters: ReportType & {
15
+ /** Name of report */
16
+ name: string;
17
+ /** Description of report */
18
+ description?: string;
19
+ /** Parameters for report */
20
+ parameters?: any;
21
+ }): Promise<Report>;
22
+ /** Gets a report by ID: https://umami.is/docs/api/reports-api#get-apireportsreportid (TODO UNTESTED) */
23
+ function getReport(this: API, reportId: string): Promise<Report>;
24
+ /** Updates a report: https://umami.is/docs/api/reports-api#post-apireportsreportid (TODO UNTESTED) */
25
+ function updateReport(this: API, reportId: string, websiteId: string, parameters: ReportType & {
26
+ /** Name of report */
27
+ name: string;
28
+ /** Description of report */
29
+ description?: string;
30
+ /** Parameters for report */
31
+ parameters?: any;
32
+ }): Promise<Report>;
33
+ /** Deletes a report: https://umami.is/docs/api/reports-api#delete-apireportsreportid (TODO UNTESTED) */
34
+ function deleteReport(this: API, reportId: string): Promise<{
35
+ ok: boolean;
36
+ }>;
37
+ /** See how users engage with your marketing and what drives conversions: https://umami.is/docs/api/reports-api#post-apireportsattribution (TODO UNTESTED) */
38
+ function getReportsAttribution(this: API, websiteId: string, parameters: ReportType & Filters & Timestamps & {
39
+ /** Attribution model */
40
+ model: "firstClick" | "lastClick";
41
+ /** Conversion type */
42
+ type: ("path" | "event")[];
43
+ /** Conversion step */
44
+ step: string;
45
+ }): Promise<{
46
+ referrer: NameValue[];
47
+ paidAds: NameValue[];
48
+ utm_source: NameValue[];
49
+ utm_medium: NameValue[];
50
+ utm_campaign: NameValue[];
51
+ utm_content: NameValue[];
52
+ utm_term: NameValue[];
53
+ total: {
54
+ pageviews: number;
55
+ visitors: number;
56
+ visits: number;
57
+ };
58
+ }>;
59
+ /** Dive deeper into your data by using segments and filters: https://umami.is/docs/api/reports-api#post-apireportsbreakdown (TODO UNTESTED) */
60
+ function getReportsBreakdown(this: API, websiteId: string, parameters: ReportType & Filters & Timestamps & {
61
+ fields: ("path" | "title" | "query" | "referrer" | "browser" | "os" | "device" | "country" | "region" | "city" | "hostname" | "tag" | "event")[];
62
+ }): Promise<{
63
+ views: number;
64
+ visitors: number;
65
+ visits: number;
66
+ bounces: number;
67
+ totaltime: number;
68
+ os: string;
69
+ country: string;
70
+ }[]>;
71
+ /** Understand the conversion and drop-off rate of users: https://umami.is/docs/api/reports-api#post-apireportsfunnel (TODO UNTESTED) */
72
+ function getReportsFunnel(this: API, websiteId: string, parameters: ReportType & Filters & Timestamps & {
73
+ /** Type of event and conversion step */
74
+ steps: {
75
+ type: "path" | "event";
76
+ value: string;
77
+ }[];
78
+ /** Window of days between funnel steps to be considered a conversion */
79
+ window: number;
80
+ }): Promise<{
81
+ type: string;
82
+ value: string;
83
+ visitors: number;
84
+ previous: number;
85
+ dropped: number;
86
+ dropoff: number | null;
87
+ remaining: number;
88
+ }[]>;
89
+ /** Track your goals for pageviews and events: https://umami.is/docs/api/reports-api#post-apireportsgoals (TODO UNTESTED) */
90
+ function getReportsGoals(this: API, websiteId: string, parameters: ReportType & Filters & Timestamps & {
91
+ /** Conversion type */
92
+ type: ("path" | "event")[];
93
+ /** Conversion step value */
94
+ value: string;
95
+ }): Promise<{
96
+ num: number;
97
+ total: number;
98
+ }>;
99
+ /** Understand how users nagivate through your website: https://umami.is/docs/api/reports-api#post-apireportsjourney (TODO UNTESTED) */
100
+ function getReportsJourney(this: API, websiteId: string, parameters: ReportType & Filters & Timestamps & {
101
+ /** Number of steps from 3 to 7 */
102
+ steps: number;
103
+ /** Starting step URL or event name */
104
+ startStep: string;
105
+ /** Ending step URL or event name */
106
+ endStep?: string;
107
+ }): Promise<{
108
+ items: (string | null)[];
109
+ count: number;
110
+ }[]>;
111
+ /** Measure your website stickiness by tracking how often users return: https://umami.is/docs/api/reports-api#post-apireportsretention (TODO UNTESTED) */
112
+ function getReportsRetention(this: API, websiteId: string, parameters: ReportType & Filters & Timestamps & {
113
+ /** Timezone (ex. America/Los_Angeles) */
114
+ timezone: string;
115
+ }): Promise<{
116
+ date: Date;
117
+ day: number;
118
+ visitors: number;
119
+ returnVisitors: number;
120
+ percentage: number;
121
+ }[]>;
122
+ /** Get currency for given range. Needed for Revenue and optional in Attribution reports: https://umami.is/docs/api/reports-api#post-apireportsrevenue (TODO UNTESTED) */
123
+ function getReportsRevenue(this: API, websiteId: string, parameters: ReportType & Filters & Timestamps & {
124
+ /** Timezone (ex. America/Los_Angeles) */
125
+ timezone: string;
126
+ /** Currency code (ISO 4217) */
127
+ currency: string;
128
+ }): Promise<{
129
+ chart: XTY[];
130
+ country: NameValue[];
131
+ total: {
132
+ sum: number;
133
+ count: number;
134
+ unique_count: number;
135
+ average: number;
136
+ };
137
+ }>;
138
+ /** Track your campaigns through UTM parameters: https://umami.is/docs/api/reports-api#post-apireportsutm (TODO UNTESTED) */
139
+ function getReportsUTM(this: API, websiteId: string, parameters: ReportType & Filters & Timestamps): Promise<{
140
+ utm_source: UTM[];
141
+ utm_medium: UTM[];
142
+ utm_campaign: UTM[];
143
+ utm_term: UTM[];
144
+ utm_content: UTM[];
145
+ }>;
146
+ }
@@ -0,0 +1,70 @@
1
+ /** For endpoints listed on: https://umami.is/docs/api/reports-api */
2
+ export var Reports;
3
+ (function (Reports) {
4
+ /** Get all reports by website ID: https://umami.is/docs/api/reports-api#get-apireports (TODO UNTESTED) */
5
+ async function getReports(websiteId, parameters) {
6
+ const response = await this.request("get", ["reports"], { websiteId, ...parameters });
7
+ return response.data;
8
+ }
9
+ Reports.getReports = getReports;
10
+ /** Creates a report: https://umami.is/docs/api/reports-api#post-apireports (TODO UNTESTED) */
11
+ async function createReport(websiteId, parameters) {
12
+ return await this.request("post", ["reports"], { websiteId, ...parameters });
13
+ }
14
+ Reports.createReport = createReport;
15
+ /** Gets a report by ID: https://umami.is/docs/api/reports-api#get-apireportsreportid (TODO UNTESTED) */
16
+ async function getReport(reportId) {
17
+ return await this.request("get", ["reports", reportId]);
18
+ }
19
+ Reports.getReport = getReport;
20
+ /** Updates a report: https://umami.is/docs/api/reports-api#post-apireportsreportid (TODO UNTESTED) */
21
+ async function updateReport(reportId, websiteId, parameters) {
22
+ return await this.request("get", ["reports", reportId], { websiteId, ...parameters });
23
+ }
24
+ Reports.updateReport = updateReport;
25
+ /** Deletes a report: https://umami.is/docs/api/reports-api#delete-apireportsreportid (TODO UNTESTED) */
26
+ async function deleteReport(reportId) {
27
+ return await this.request("delete", ["reports", reportId]);
28
+ }
29
+ Reports.deleteReport = deleteReport;
30
+ /** See how users engage with your marketing and what drives conversions: https://umami.is/docs/api/reports-api#post-apireportsattribution (TODO UNTESTED) */
31
+ async function getReportsAttribution(websiteId, parameters) {
32
+ return await this.request("post", ["reports", "attribution"], { websiteId, ...parameters });
33
+ }
34
+ Reports.getReportsAttribution = getReportsAttribution;
35
+ /** Dive deeper into your data by using segments and filters: https://umami.is/docs/api/reports-api#post-apireportsbreakdown (TODO UNTESTED) */
36
+ async function getReportsBreakdown(websiteId, parameters) {
37
+ return await this.request("post", ["reports", "breakdown"], { websiteId, ...parameters });
38
+ }
39
+ Reports.getReportsBreakdown = getReportsBreakdown;
40
+ /** Understand the conversion and drop-off rate of users: https://umami.is/docs/api/reports-api#post-apireportsfunnel (TODO UNTESTED) */
41
+ async function getReportsFunnel(websiteId, parameters) {
42
+ return await this.request("post", ["reports", "funnel"], { websiteId, ...parameters });
43
+ }
44
+ Reports.getReportsFunnel = getReportsFunnel;
45
+ /** Track your goals for pageviews and events: https://umami.is/docs/api/reports-api#post-apireportsgoals (TODO UNTESTED) */
46
+ async function getReportsGoals(websiteId, parameters) {
47
+ return await this.request("post", ["reports", "goals"], { websiteId, ...parameters });
48
+ }
49
+ Reports.getReportsGoals = getReportsGoals;
50
+ /** Understand how users nagivate through your website: https://umami.is/docs/api/reports-api#post-apireportsjourney (TODO UNTESTED) */
51
+ async function getReportsJourney(websiteId, parameters) {
52
+ return await this.request("post", ["reports", "journey"], { websiteId, ...parameters });
53
+ }
54
+ Reports.getReportsJourney = getReportsJourney;
55
+ /** Measure your website stickiness by tracking how often users return: https://umami.is/docs/api/reports-api#post-apireportsretention (TODO UNTESTED) */
56
+ async function getReportsRetention(websiteId, parameters) {
57
+ return await this.request("post", ["reports", "retention"], { websiteId, ...parameters });
58
+ }
59
+ Reports.getReportsRetention = getReportsRetention;
60
+ /** Get currency for given range. Needed for Revenue and optional in Attribution reports: https://umami.is/docs/api/reports-api#post-apireportsrevenue (TODO UNTESTED) */
61
+ async function getReportsRevenue(websiteId, parameters) {
62
+ return await this.request("post", ["reports", "revenue"], { websiteId, ...parameters });
63
+ }
64
+ Reports.getReportsRevenue = getReportsRevenue;
65
+ /** Track your campaigns through UTM parameters: https://umami.is/docs/api/reports-api#post-apireportsutm (TODO UNTESTED) */
66
+ async function getReportsUTM(websiteId, parameters) {
67
+ return await this.request("post", ["reports", "utm"], { websiteId, ...parameters });
68
+ }
69
+ Reports.getReportsUTM = getReportsUTM;
70
+ })(Reports || (Reports = {}));
@@ -0,0 +1,93 @@
1
+ import { API, Filters, GenericRequestParameters, Timestamps } from "../index.js";
2
+ /** For endpoints listed on: https://umami.is/docs/api/sessions-api */
3
+ export declare namespace Sessions {
4
+ interface GenericSession {
5
+ id: string;
6
+ websiteId: string;
7
+ browser: string;
8
+ os: string;
9
+ device: string;
10
+ screen: string;
11
+ language: string;
12
+ country: string;
13
+ region: string;
14
+ city: string;
15
+ firstAt: Date;
16
+ lastAt: Date;
17
+ visits: number;
18
+ views: number;
19
+ }
20
+ /** Gets website session details within a given time range: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsessions (TODO UNTESTED) */
21
+ function getWebsiteSessions(this: API, websiteId: string, parameters: Filters & Timestamps & GenericRequestParameters): Promise<(GenericSession & {
22
+ hostname: string;
23
+ createdAt: Date;
24
+ })[]>;
25
+ /** Gets summarized website session statistics: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsessionsstats (TODO UNTESTED) */
26
+ function getWebsiteSessionsStats(this: API, websiteId: string, parameters: Filters & Timestamps): Promise<{
27
+ /** Pages hits */
28
+ pageviews: {
29
+ value: number;
30
+ };
31
+ /** Number of unique visitors */
32
+ visitors: {
33
+ value: number;
34
+ };
35
+ /** Number of unique visits */
36
+ visits: {
37
+ value: number;
38
+ };
39
+ /** Number of visitors who only visit a single page */
40
+ bounces: {
41
+ value: number;
42
+ };
43
+ /** Time spent on the website */
44
+ totaltime: {
45
+ value: number;
46
+ };
47
+ }>;
48
+ /** Get collected count of sessions by hour of weekday: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsessionsweekly (TODO UNTESTED) */
49
+ function getWebsiteSessionsWeekly(this: API, websiteId: string, parameters: Filters & Timestamps & {
50
+ timezone: string;
51
+ }): Promise<number[][]>;
52
+ /** Gets session details for a individual session: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsessionssessionid (TODO UNTESTED) */
53
+ function getWebsiteSession(this: API, websiteId: string, sessionId: string): Promise<GenericSession & {
54
+ distinctId: string;
55
+ events: number;
56
+ totaltime: number;
57
+ }>;
58
+ /** Gets session activity for a individual session: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsessionssessionidactivity (TODO UNTESTED) */
59
+ function getWebsiteSessionActivity(this: API, websiteId: string, sessionId: string, parameters: Timestamps): Promise<{
60
+ createdAt: Date;
61
+ urlPath: string;
62
+ urlQuery: string;
63
+ referrerDomain: string;
64
+ eventId: string;
65
+ eventType: number;
66
+ eventName: string;
67
+ visitId: string;
68
+ hasData: number;
69
+ }[]>;
70
+ /** Gets session properties for a individual session: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsessionssessionidproperties (TODO UNTESTED) */
71
+ function getWebsiteSessionProperties(this: API, websiteId: string, sessionId: string): Promise<{
72
+ websiteId: string;
73
+ sessionid: string;
74
+ dataKey: string;
75
+ dataType: number;
76
+ stringValue: string;
77
+ numberValue: number | null;
78
+ dateValue: Date | null;
79
+ createdAt: Date;
80
+ }[]>;
81
+ /** Gets session data counts by property name: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsession-dataproperties (TODO UNTESTED) */
82
+ function getWebsiteSessionDataProperties(this: API, websiteId: string, parameters: Filters & Timestamps): Promise<{
83
+ propertyName: string;
84
+ total: number;
85
+ }[]>;
86
+ /** Gets session data counts for a given property: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsession-datavalues (TODO UNTESTED) */
87
+ function getWebsiteSessionDataValues(this: API, websiteId: string, parameters: Filters & Timestamps & {
88
+ propertyName: string;
89
+ }): Promise<{
90
+ value: string;
91
+ total: number;
92
+ }[]>;
93
+ }
@@ -0,0 +1,45 @@
1
+ /** For endpoints listed on: https://umami.is/docs/api/sessions-api */
2
+ export var Sessions;
3
+ (function (Sessions) {
4
+ /** Gets website session details within a given time range: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsessions (TODO UNTESTED) */
5
+ async function getWebsiteSessions(websiteId, parameters) {
6
+ const response = await this.request("get", ["websites", websiteId, "sessions"], parameters);
7
+ return response.data;
8
+ }
9
+ Sessions.getWebsiteSessions = getWebsiteSessions;
10
+ /** Gets summarized website session statistics: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsessionsstats (TODO UNTESTED) */
11
+ async function getWebsiteSessionsStats(websiteId, parameters) {
12
+ return await this.request("get", ["websites", websiteId, "sessions"], parameters);
13
+ }
14
+ Sessions.getWebsiteSessionsStats = getWebsiteSessionsStats;
15
+ /** Get collected count of sessions by hour of weekday: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsessionsweekly (TODO UNTESTED) */
16
+ async function getWebsiteSessionsWeekly(websiteId, parameters) {
17
+ return await this.request("get", ["websites", websiteId, "sessions", "weekly"], parameters);
18
+ }
19
+ Sessions.getWebsiteSessionsWeekly = getWebsiteSessionsWeekly;
20
+ /** Gets session details for a individual session: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsessionssessionid (TODO UNTESTED) */
21
+ async function getWebsiteSession(websiteId, sessionId) {
22
+ return await this.request("get", ["websites", websiteId, "sessions", sessionId]);
23
+ }
24
+ Sessions.getWebsiteSession = getWebsiteSession;
25
+ /** Gets session activity for a individual session: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsessionssessionidactivity (TODO UNTESTED) */
26
+ async function getWebsiteSessionActivity(websiteId, sessionId, parameters) {
27
+ return await this.request("get", ["websites", websiteId, "sessions", sessionId, "activity"], parameters);
28
+ }
29
+ Sessions.getWebsiteSessionActivity = getWebsiteSessionActivity;
30
+ /** Gets session properties for a individual session: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsessionssessionidproperties (TODO UNTESTED) */
31
+ async function getWebsiteSessionProperties(websiteId, sessionId) {
32
+ return await this.request("get", ["websites", websiteId, "sessions", sessionId, "activity", "properties"]);
33
+ }
34
+ Sessions.getWebsiteSessionProperties = getWebsiteSessionProperties;
35
+ /** Gets session data counts by property name: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsession-dataproperties (TODO UNTESTED) */
36
+ async function getWebsiteSessionDataProperties(websiteId, parameters) {
37
+ return await this.request("get", ["websites", websiteId, "session-data", "properties"], parameters);
38
+ }
39
+ Sessions.getWebsiteSessionDataProperties = getWebsiteSessionDataProperties;
40
+ /** Gets session data counts for a given property: https://umami.is/docs/api/sessions-api#get-apiwebsiteswebsiteidsession-datavalues (TODO UNTESTED) */
41
+ async function getWebsiteSessionDataValues(websiteId, parameters) {
42
+ return await this.request("get", ["websites", websiteId, "session-data", "values"], parameters);
43
+ }
44
+ Sessions.getWebsiteSessionDataValues = getWebsiteSessionDataValues;
45
+ })(Sessions || (Sessions = {}));
@@ -1,9 +1,7 @@
1
- import { API, GenericObject, GenericRequestParameters, Role, TeamRole } from "../index.js";
1
+ import { API, GenericObject, GenericRequestParameters, MinimalUser, Role, TeamRole, Website } from "../index.js";
2
2
  /** For endpoints listed on: https://umami.is/docs/api/users-api */
3
3
  export declare namespace Users {
4
- interface GenericUser {
5
- id: string;
6
- username: string;
4
+ interface GenericUser extends MinimalUser {
7
5
  role: Role;
8
6
  }
9
7
  /** Creates a user: https://umami.is/docs/api/users-api#post-apiusers */
@@ -39,18 +37,8 @@ export declare namespace Users {
39
37
  /** Gets all websites that belong to a user: https://umami.is/docs/api/users-api#get-apiusersuseridwebsites */
40
38
  function getUserWebsites(this: API, id: string, parameters: GenericRequestParameters & {
41
39
  includeTeams: boolean;
42
- }): Promise<(GenericObject & {
43
- name: string;
44
- domain: string;
45
- shareId: string | null;
46
- resetAt: Date | null;
47
- userId: string;
48
- teamId: string | null;
49
- createdBy: string;
50
- user: {
51
- username: string;
52
- id: string;
53
- };
40
+ }): Promise<(Website & {
41
+ user: MinimalUser;
54
42
  })[]>;
55
43
  /** Gets all teams that belong to a user: https://umami.is/docs/api/users-api#get-apiusersuseridteams */
56
44
  function getUserTeams(this: API, id: string, parameters?: Omit<GenericRequestParameters, "search">): Promise<(GenericObject & {
@@ -0,0 +1,90 @@
1
+ import { API, Filters, Timestamps, XTY } from "../index.js";
2
+ /** For endpoints listed on: https://umami.is/docs/api/website-stats-api */
3
+ export declare namespace WebsiteStats {
4
+ /**
5
+ * The unit parameter buckets the data returned
6
+ * @remarks The unit is automatically converted to the next largest applicable time unit if the maximum is exceeded
7
+ */
8
+ interface Units {
9
+ /** Up to 60 minutes */
10
+ minute?: number;
11
+ /** Up to 48 hours */
12
+ hour?: number;
13
+ /** Up to 12 months */
14
+ day?: number;
15
+ /** No limit */
16
+ month?: number;
17
+ /** No limit */
18
+ year?: number;
19
+ }
20
+ interface Stats {
21
+ /** Pages hits */
22
+ pageviews: string;
23
+ /** Number of unique visitors */
24
+ visitors: string;
25
+ /** Number of unique visits */
26
+ visits: string;
27
+ /** Number of visitors who only visit a single page */
28
+ bounces: string;
29
+ /** Time spent on the website */
30
+ totaltime: string;
31
+ }
32
+ type MetricsTypes = "path" | "entry" | "exit" | "title" | "query" | "referrer" | "channel" | "domain" | "country" | "region" | "city" | "browser" | "os" | "device" | "language" | "screen" | "event" | "hostname" | "tag";
33
+ /** Gets the number of active users on a website: https://umami.is/docs/api/website-stats-api#get-apiwebsiteswebsiteidactive (TODO UNTESTED) */
34
+ function getWebsiteActiveVisitors(this: API, websiteId: string): Promise<{
35
+ visitors: number;
36
+ }>;
37
+ /** Gets events within a given time range: https://umami.is/docs/api/website-stats-api#get-apiwebsiteswebsiteideventsseries (TODO UNTESTED) */
38
+ function getWebsiteEvents(this: API, websiteId: string, parameters: Timestamps & Units & Filters & {
39
+ /** Timezone (ex. America/Los_Angeles) */
40
+ timezone: string;
41
+ }): Promise<XTY[]>;
42
+ /** Gets metrics for a given time range: https://umami.is/docs/api/website-stats-api#get-apiwebsiteswebsiteidmetrics (TODO UNTESTED) */
43
+ function getWebsiteMetrics(this: API, websiteId: string, parameters: Timestamps & Units & Filters & {
44
+ /** Timezone (ex. America/Los_Angeles) */
45
+ timezone: string;
46
+ /** Metrics type */
47
+ type: MetricsTypes;
48
+ /** (optional, default 500) Number of rows returned */
49
+ limit?: number;
50
+ /** (optional, default 0) Number of ows to skip */
51
+ offset?: number;
52
+ }): Promise<{
53
+ /** Unique value, depending on metric type */
54
+ x: string;
55
+ /** Number of visitors */
56
+ y: number;
57
+ }[]>;
58
+ /** Gets expanded metrics for a given time range: https://umami.is/docs/api/website-stats-api#get-apiwebsiteswebsiteidmetricsexpanded (TODO UNTESTED) */
59
+ function getWebsiteMetricsExpanded(this: API, ...args: Parameters<typeof getWebsiteMetrics>): Promise<(Stats & {
60
+ /** Unique value, depending on metric type */
61
+ name: string;
62
+ })[]>;
63
+ /** Gets pageviews within a given time range: https://umami.is/docs/api/website-stats-api#get-apiwebsiteswebsiteidpageviews (TODO UNTESTED) */
64
+ function getWebsitePageviews(this: API, websiteId: string, parameters: Timestamps & Units & Filters & {
65
+ /** Timezone (ex. America/Los_Angeles) */
66
+ timezone: string;
67
+ /** Comparison value `prev` | `yoy` */
68
+ compare?: string;
69
+ }): Promise<{
70
+ pageviews: {
71
+ /** Timestamp */
72
+ x: Date;
73
+ /** Number of pageviews or visitors */
74
+ y: number;
75
+ }[];
76
+ sessions: {
77
+ /** Timestamp */
78
+ x: Date;
79
+ /** Number of pageviews or visitors */
80
+ y: number;
81
+ }[];
82
+ }>;
83
+ /** Gets summarized website statistics: https://umami.is/docs/api/website-stats-api#get-apiwebsiteswebsiteidstats (TODO UNTESTED) */
84
+ function getWebsiteStats(this: API, websiteId: string, parameters: Timestamps & Filters & Units & {
85
+ /** Timezone (ex. America/Los_Angeles) */
86
+ timezone: string;
87
+ }): Promise<Stats & {
88
+ comparison: Stats;
89
+ }>;
90
+ }
@@ -0,0 +1,34 @@
1
+ /** For endpoints listed on: https://umami.is/docs/api/website-stats-api */
2
+ export var WebsiteStats;
3
+ (function (WebsiteStats) {
4
+ /** Gets the number of active users on a website: https://umami.is/docs/api/website-stats-api#get-apiwebsiteswebsiteidactive (TODO UNTESTED) */
5
+ async function getWebsiteActiveVisitors(websiteId) {
6
+ return await this.request("get", ["websites", websiteId, "active"]);
7
+ }
8
+ WebsiteStats.getWebsiteActiveVisitors = getWebsiteActiveVisitors;
9
+ /** Gets events within a given time range: https://umami.is/docs/api/website-stats-api#get-apiwebsiteswebsiteideventsseries (TODO UNTESTED) */
10
+ async function getWebsiteEvents(websiteId, parameters) {
11
+ return await this.request("get", ["websites", websiteId, "events", "series"], parameters);
12
+ }
13
+ WebsiteStats.getWebsiteEvents = getWebsiteEvents;
14
+ /** Gets metrics for a given time range: https://umami.is/docs/api/website-stats-api#get-apiwebsiteswebsiteidmetrics (TODO UNTESTED) */
15
+ async function getWebsiteMetrics(websiteId, parameters) {
16
+ return await this.request("get", ["websites", websiteId, "metrics"], parameters);
17
+ }
18
+ WebsiteStats.getWebsiteMetrics = getWebsiteMetrics;
19
+ /** Gets expanded metrics for a given time range: https://umami.is/docs/api/website-stats-api#get-apiwebsiteswebsiteidmetricsexpanded (TODO UNTESTED) */
20
+ async function getWebsiteMetricsExpanded(...args) {
21
+ return await this.request("get", ["websites", args[0], "metrics", "expanded"], args[1]);
22
+ }
23
+ WebsiteStats.getWebsiteMetricsExpanded = getWebsiteMetricsExpanded;
24
+ /** Gets pageviews within a given time range: https://umami.is/docs/api/website-stats-api#get-apiwebsiteswebsiteidpageviews (TODO UNTESTED) */
25
+ async function getWebsitePageviews(websiteId, parameters) {
26
+ return await this.request("get", ["websites", websiteId, "pageviews"], parameters);
27
+ }
28
+ WebsiteStats.getWebsitePageviews = getWebsitePageviews;
29
+ /** Gets summarized website statistics: https://umami.is/docs/api/website-stats-api#get-apiwebsiteswebsiteidstats (TODO UNTESTED) */
30
+ async function getWebsiteStats(websiteId, parameters) {
31
+ return await this.request("get", ["websites", websiteId, "stats"], parameters);
32
+ }
33
+ WebsiteStats.getWebsiteStats = getWebsiteStats;
34
+ })(WebsiteStats || (WebsiteStats = {}));
@@ -0,0 +1,42 @@
1
+ import { API, GenericRequestParameters, MinimalUser, Website } from "../index.js";
2
+ /** For endpoints listed on: https://umami.is/docs/api/websites-api */
3
+ export declare namespace Websites {
4
+ /** Returns all user websites: https://umami.is/docs/api/websites-api#get-apiwebsites (TODO UNTESTED) */
5
+ function getWebsites(this: API, parameters: GenericRequestParameters & {
6
+ includeTeams: boolean;
7
+ }): Promise<(Website & {
8
+ user: MinimalUser;
9
+ })[]>;
10
+ /** Creates a website: https://umami.is/docs/api/websites-api#post-apiwebsites (TODO UNTESTED) */
11
+ function createWebsite(this: API, parameters: {
12
+ /** The name of the website in Umami */
13
+ name: string;
14
+ /** The full domain of the tracked website */
15
+ domain: string;
16
+ /** A unique string to enable a share url. Set `null` to unshare */
17
+ shareId?: string | null;
18
+ /** The ID of the team the website will be created under */
19
+ teamId?: string;
20
+ /** Force a UUID assignment to the website */
21
+ id?: string;
22
+ }): Promise<Website>;
23
+ /** Gets a website by ID: https://umami.is/docs/api/websites-api#get-apiwebsiteswebsiteid (TODO UNTESTED) */
24
+ function getWebsite(this: API, websiteId: string): Promise<Website>;
25
+ /** Updates a website: https://umami.is/docs/api/websites-api#post-apiwebsiteswebsiteid (TODO UNTESTED) */
26
+ function updateWebsite(this: API, websiteId: string, parameters: {
27
+ /** The name of the website in Umami */
28
+ name: string;
29
+ /** The full domain of the tracked website */
30
+ domain: string;
31
+ /** A unique string to enable a share url. Set `null` to unshare */
32
+ shareId?: string | null;
33
+ }): Promise<Website>;
34
+ /** Deletes a website: https://umami.is/docs/api/websites-api#delete-apiwebsiteswebsiteid (TODO UNTESTED) */
35
+ function deleteWebsite(this: API, websiteId: string): Promise<{
36
+ ok: boolean;
37
+ }>;
38
+ /** Resets a website by removing all data related to the website: https://umami.is/docs/api/websites-api#post-apiwebsiteswebsiteidreset (TODO UNTESTED) */
39
+ function resetWebsite(this: API, websiteId: string): Promise<{
40
+ ok: boolean;
41
+ }>;
42
+ }
@@ -0,0 +1,35 @@
1
+ /** For endpoints listed on: https://umami.is/docs/api/websites-api */
2
+ export var Websites;
3
+ (function (Websites) {
4
+ /** Returns all user websites: https://umami.is/docs/api/websites-api#get-apiwebsites (TODO UNTESTED) */
5
+ async function getWebsites(parameters) {
6
+ const response = await this.request("get", ["websites"], parameters);
7
+ return response.data;
8
+ }
9
+ Websites.getWebsites = getWebsites;
10
+ /** Creates a website: https://umami.is/docs/api/websites-api#post-apiwebsites (TODO UNTESTED) */
11
+ async function createWebsite(parameters) {
12
+ return await this.request("post", ["websites"], parameters);
13
+ }
14
+ Websites.createWebsite = createWebsite;
15
+ /** Gets a website by ID: https://umami.is/docs/api/websites-api#get-apiwebsiteswebsiteid (TODO UNTESTED) */
16
+ async function getWebsite(websiteId) {
17
+ return await this.request("get", ["websites", websiteId]);
18
+ }
19
+ Websites.getWebsite = getWebsite;
20
+ /** Updates a website: https://umami.is/docs/api/websites-api#post-apiwebsiteswebsiteid (TODO UNTESTED) */
21
+ async function updateWebsite(websiteId, parameters) {
22
+ return await this.request("post", ["websites", websiteId], parameters);
23
+ }
24
+ Websites.updateWebsite = updateWebsite;
25
+ /** Deletes a website: https://umami.is/docs/api/websites-api#delete-apiwebsiteswebsiteid (TODO UNTESTED) */
26
+ async function deleteWebsite(websiteId) {
27
+ return await this.request("delete", ["websites", websiteId]);
28
+ }
29
+ Websites.deleteWebsite = deleteWebsite;
30
+ /** Resets a website by removing all data related to the website: https://umami.is/docs/api/websites-api#post-apiwebsiteswebsiteidreset (TODO UNTESTED) */
31
+ async function resetWebsite(websiteId) {
32
+ return await this.request("post", ["websites", websiteId, "reset"]);
33
+ }
34
+ Websites.resetWebsite = resetWebsite;
35
+ })(Websites || (Websites = {}));
package/dist/utilities.js CHANGED
@@ -58,7 +58,7 @@ export function correctType(x, force_string) {
58
58
  const unconvertables = ["value"];
59
59
  const unconvertables_substrings = ["string", "name"]; // or if the key contains any of those substrings
60
60
  for (let i = 0; i < keys.length; i++) {
61
- x[keys[i]] = correctType(vals[i], unconvertables.some((u) => keys[i] === u) ?? unconvertables_substrings.some((s) => keys[i].toLowerCase().includes(s)));
61
+ x[keys[i]] = correctType(vals[i], unconvertables.some((u) => keys[i] === u) || unconvertables_substrings.some((s) => keys[i].toLowerCase().includes(s)));
62
62
  }
63
63
  return x;
64
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "umami-api-js",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Package to easily access the umami api!",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -8,7 +8,8 @@
8
8
  "scripts": {
9
9
  "prepublish": "npm run build",
10
10
  "build": "tsc",
11
- "test": "npm run build && node ./dist/test.js"
11
+ "test": "npm run build && node ./dist/test.js",
12
+ "docs": "npx typedoc lib/index.ts"
12
13
  },
13
14
  "engines": {
14
15
  "node": ">=20.0.0"
@@ -27,9 +28,9 @@
27
28
  ],
28
29
  "license": "Unlicense",
29
30
  "devDependencies": {
30
- "@types/chai": "^5.2.2",
31
31
  "@types/node": "^24.3.1",
32
32
  "dotenv": "^17.2.2",
33
+ "typedoc": "^0.28.14",
33
34
  "typescript": "^5.9.2"
34
35
  }
35
36
  }