umami-api-js 0.0.1 → 0.0.2
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 +3 -3
- package/dist/index.d.ts +52 -1
- package/dist/index.js +42 -2
- package/dist/namespaces/Admin.d.ts +50 -0
- package/dist/namespaces/Admin.js +28 -0
- package/dist/namespaces/Events.d.ts +116 -0
- package/dist/namespaces/Events.js +44 -0
- package/dist/namespaces/Realtime.d.ts +45 -0
- package/dist/namespaces/Realtime.js +9 -0
- package/dist/namespaces/Teams.d.ts +76 -0
- package/dist/namespaces/Teams.js +67 -0
- package/dist/namespaces/Users.d.ts +74 -0
- package/dist/namespaces/Users.js +36 -0
- package/dist/utilities.js +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
|
|
3
|
+
Please note that this package is not expected to work with Umami 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
|
|
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,9 +1,31 @@
|
|
|
1
|
+
import { Admin } from "./namespaces/Admin.js";
|
|
2
|
+
import { Events } from "./namespaces/Events.js";
|
|
3
|
+
import { Realtime } from "./namespaces/Realtime.js";
|
|
4
|
+
import { Teams } from "./namespaces/Teams.js";
|
|
5
|
+
import { Users } from "./namespaces/Users.js";
|
|
6
|
+
export { Admin, Users, Teams, Events, Realtime };
|
|
1
7
|
export interface ValueAndPrev {
|
|
2
8
|
/** The actual value for the given time period */
|
|
3
9
|
value: number;
|
|
4
10
|
/** The value for the same *timespan* for the time period that ends where the time period for value starts */
|
|
5
11
|
prev: number;
|
|
6
12
|
}
|
|
13
|
+
export interface GenericObject {
|
|
14
|
+
id: string;
|
|
15
|
+
createdAt: Date;
|
|
16
|
+
updatedAt: Date | null;
|
|
17
|
+
deletedAt: Date | null;
|
|
18
|
+
}
|
|
19
|
+
export interface GenericRequestParameters {
|
|
20
|
+
/** Search text */
|
|
21
|
+
search?: string;
|
|
22
|
+
/** Determines page **(default: 1)** */
|
|
23
|
+
page?: number;
|
|
24
|
+
/** Determines how many results to return **(default: 20)** */
|
|
25
|
+
pageSize?: number;
|
|
26
|
+
}
|
|
27
|
+
export type Role = "admin" | "user" | "view-only";
|
|
28
|
+
export type TeamRole = "team-manager" | "team-member" | "team-view-only";
|
|
7
29
|
/** If the {@link API} throws an error, it should always be an {@link APIError}! */
|
|
8
30
|
export declare class APIError extends Error {
|
|
9
31
|
message: string;
|
|
@@ -160,7 +182,7 @@ export declare class API {
|
|
|
160
182
|
*/
|
|
161
183
|
private fetch;
|
|
162
184
|
/**
|
|
163
|
-
* The function that directly communicates with the API! Almost
|
|
185
|
+
* The function that directly communicates with the API! Almost all functions of the API object uses this function!
|
|
164
186
|
* @param method The type of request, each endpoint uses a specific one (if it uses multiple, the intent and parameters become different)
|
|
165
187
|
* @param endpoint What comes in the URL after `api/`, **DO NOT USE TEMPLATE LITERALS (\`) OR THE ADDITION OPERATOR (+), put everything separately for type safety**
|
|
166
188
|
* @param parameters The things to specify in the request, such as the beatmap_id when looking for a beatmap
|
|
@@ -177,4 +199,33 @@ export declare class API {
|
|
|
177
199
|
bounces: ValueAndPrev;
|
|
178
200
|
totaltime: ValueAndPrev;
|
|
179
201
|
}>;
|
|
202
|
+
readonly getUsersAsAdmin: typeof Admin.getUsers;
|
|
203
|
+
readonly getWebsitesAsAdmin: typeof Admin.getWebsites;
|
|
204
|
+
readonly getTeamsAsAdmin: typeof Admin.getTeams;
|
|
205
|
+
readonly createUser: typeof Users.createUser;
|
|
206
|
+
readonly getUser: typeof Users.getUser;
|
|
207
|
+
readonly updateUser: typeof Users.updateUser;
|
|
208
|
+
readonly deleteUser: typeof Users.deleteUser;
|
|
209
|
+
readonly getUserTeams: typeof Users.getUserTeams;
|
|
210
|
+
readonly getUserWebsites: typeof Users.getUserWebsites;
|
|
211
|
+
readonly getTeams: typeof Teams.getTeams;
|
|
212
|
+
readonly createTeam: typeof Teams.createTeam;
|
|
213
|
+
readonly joinTeam: typeof Teams.joinTeam;
|
|
214
|
+
readonly getTeam: typeof Teams.getTeam;
|
|
215
|
+
readonly updateTeam: typeof Teams.updateTeam;
|
|
216
|
+
readonly deleteTeam: typeof Teams.deleteTeam;
|
|
217
|
+
readonly getTeamUsers: typeof Teams.getTeamUsers;
|
|
218
|
+
readonly addTeamUser: typeof Teams.addTeamUser;
|
|
219
|
+
readonly getTeamUser: typeof Teams.getTeamUser;
|
|
220
|
+
readonly updateTeamUser: typeof Teams.updateTeamUser;
|
|
221
|
+
readonly removeTeamUser: typeof Teams.removeTeamUser;
|
|
222
|
+
readonly getTeamWebsites: typeof Teams.getTeamWebsites;
|
|
223
|
+
readonly getWebsiteEvents: typeof Events.getWebsiteEvents;
|
|
224
|
+
readonly getWebsiteEventData: typeof Events.getWebsiteEventData;
|
|
225
|
+
readonly getWebsiteEventsData: typeof Events.getWebsiteEventsData;
|
|
226
|
+
readonly getWebsiteEventsDataFields: typeof Events.getWebsiteEventsDataFields;
|
|
227
|
+
readonly getWebsiteEventsDataProperties: typeof Events.getWebsiteEventsDataProperties;
|
|
228
|
+
readonly getWebsiteEventsDataValues: typeof Events.getWebsiteEventsDataValues;
|
|
229
|
+
readonly getWebsiteEventsDataStats: typeof Events.getWebsiteEventsDataStats;
|
|
230
|
+
readonly getRealtime: typeof Realtime.getRealtime;
|
|
180
231
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import { Admin } from "./namespaces/Admin.js";
|
|
2
|
+
import { Events } from "./namespaces/Events.js";
|
|
3
|
+
import { Realtime } from "./namespaces/Realtime.js";
|
|
4
|
+
import { Teams } from "./namespaces/Teams.js";
|
|
5
|
+
import { Users } from "./namespaces/Users.js";
|
|
1
6
|
import { adaptParametersForGETRequests, correctType } from "./utilities.js";
|
|
7
|
+
export { Admin, Users, Teams, Events, Realtime };
|
|
2
8
|
/** If the {@link API} throws an error, it should always be an {@link APIError}! */
|
|
3
9
|
export class APIError extends Error {
|
|
4
10
|
message;
|
|
@@ -57,7 +63,7 @@ export class API {
|
|
|
57
63
|
/** Should always be "Bearer" */
|
|
58
64
|
get token_type() { return this._token_type; }
|
|
59
65
|
set token_type(token) { this._token_type = token; }
|
|
60
|
-
_expires = new Date(new Date().getTime() + 24 * 60 * 60 * 1000); // 24 hours default, is set through
|
|
66
|
+
_expires = new Date(new Date().getTime() + 24 * 60 * 60 * 1000); // 24 hours default, is set through setNewToken anyway
|
|
61
67
|
/** The expiration date of your token */
|
|
62
68
|
get expires() { return this._expires; }
|
|
63
69
|
set expires(date) {
|
|
@@ -336,7 +342,7 @@ export class API {
|
|
|
336
342
|
return response;
|
|
337
343
|
}
|
|
338
344
|
/**
|
|
339
|
-
* The function that directly communicates with the API! Almost
|
|
345
|
+
* The function that directly communicates with the API! Almost all functions of the API object uses this function!
|
|
340
346
|
* @param method The type of request, each endpoint uses a specific one (if it uses multiple, the intent and parameters become different)
|
|
341
347
|
* @param endpoint What comes in the URL after `api/`, **DO NOT USE TEMPLATE LITERALS (\`) OR THE ADDITION OPERATOR (+), put everything separately for type safety**
|
|
342
348
|
* @param parameters The things to specify in the request, such as the beatmap_id when looking for a beatmap
|
|
@@ -369,4 +375,38 @@ export class API {
|
|
|
369
375
|
async getWebsiteStats(website_id, startAt, endAt) {
|
|
370
376
|
return await this.request("get", ["websites", website_id, "stats"], { startAt: Number(startAt), endAt: Number(endAt) });
|
|
371
377
|
}
|
|
378
|
+
// ADMIN
|
|
379
|
+
getUsersAsAdmin = Admin.getUsers;
|
|
380
|
+
getWebsitesAsAdmin = Admin.getWebsites;
|
|
381
|
+
getTeamsAsAdmin = Admin.getTeams;
|
|
382
|
+
// USERS
|
|
383
|
+
createUser = Users.createUser;
|
|
384
|
+
getUser = Users.getUser;
|
|
385
|
+
updateUser = Users.updateUser;
|
|
386
|
+
deleteUser = Users.deleteUser;
|
|
387
|
+
getUserTeams = Users.getUserTeams;
|
|
388
|
+
getUserWebsites = Users.getUserWebsites;
|
|
389
|
+
// TEAMS
|
|
390
|
+
getTeams = Teams.getTeams;
|
|
391
|
+
createTeam = Teams.createTeam;
|
|
392
|
+
joinTeam = Teams.joinTeam;
|
|
393
|
+
getTeam = Teams.getTeam;
|
|
394
|
+
updateTeam = Teams.updateTeam;
|
|
395
|
+
deleteTeam = Teams.deleteTeam;
|
|
396
|
+
getTeamUsers = Teams.getTeamUsers;
|
|
397
|
+
addTeamUser = Teams.addTeamUser;
|
|
398
|
+
getTeamUser = Teams.getTeamUser;
|
|
399
|
+
updateTeamUser = Teams.updateTeamUser;
|
|
400
|
+
removeTeamUser = Teams.removeTeamUser;
|
|
401
|
+
getTeamWebsites = Teams.getTeamWebsites;
|
|
402
|
+
// EVENTS
|
|
403
|
+
getWebsiteEvents = Events.getWebsiteEvents;
|
|
404
|
+
getWebsiteEventData = Events.getWebsiteEventData;
|
|
405
|
+
getWebsiteEventsData = Events.getWebsiteEventsData;
|
|
406
|
+
getWebsiteEventsDataFields = Events.getWebsiteEventsDataFields;
|
|
407
|
+
getWebsiteEventsDataProperties = Events.getWebsiteEventsDataProperties;
|
|
408
|
+
getWebsiteEventsDataValues = Events.getWebsiteEventsDataValues;
|
|
409
|
+
getWebsiteEventsDataStats = Events.getWebsiteEventsDataStats;
|
|
410
|
+
// REALTIME
|
|
411
|
+
getRealtime = Realtime.getRealtime;
|
|
372
412
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { API, GenericObject, GenericRequestParameters, Role, Teams } from "../index.js";
|
|
2
|
+
/** For endpoints listed on: https://umami.is/docs/api/admin-api */
|
|
3
|
+
export declare namespace Admin {
|
|
4
|
+
/** Returns all users: https://umami.is/docs/api/admin-api#get-apiadminusers */
|
|
5
|
+
function getUsers(this: API, parameters?: GenericRequestParameters): Promise<(GenericObject & {
|
|
6
|
+
username: string;
|
|
7
|
+
/** @remarks **UNDOCUMENTED** & seems encrypted (thankfully, lol) */
|
|
8
|
+
password: string;
|
|
9
|
+
role: Role;
|
|
10
|
+
logoUrl: string | null;
|
|
11
|
+
displayName: string | null;
|
|
12
|
+
_count: {
|
|
13
|
+
/** @remarks **UNDOCUMENTED**, documented uncorrectly as `websites`? */
|
|
14
|
+
websiteUser: number;
|
|
15
|
+
};
|
|
16
|
+
})[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns all websites: https://umami.is/docs/api/admin-api#get-apiadminwebsites
|
|
19
|
+
* @remarks TODO Possibly doesn't work? (throws 400 on my end)
|
|
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
|
+
};
|
|
33
|
+
/** @remarks TODO Documentation says it can be null but doesn't actually say what else it can be, ***presumed* to be string**, check */
|
|
34
|
+
team: string | null;
|
|
35
|
+
})[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Returns all teams: https://umami.is/docs/api/admin-api#get-apiadminteams
|
|
38
|
+
* @remarks TODO Possibly doesn't work? (throws 404 on my end)
|
|
39
|
+
*/
|
|
40
|
+
function getTeams(this: API, parameters?: GenericRequestParameters): Promise<(GenericObject & {
|
|
41
|
+
name: string;
|
|
42
|
+
accessCode: string;
|
|
43
|
+
logoUrl: string | null;
|
|
44
|
+
members: Teams.TeamMember[];
|
|
45
|
+
_count: {
|
|
46
|
+
websites: number;
|
|
47
|
+
members: number;
|
|
48
|
+
};
|
|
49
|
+
})[]>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** For endpoints listed on: https://umami.is/docs/api/admin-api */
|
|
2
|
+
export var Admin;
|
|
3
|
+
(function (Admin) {
|
|
4
|
+
/** Returns all users: https://umami.is/docs/api/admin-api#get-apiadminusers */
|
|
5
|
+
async function getUsers(parameters) {
|
|
6
|
+
const response = await this.request("get", ["admin", "users"], parameters);
|
|
7
|
+
return response.data;
|
|
8
|
+
}
|
|
9
|
+
Admin.getUsers = getUsers;
|
|
10
|
+
/**
|
|
11
|
+
* Returns all websites: https://umami.is/docs/api/admin-api#get-apiadminwebsites
|
|
12
|
+
* @remarks TODO Possibly doesn't work? (throws 400 on my end)
|
|
13
|
+
*/
|
|
14
|
+
async function getWebsites(parameters) {
|
|
15
|
+
const response = await this.request("get", ["admin", "websites"], parameters);
|
|
16
|
+
return response.data;
|
|
17
|
+
}
|
|
18
|
+
Admin.getWebsites = getWebsites;
|
|
19
|
+
/**
|
|
20
|
+
* Returns all teams: https://umami.is/docs/api/admin-api#get-apiadminteams
|
|
21
|
+
* @remarks TODO Possibly doesn't work? (throws 404 on my end)
|
|
22
|
+
*/
|
|
23
|
+
async function getTeams(parameters) {
|
|
24
|
+
const response = await this.request("get", ["admin", "teams"], parameters);
|
|
25
|
+
return response.data;
|
|
26
|
+
}
|
|
27
|
+
Admin.getTeams = getTeams;
|
|
28
|
+
})(Admin || (Admin = {}));
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { API, GenericRequestParameters } from "../index.js";
|
|
2
|
+
/** For endpoints listed on: https://umami.is/docs/api/events-api */
|
|
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
|
+
/** 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<{
|
|
43
|
+
id: string;
|
|
44
|
+
websiteId: string;
|
|
45
|
+
sessionId: string;
|
|
46
|
+
createdAt: Date;
|
|
47
|
+
hostname: string;
|
|
48
|
+
urlPath: string;
|
|
49
|
+
urlQuery: string;
|
|
50
|
+
referrerPath: string;
|
|
51
|
+
referrerQuery: string;
|
|
52
|
+
referrerDomain: string;
|
|
53
|
+
country: string;
|
|
54
|
+
city: string;
|
|
55
|
+
device: string;
|
|
56
|
+
os: string;
|
|
57
|
+
browser: string;
|
|
58
|
+
pageTitle: string;
|
|
59
|
+
eventType: number;
|
|
60
|
+
eventName: string;
|
|
61
|
+
hasData: number;
|
|
62
|
+
}[]>;
|
|
63
|
+
/** Gets event-data for a individual event https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevent-dataeventid (TODO UNTESTED) */
|
|
64
|
+
function getWebsiteEventData(this: API, websiteId: string, eventId: string): Promise<{
|
|
65
|
+
websiteId: string;
|
|
66
|
+
sessionId: string;
|
|
67
|
+
eventId: string;
|
|
68
|
+
urlPath: string;
|
|
69
|
+
eventName: string;
|
|
70
|
+
dataKey: string;
|
|
71
|
+
stringValue: string;
|
|
72
|
+
numberValue: number | null;
|
|
73
|
+
dateValue: Date | null;
|
|
74
|
+
dataType: number;
|
|
75
|
+
createdAt: Date;
|
|
76
|
+
}[]>;
|
|
77
|
+
/** 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 & {
|
|
79
|
+
/** Event name filter */
|
|
80
|
+
event?: string;
|
|
81
|
+
}): Promise<{
|
|
82
|
+
eventName: string;
|
|
83
|
+
propertyName: string;
|
|
84
|
+
dataType: number;
|
|
85
|
+
total: number;
|
|
86
|
+
}[]>;
|
|
87
|
+
/** 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<{
|
|
89
|
+
propertyName: string;
|
|
90
|
+
dataType: number;
|
|
91
|
+
value: string;
|
|
92
|
+
total: number;
|
|
93
|
+
}[]>;
|
|
94
|
+
/** 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<{
|
|
96
|
+
eventName: string;
|
|
97
|
+
propertyName: string;
|
|
98
|
+
total: number;
|
|
99
|
+
}[]>;
|
|
100
|
+
/** 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 & {
|
|
102
|
+
/** Event name filter */
|
|
103
|
+
event: string;
|
|
104
|
+
/** Property name */
|
|
105
|
+
propertyName: string;
|
|
106
|
+
}): Promise<{
|
|
107
|
+
value: string;
|
|
108
|
+
total: number;
|
|
109
|
+
}>;
|
|
110
|
+
/** 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<{
|
|
112
|
+
events: number;
|
|
113
|
+
properties: number;
|
|
114
|
+
records: number;
|
|
115
|
+
}[]>;
|
|
116
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** For endpoints listed on: https://umami.is/docs/api/events-api */
|
|
2
|
+
export var Events;
|
|
3
|
+
(function (Events) {
|
|
4
|
+
/** Gets website event details within a given time range: https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevents (TODO UNTESTED) */
|
|
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
|
+
const response = await this.request("get", ["websites", websiteId, "events"], parameters);
|
|
11
|
+
return response.data;
|
|
12
|
+
}
|
|
13
|
+
Events.getWebsiteEvents = getWebsiteEvents;
|
|
14
|
+
/** Gets event-data for a individual event https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevent-dataeventid (TODO UNTESTED) */
|
|
15
|
+
async function getWebsiteEventData(websiteId, eventId) {
|
|
16
|
+
return await this.request("get", ["websites", websiteId, "event-data", eventId]);
|
|
17
|
+
}
|
|
18
|
+
Events.getWebsiteEventData = getWebsiteEventData;
|
|
19
|
+
/** Gets event data names, properties, and counts: https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevent-dataevents (TODO UNTESTED) */
|
|
20
|
+
async function getWebsiteEventsData(websiteId, parameters) {
|
|
21
|
+
return await this.request("get", ["websites", websiteId, "event-data", "events"], parameters);
|
|
22
|
+
}
|
|
23
|
+
Events.getWebsiteEventsData = getWebsiteEventsData;
|
|
24
|
+
/** Gets event data property and value counts within a given time range: https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevent-datafields (TODO UNTESTED) */
|
|
25
|
+
async function getWebsiteEventsDataFields(websiteId, parameters) {
|
|
26
|
+
return await this.request("get", ["websites", websiteId, "event-data", "fields"], parameters);
|
|
27
|
+
}
|
|
28
|
+
Events.getWebsiteEventsDataFields = getWebsiteEventsDataFields;
|
|
29
|
+
/** Gets event name and property counts for a website: https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevent-dataproperties (TODO UNTESTED) */
|
|
30
|
+
async function getWebsiteEventsDataProperties(websiteId, parameters) {
|
|
31
|
+
return await this.request("get", ["websites", websiteId, "event-data", "properties"], parameters);
|
|
32
|
+
}
|
|
33
|
+
Events.getWebsiteEventsDataProperties = getWebsiteEventsDataProperties;
|
|
34
|
+
/** Gets event data counts for a given event and property: https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevent-datavalues (TODO UNTESTED) */
|
|
35
|
+
async function getWebsiteEventsDataValues(websiteId, parameters) {
|
|
36
|
+
return await this.request("get", ["websites", websiteId, "event-data", "values"], parameters);
|
|
37
|
+
}
|
|
38
|
+
Events.getWebsiteEventsDataValues = getWebsiteEventsDataValues;
|
|
39
|
+
/** Gets aggregated website events, properties, and records within a given time range https://umami.is/docs/api/events-api#get-apiwebsiteswebsiteidevent-datastats (TODO UNTESTED) */
|
|
40
|
+
async function getWebsiteEventsDataStats(websiteId, parameters) {
|
|
41
|
+
return await this.request("get", ["websites", websiteId, "event-data", "stats"], parameters);
|
|
42
|
+
}
|
|
43
|
+
Events.getWebsiteEventsDataStats = getWebsiteEventsDataStats;
|
|
44
|
+
})(Events || (Events = {}));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { API } from "../index.js";
|
|
2
|
+
/** For endpoints listed on: https://umami.is/docs/api/realtime-api */
|
|
3
|
+
export declare namespace Realtime {
|
|
4
|
+
/** Realtime stats within the last 30 minutes: https://umami.is/docs/api/realtime-api#get-apirealtimewebsiteid (TODO UNTESTED) */
|
|
5
|
+
function getRealtime(this: API, websiteId: string): Promise<{
|
|
6
|
+
countries: {
|
|
7
|
+
[k: string]: number;
|
|
8
|
+
};
|
|
9
|
+
urls: {
|
|
10
|
+
[k: string]: number;
|
|
11
|
+
};
|
|
12
|
+
referrers: {
|
|
13
|
+
[k: string]: number;
|
|
14
|
+
};
|
|
15
|
+
events: {
|
|
16
|
+
__type: string;
|
|
17
|
+
sessionId: string;
|
|
18
|
+
eventName: string;
|
|
19
|
+
createdAt: Date;
|
|
20
|
+
browser: string;
|
|
21
|
+
os: string;
|
|
22
|
+
device: string;
|
|
23
|
+
country: string;
|
|
24
|
+
urlPath: string;
|
|
25
|
+
referrerDomain: string;
|
|
26
|
+
}[];
|
|
27
|
+
series: {
|
|
28
|
+
views: {
|
|
29
|
+
x: Date;
|
|
30
|
+
y: number;
|
|
31
|
+
}[];
|
|
32
|
+
visitors: {
|
|
33
|
+
x: Date;
|
|
34
|
+
y: number;
|
|
35
|
+
}[];
|
|
36
|
+
};
|
|
37
|
+
totals: {
|
|
38
|
+
views: number;
|
|
39
|
+
visitors: number;
|
|
40
|
+
events: number;
|
|
41
|
+
countries: number;
|
|
42
|
+
};
|
|
43
|
+
timestamp: number;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** For endpoints listed on: https://umami.is/docs/api/realtime-api */
|
|
2
|
+
export var Realtime;
|
|
3
|
+
(function (Realtime) {
|
|
4
|
+
/** Realtime stats within the last 30 minutes: https://umami.is/docs/api/realtime-api#get-apirealtimewebsiteid (TODO UNTESTED) */
|
|
5
|
+
async function getRealtime(websiteId) {
|
|
6
|
+
return await this.request("post", ["realtime", websiteId]);
|
|
7
|
+
}
|
|
8
|
+
Realtime.getRealtime = getRealtime;
|
|
9
|
+
})(Realtime || (Realtime = {}));
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { API, GenericObject, GenericRequestParameters, TeamRole } from "../index.js";
|
|
2
|
+
/** For endpoints listed on: https://umami.is/docs/api/teams-api */
|
|
3
|
+
export declare namespace Teams {
|
|
4
|
+
interface GenericTeam extends GenericObject {
|
|
5
|
+
name: string;
|
|
6
|
+
accessCode: string;
|
|
7
|
+
logoUrl: string | null;
|
|
8
|
+
}
|
|
9
|
+
interface TeamMember extends Omit<GenericObject, "deletedAt"> {
|
|
10
|
+
teamId: string;
|
|
11
|
+
userId: string;
|
|
12
|
+
role: TeamRole;
|
|
13
|
+
user: {
|
|
14
|
+
id: string;
|
|
15
|
+
username: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** Returns all teams: https://umami.is/docs/api/teams-api#get-apiteams (TODO UNTESTED) */
|
|
19
|
+
function getTeams(this: API, parameters?: Omit<GenericRequestParameters, "search">): Promise<(GenericTeam & {
|
|
20
|
+
members: TeamMember[];
|
|
21
|
+
_count: {
|
|
22
|
+
websites: number;
|
|
23
|
+
members: number;
|
|
24
|
+
};
|
|
25
|
+
})[]>;
|
|
26
|
+
/** Creates a team: https://umami.is/docs/api/teams-api#post-apiteams (TODO UNTESTED) */
|
|
27
|
+
function createTeam(this: API, name: string): Promise<[GenericTeam, Omit<TeamMember, "user">]>;
|
|
28
|
+
/** Join a team: https://umami.is/docs/api/teams-api#post-apiteamsjoin (TODO UNTESTED) */
|
|
29
|
+
function joinTeam(this: API, accessCode: string): Promise<Omit<TeamMember, "user">>;
|
|
30
|
+
/** Get a team: https://umami.is/docs/api/teams-api#get-apiteamsteamid (TODO UNTESTED) */
|
|
31
|
+
function getTeam(this: API, teamId: string): Promise<GenericTeam & {
|
|
32
|
+
members: Omit<TeamMember, "user">[];
|
|
33
|
+
}>;
|
|
34
|
+
/** Update a team: https://umami.is/docs/api/teams-api#post-apiteamsteamid (TODO UNTESTED) */
|
|
35
|
+
function updateTeam(this: API, teamId: string, parameters: {
|
|
36
|
+
/** The team's name */
|
|
37
|
+
name?: string;
|
|
38
|
+
/** The team's access code */
|
|
39
|
+
accessCode?: string;
|
|
40
|
+
}): Promise<GenericTeam>;
|
|
41
|
+
/** Delete a team: https://umami.is/docs/api/teams-api#delete-apiteamsteamid (TODO UNTESTED) */
|
|
42
|
+
function deleteTeam(this: API, teamId: string): Promise<{
|
|
43
|
+
ok: boolean;
|
|
44
|
+
}>;
|
|
45
|
+
/** Get all users that belong to a team: https://umami.is/docs/api/teams-api#get-apiteamsteamidusers (TODO UNTESTED) */
|
|
46
|
+
function getTeamUsers(this: API, teamId: string, parameters: GenericRequestParameters): Promise<TeamMember[]>;
|
|
47
|
+
/** Add a user to a team: https://umami.is/docs/api/teams-api#post-apiteamsteamidusers (TODO UNTESTED) */
|
|
48
|
+
function addTeamUser(this: API, teamId: string, parameters: {
|
|
49
|
+
/** ID of user to be added */
|
|
50
|
+
userId: string;
|
|
51
|
+
/** Team role for user */
|
|
52
|
+
role: TeamRole;
|
|
53
|
+
}): Promise<Omit<TeamMember, "user">>;
|
|
54
|
+
/** Get a user belonging to a team: https://umami.is/docs/api/teams-api#get-apiteamsteamidusersuserid (TODO UNTESTED) */
|
|
55
|
+
function getTeamUser(this: API, teamId: string, userId: string): Promise<Omit<TeamMember, "user">>;
|
|
56
|
+
/** Update a user's role on a team: https://umami.is/docs/api/teams-api#post-apiteamsteamidusersuserid (TODO UNTESTED) */
|
|
57
|
+
function updateTeamUser(this: API, teamId: string, userId: string, role: TeamRole): Promise<Omit<TeamMember, "user">>;
|
|
58
|
+
/** Remove a user from a team: https://umami.is/docs/api/teams-api#delete-apiteamsteamidusersuserid (TODO UNTESTED) */
|
|
59
|
+
function removeTeamUser(this: API, teamId: string, userId: string): Promise<{
|
|
60
|
+
ok: boolean;
|
|
61
|
+
}>;
|
|
62
|
+
/** Get all websites that belong to a team: https://umami.is/docs/api/teams-api#get-apiteamsteamidwebsites (TODO UNTESTED) */
|
|
63
|
+
function getTeamWebsites(this: API, teamId: string, parameters: GenericRequestParameters): Promise<(GenericObject & {
|
|
64
|
+
name: string;
|
|
65
|
+
domain: string;
|
|
66
|
+
shareId: string;
|
|
67
|
+
resetAt: Date | null;
|
|
68
|
+
userId: string | null;
|
|
69
|
+
teamId: string | null;
|
|
70
|
+
createdBy: string;
|
|
71
|
+
createUser: {
|
|
72
|
+
id: string;
|
|
73
|
+
username: string;
|
|
74
|
+
};
|
|
75
|
+
})[]>;
|
|
76
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** For endpoints listed on: https://umami.is/docs/api/teams-api */
|
|
2
|
+
export var Teams;
|
|
3
|
+
(function (Teams) {
|
|
4
|
+
/** Returns all teams: https://umami.is/docs/api/teams-api#get-apiteams (TODO UNTESTED) */
|
|
5
|
+
async function getTeams(parameters) {
|
|
6
|
+
const response = await this.request("get", ["teams"], parameters);
|
|
7
|
+
return response.data;
|
|
8
|
+
}
|
|
9
|
+
Teams.getTeams = getTeams;
|
|
10
|
+
/** Creates a team: https://umami.is/docs/api/teams-api#post-apiteams (TODO UNTESTED) */
|
|
11
|
+
async function createTeam(name) {
|
|
12
|
+
return await this.request("post", ["teams"], { name });
|
|
13
|
+
}
|
|
14
|
+
Teams.createTeam = createTeam;
|
|
15
|
+
/** Join a team: https://umami.is/docs/api/teams-api#post-apiteamsjoin (TODO UNTESTED) */
|
|
16
|
+
async function joinTeam(accessCode) {
|
|
17
|
+
return await this.request("post", ["teams", "join"], { accessCode });
|
|
18
|
+
}
|
|
19
|
+
Teams.joinTeam = joinTeam;
|
|
20
|
+
/** Get a team: https://umami.is/docs/api/teams-api#get-apiteamsteamid (TODO UNTESTED) */
|
|
21
|
+
async function getTeam(teamId) {
|
|
22
|
+
return await this.request("get", ["teams", teamId]);
|
|
23
|
+
}
|
|
24
|
+
Teams.getTeam = getTeam;
|
|
25
|
+
/** Update a team: https://umami.is/docs/api/teams-api#post-apiteamsteamid (TODO UNTESTED) */
|
|
26
|
+
async function updateTeam(teamId, parameters) {
|
|
27
|
+
return await this.request("post", ["teams", teamId], parameters);
|
|
28
|
+
}
|
|
29
|
+
Teams.updateTeam = updateTeam;
|
|
30
|
+
/** Delete a team: https://umami.is/docs/api/teams-api#delete-apiteamsteamid (TODO UNTESTED) */
|
|
31
|
+
async function deleteTeam(teamId) {
|
|
32
|
+
return await this.request("delete", ["teams", teamId]);
|
|
33
|
+
}
|
|
34
|
+
Teams.deleteTeam = deleteTeam;
|
|
35
|
+
/** Get all users that belong to a team: https://umami.is/docs/api/teams-api#get-apiteamsteamidusers (TODO UNTESTED) */
|
|
36
|
+
async function getTeamUsers(teamId, parameters) {
|
|
37
|
+
const response = await this.request("get", ["teams", teamId, "users"], parameters);
|
|
38
|
+
return response.data;
|
|
39
|
+
}
|
|
40
|
+
Teams.getTeamUsers = getTeamUsers;
|
|
41
|
+
/** Add a user to a team: https://umami.is/docs/api/teams-api#post-apiteamsteamidusers (TODO UNTESTED) */
|
|
42
|
+
async function addTeamUser(teamId, parameters) {
|
|
43
|
+
return await this.request("post", ["teams", teamId, "users"], parameters);
|
|
44
|
+
}
|
|
45
|
+
Teams.addTeamUser = addTeamUser;
|
|
46
|
+
/** Get a user belonging to a team: https://umami.is/docs/api/teams-api#get-apiteamsteamidusersuserid (TODO UNTESTED) */
|
|
47
|
+
async function getTeamUser(teamId, userId) {
|
|
48
|
+
return await this.request("get", ["teams", teamId, "users", userId]);
|
|
49
|
+
}
|
|
50
|
+
Teams.getTeamUser = getTeamUser;
|
|
51
|
+
/** Update a user's role on a team: https://umami.is/docs/api/teams-api#post-apiteamsteamidusersuserid (TODO UNTESTED) */
|
|
52
|
+
async function updateTeamUser(teamId, userId, role) {
|
|
53
|
+
return await this.request("post", ["teams", teamId, "users", userId], { role });
|
|
54
|
+
}
|
|
55
|
+
Teams.updateTeamUser = updateTeamUser;
|
|
56
|
+
/** Remove a user from a team: https://umami.is/docs/api/teams-api#delete-apiteamsteamidusersuserid (TODO UNTESTED) */
|
|
57
|
+
async function removeTeamUser(teamId, userId) {
|
|
58
|
+
return await this.request("delete", ["teams", teamId, "users", userId]);
|
|
59
|
+
}
|
|
60
|
+
Teams.removeTeamUser = removeTeamUser;
|
|
61
|
+
/** Get all websites that belong to a team: https://umami.is/docs/api/teams-api#get-apiteamsteamidwebsites (TODO UNTESTED) */
|
|
62
|
+
async function getTeamWebsites(teamId, parameters) {
|
|
63
|
+
const response = await this.request("get", ["teams", teamId, "websites"], parameters);
|
|
64
|
+
return response.data;
|
|
65
|
+
}
|
|
66
|
+
Teams.getTeamWebsites = getTeamWebsites;
|
|
67
|
+
})(Teams || (Teams = {}));
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { API, GenericObject, GenericRequestParameters, Role, TeamRole } from "../index.js";
|
|
2
|
+
/** For endpoints listed on: https://umami.is/docs/api/users-api */
|
|
3
|
+
export declare namespace Users {
|
|
4
|
+
interface GenericUser {
|
|
5
|
+
id: string;
|
|
6
|
+
username: string;
|
|
7
|
+
role: Role;
|
|
8
|
+
}
|
|
9
|
+
/** Creates a user: https://umami.is/docs/api/users-api#post-apiusers */
|
|
10
|
+
function createUser(this: API, parameters: {
|
|
11
|
+
/** The user's username */
|
|
12
|
+
username: string;
|
|
13
|
+
/** The user's password */
|
|
14
|
+
password: string;
|
|
15
|
+
/** The user's role */
|
|
16
|
+
role: Role;
|
|
17
|
+
/** Force a UUID assignment to the user */
|
|
18
|
+
id?: string;
|
|
19
|
+
}): Promise<GenericUser>;
|
|
20
|
+
/** Gets a user by ID: https://umami.is/docs/api/users-api#get-apiusersuserid */
|
|
21
|
+
function getUser(this: API, id: string): Promise<GenericUser & {
|
|
22
|
+
createdAt: Date;
|
|
23
|
+
}>;
|
|
24
|
+
/** Updates a user: https://umami.is/docs/api/users-api#post-apiusersuserid */
|
|
25
|
+
function updateUser(this: API, id: string, parameters?: {
|
|
26
|
+
/** The user's username */
|
|
27
|
+
username?: string;
|
|
28
|
+
/** The user's password */
|
|
29
|
+
password?: string;
|
|
30
|
+
/** The user's role */
|
|
31
|
+
role?: Role;
|
|
32
|
+
}): Promise<GenericUser & {
|
|
33
|
+
createdAt: Date;
|
|
34
|
+
}>;
|
|
35
|
+
/** Deletes a user: https://umami.is/docs/api/users-api#delete-apiusersuserid */
|
|
36
|
+
function deleteUser(this: API, id: string): Promise<{
|
|
37
|
+
ok: boolean;
|
|
38
|
+
}>;
|
|
39
|
+
/** Gets all websites that belong to a user: https://umami.is/docs/api/users-api#get-apiusersuseridwebsites */
|
|
40
|
+
function getUserWebsites(this: API, id: string, parameters: GenericRequestParameters & {
|
|
41
|
+
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
|
+
};
|
|
54
|
+
})[]>;
|
|
55
|
+
/** Gets all teams that belong to a user: https://umami.is/docs/api/users-api#get-apiusersuseridteams */
|
|
56
|
+
function getUserTeams(this: API, id: string, parameters?: Omit<GenericRequestParameters, "search">): Promise<(GenericObject & {
|
|
57
|
+
name: string;
|
|
58
|
+
accessCode: string;
|
|
59
|
+
logoUrl: string | null;
|
|
60
|
+
members: Omit<GenericObject, "deletedAt"> & {
|
|
61
|
+
teamId: string;
|
|
62
|
+
userId: string;
|
|
63
|
+
role: TeamRole;
|
|
64
|
+
user: {
|
|
65
|
+
id: string;
|
|
66
|
+
username: string;
|
|
67
|
+
};
|
|
68
|
+
}[];
|
|
69
|
+
_count: {
|
|
70
|
+
websites: number;
|
|
71
|
+
members: number;
|
|
72
|
+
};
|
|
73
|
+
})[]>;
|
|
74
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** For endpoints listed on: https://umami.is/docs/api/users-api */
|
|
2
|
+
export var Users;
|
|
3
|
+
(function (Users) {
|
|
4
|
+
/** Creates a user: https://umami.is/docs/api/users-api#post-apiusers */
|
|
5
|
+
async function createUser(parameters) {
|
|
6
|
+
return await this.request("post", ["users"], parameters);
|
|
7
|
+
}
|
|
8
|
+
Users.createUser = createUser;
|
|
9
|
+
/** Gets a user by ID: https://umami.is/docs/api/users-api#get-apiusersuserid */
|
|
10
|
+
async function getUser(id) {
|
|
11
|
+
return await this.request("get", ["users", id]);
|
|
12
|
+
}
|
|
13
|
+
Users.getUser = getUser;
|
|
14
|
+
/** Updates a user: https://umami.is/docs/api/users-api#post-apiusersuserid */
|
|
15
|
+
async function updateUser(id, parameters) {
|
|
16
|
+
return await this.request("post", ["users", id], parameters);
|
|
17
|
+
}
|
|
18
|
+
Users.updateUser = updateUser;
|
|
19
|
+
/** Deletes a user: https://umami.is/docs/api/users-api#delete-apiusersuserid */
|
|
20
|
+
async function deleteUser(id) {
|
|
21
|
+
return await this.request("delete", ["users", id]);
|
|
22
|
+
}
|
|
23
|
+
Users.deleteUser = deleteUser;
|
|
24
|
+
/** Gets all websites that belong to a user: https://umami.is/docs/api/users-api#get-apiusersuseridwebsites */
|
|
25
|
+
async function getUserWebsites(id, parameters) {
|
|
26
|
+
const response = await this.request("get", ["users", id, "websites"], parameters);
|
|
27
|
+
return response.data;
|
|
28
|
+
}
|
|
29
|
+
Users.getUserWebsites = getUserWebsites;
|
|
30
|
+
/** Gets all teams that belong to a user: https://umami.is/docs/api/users-api#get-apiusersuseridteams */
|
|
31
|
+
async function getUserTeams(id, parameters) {
|
|
32
|
+
const response = await this.request("get", ["users", id, "teams"], parameters);
|
|
33
|
+
return response.data;
|
|
34
|
+
}
|
|
35
|
+
Users.getUserTeams = getUserTeams;
|
|
36
|
+
})(Users || (Users = {}));
|
package/dist/utilities.js
CHANGED
|
@@ -55,9 +55,10 @@ export function correctType(x, force_string) {
|
|
|
55
55
|
const keys = Object.keys(x);
|
|
56
56
|
const vals = Object.values(x);
|
|
57
57
|
// If a key is any of those, the value is expected to be a string, so we use `force_string` to make correctType convert them to string for us
|
|
58
|
-
const unconvertables = [];
|
|
58
|
+
const unconvertables = ["value"];
|
|
59
|
+
const unconvertables_substrings = ["string", "name"]; // or if the key contains any of those substrings
|
|
59
60
|
for (let i = 0; i < keys.length; i++) {
|
|
60
|
-
x[keys[i]] = correctType(vals[i], unconvertables.some((
|
|
61
|
+
x[keys[i]] = correctType(vals[i], unconvertables.some((u) => keys[i] === u) ?? unconvertables_substrings.some((s) => keys[i].toLowerCase().includes(s)));
|
|
61
62
|
}
|
|
62
63
|
return x;
|
|
63
64
|
}
|