umami-api-js 1.0.0 → 1.1.0

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
@@ -82,13 +82,14 @@ const api = new umami.API("<api_endpoint>", "<username>", "<password>", {
82
82
 
83
83
  ### Tokens
84
84
 
85
- An [`access_token`](https://umami-api-js.taevas.xyz/classes/API.html#access_token) is required to access the API, and should be valid for 24 hours. When you first create your [`api`](https://umami-api-js.taevas.xyz/classes/API.html) object, that token is automatically set before any request is made, so you don't have to worry about that! But how about after those 24 hours?
85
+ An [`access_token`](https://umami-api-js.taevas.xyz/classes/API.html#access_token) is required to access the API. When you first create your [`api`](https://umami-api-js.taevas.xyz/classes/API.html) object, that token is automatically set before any request is made, so you don't have to worry about that!
86
86
 
87
- Once an `access_token` has become invalid, the server will no longer respond correctly to requests made with it, instead responding with [401](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/401). Thankfully, there are solutions to get and set new `access_token`s in a convenient way, so there is no need to create a new `api` object every day!
87
+ Unlike many other web applications, [Umami doesn't expire tokens after a certain amount of time](https://github.com/umami-software/umami/discussions/1170), meaning in theory that you would only ever need to request a new token if your credentials change. After changing the [username](https://umami-api-js.taevas.xyz/classes/API.html#username) or [password](https://umami-api-js.taevas.xyz/classes/API.html#password), you may manually call [`setNewToken()`](https://umami-api-js.taevas.xyz/classes/API.html#setnewtoken), which will replace your previous token with a new one!
88
88
 
89
- - If you'd like to manually get a new `access_token`, calling [`setNewToken()`](https://umami-api-js.taevas.xyz/classes/API.html#setnewtoken) will replace your previous token with a new one
90
- - Keep the [`set_token_on_expires`](https://umami-api-js.taevas.xyz/classes/API.html#set_token_on_expires) option to true if you'd like the object to call it automatically as soon as the token expires
91
- - By default, the [`set_token_on_401`](https://umami-api-js.taevas.xyz/classes/API.html#set_token_on_401) option is set to true, which (as its name indicates) will do that upon encountering a 401
89
+ This package was built with the expectation that tokens would eventually expire, so you've got some configuration options you can play around with:
90
+
91
+ - Keep the [`set_token_on_expires`](https://umami-api-js.taevas.xyz/classes/API.html#set_token_on_expires) option to true if you'd like the object to call `setNewToken()` automatically as soon as the token expires
92
+ - By default, the [`set_token_on_401`](https://umami-api-js.taevas.xyz/classes/API.html#set_token_on_401) option is set to false, which (as its name indicates) would do that upon encountering a 401
92
93
  - When that happens, if [`retry_on_new_token`](https://umami-api-js.taevas.xyz/classes/API.html#retry_on_new_token) is set to true as it is by default, it will retry the request it has encountered a 401 on, with the new token! (note that loops are prevented, it won't retry or get another token if the same request with the new token gets a 401)
93
94
 
94
95
  At any point in time, you can see when the current `access_token` is set to expire through the [`expires`](https://umami-api-js.taevas.xyz/classes/API.html#expires) property of the API.
package/dist/index.d.ts CHANGED
@@ -6,11 +6,12 @@ import { Pixels } from "./namespaces/Pixels.js";
6
6
  import { Realtime } from "./namespaces/Realtime.js";
7
7
  import { Reports } from "./namespaces/Reports.js";
8
8
  import { Sessions } from "./namespaces/Sessions.js";
9
+ import { Share } from "./namespaces/Share.js";
9
10
  import { Teams } from "./namespaces/Teams.js";
10
11
  import { Users } from "./namespaces/Users.js";
11
12
  import { Websites } from "./namespaces/Websites.js";
12
13
  import { WebsiteStats } from "./namespaces/WebsiteStats.js";
13
- export { Admin, Events, Links, Me, Pixels, Websites, WebsiteStats, Realtime, Reports, Sessions, Teams, Users, };
14
+ export { Admin, Events, Links, Me, Pixels, Websites, WebsiteStats, Realtime, Reports, Sessions, Share, Teams, Users, };
14
15
  export interface DeletionResult {
15
16
  ok: boolean;
16
17
  }
@@ -125,9 +126,13 @@ export declare class API {
125
126
  get token_type(): string;
126
127
  set token_type(token: string);
127
128
  private _expires;
128
- /** The expiration date of your token */
129
- get expires(): Date;
130
- set expires(date: Date);
129
+ /**
130
+ * The expiration date of your token
131
+ * @remarks Umami v3.0.3 behaviour is to NOT expire tokens a given amount of time after creation,
132
+ * see https://github.com/umami-software/umami/discussions/1170
133
+ */
134
+ get expires(): Date | null;
135
+ set expires(date: Date | null);
131
136
  private _server;
132
137
  /** The base URL where requests should land, **should include the `/api` portion if applicable** */
133
138
  get server(): string;
@@ -153,8 +158,8 @@ export declare class API {
153
158
  });
154
159
  private _user;
155
160
  /** Information about the account that has been used to log in */
156
- get user(): Users.User;
157
- set user(user: Users.User);
161
+ get user(): Users.UserWithTeams;
162
+ set user(user: Users.UserWithTeams);
158
163
  private number_of_requests;
159
164
  /** Has {@link API.setNewToken} been called and not yet returned anything? */
160
165
  private is_setting_token;
@@ -171,7 +176,7 @@ export declare class API {
171
176
  get set_token_on_creation(): boolean;
172
177
  set set_token_on_creation(bool: boolean);
173
178
  private _set_token_on_401;
174
- /** If true, upon failing a request due to a 401, it will call {@link API.setNewToken} (defaults to **true**) */
179
+ /** If true, upon failing a request due to a 401, it will call {@link API.setNewToken} (defaults to **false**) */
175
180
  get set_token_on_401(): boolean;
176
181
  set set_token_on_401(bool: boolean);
177
182
  private _set_token_on_expires;
@@ -188,8 +193,8 @@ export declare class API {
188
193
  private updateTokenTimer;
189
194
  private _verbose?;
190
195
  /** Which events should be logged (defaults to **none**) */
191
- get verbose(): "none" | "errors" | "all" | undefined;
192
- set verbose(verbose: "none" | "errors" | "all" | undefined);
196
+ get verbose(): "all" | "none" | "errors" | undefined;
197
+ set verbose(verbose: "all" | "none" | "errors" | undefined);
193
198
  private _timeout;
194
199
  /**
195
200
  * The maximum **amount of seconds** requests should take before returning an answer (defaults to **20**)
@@ -305,6 +310,8 @@ export declare class API {
305
310
  /** @group Links endpoints */
306
311
  readonly getLinks: typeof Links.get;
307
312
  /** @group Links endpoints */
313
+ readonly createLink: typeof Links.post;
314
+ /** @group Links endpoints */
308
315
  readonly getLink: typeof Links.get_LINKID;
309
316
  /** @group Links endpoints */
310
317
  readonly updateLink: typeof Links.post_LINKID;
@@ -316,13 +323,15 @@ export declare class API {
316
323
  readonly getMyTeams: typeof Me.getTeams;
317
324
  /** @group Me endpoints */
318
325
  readonly getMyWebsites: typeof Me.getWebsites;
319
- /** @group Links endpoints */
326
+ /** @group Pixels endpoints */
320
327
  readonly getPixels: typeof Pixels.get;
321
- /** @group Links endpoints */
328
+ /** @group Pixels endpoints */
329
+ readonly createPixel: typeof Pixels.post;
330
+ /** @group Pixels endpoints */
322
331
  readonly getPixel: typeof Pixels.get_PIXELID;
323
- /** @group Links endpoints */
332
+ /** @group Pixels endpoints */
324
333
  readonly updatePixel: typeof Pixels.post_PIXELID;
325
- /** @group Links endpoints */
334
+ /** @group Pixels endpoints */
326
335
  readonly deletePixel: typeof Pixels.delete_PIXELID;
327
336
  /** @group Websites endpoints */
328
337
  readonly getWebsites: typeof Websites.get;
@@ -392,6 +401,18 @@ export declare class API {
392
401
  readonly getWebsiteSessionDataProperties: typeof Sessions.get_WEBSITEID_SessiondataProperties;
393
402
  /** @group Sessions endpoints */
394
403
  readonly getWebsiteSessionDataValues: typeof Sessions.get_WEBSITEID_SessiondataValues;
404
+ /** @group Share endpoints */
405
+ readonly createShare: typeof Share.post;
406
+ /** @group Share endpoints */
407
+ readonly getShare: typeof Share.get_SHAREID;
408
+ /** @group Share endpoints */
409
+ readonly updateShare: typeof Share.post_SHAREID;
410
+ /** @group Share endpoints */
411
+ readonly deleteShare: typeof Share.delete_SHAREID;
412
+ /** @group Share endpoints */
413
+ readonly getWebsiteShares: typeof Share.get_WEBSITEID_Shares;
414
+ /** @group Share endpoints */
415
+ readonly createWebsiteShare: typeof Share.post_WEBSITEID_Shares;
395
416
  /** @group Teams endpoints */
396
417
  readonly getTeams: typeof Teams.get;
397
418
  /** @group Teams endpoints */
package/dist/index.js CHANGED
@@ -6,12 +6,13 @@ import { Pixels } from "./namespaces/Pixels.js";
6
6
  import { Realtime } from "./namespaces/Realtime.js";
7
7
  import { Reports } from "./namespaces/Reports.js";
8
8
  import { Sessions } from "./namespaces/Sessions.js";
9
+ import { Share } from "./namespaces/Share.js";
9
10
  import { Teams } from "./namespaces/Teams.js";
10
11
  import { Users } from "./namespaces/Users.js";
11
12
  import { Websites } from "./namespaces/Websites.js";
12
13
  import { WebsiteStats } from "./namespaces/WebsiteStats.js";
13
14
  import { adaptParametersForGETRequests, correctType } from "./utilities.js";
14
- export { Admin, Events, Links, Me, Pixels, Websites, WebsiteStats, Realtime, Reports, Sessions, Teams, Users, };
15
+ export { Admin, Events, Links, Me, Pixels, Websites, WebsiteStats, Realtime, Reports, Sessions, Share, Teams, Users, };
15
16
  /** If the {@link API} throws an error, it should always be an {@link APIError}! */
16
17
  export class APIError extends Error {
17
18
  message;
@@ -62,14 +63,17 @@ export class API {
62
63
  // Very likely a clone created while the original didn't have a valid token
63
64
  this.set_token_on_expires = false; // In which case allow the clone to get its own token, but not renewing it automatically
64
65
  } // And if the clone keeps getting used, `set_token_on_401` being true should cover that
65
- /** We want to set a new token instantly if account credentials have been provided */
66
- if (this.set_token_on_creation &&
67
- typeof server_or_settings === "string" &&
68
- username &&
69
- password) {
70
- this.server = server_or_settings;
66
+ if (username) {
71
67
  this.username = username;
68
+ }
69
+ if (password) {
72
70
  this.password = password;
71
+ }
72
+ if (typeof server_or_settings === "string") {
73
+ this.server = server_or_settings;
74
+ }
75
+ /** We want to set a new token instantly if account credentials have been provided */
76
+ if (this.set_token_on_creation && username && password) {
73
77
  this.setNewToken();
74
78
  }
75
79
  }
@@ -110,8 +114,12 @@ export class API {
110
114
  set token_type(token) {
111
115
  this._token_type = token;
112
116
  }
113
- _expires = new Date(new Date().getTime() + 24 * 60 * 60 * 1000); // 24 hours default, is set through setNewToken anyway
114
- /** The expiration date of your token */
117
+ _expires = null;
118
+ /**
119
+ * The expiration date of your token
120
+ * @remarks Umami v3.0.3 behaviour is to NOT expire tokens a given amount of time after creation,
121
+ * see https://github.com/umami-software/umami/discussions/1170
122
+ */
115
123
  get expires() {
116
124
  return this._expires;
117
125
  }
@@ -166,12 +174,14 @@ export class API {
166
174
  role: "view-only",
167
175
  createdAt: new Date(),
168
176
  isAdmin: false,
177
+ teams: [],
169
178
  };
170
179
  /** Information about the account that has been used to log in */
171
180
  get user() {
172
181
  return this._user;
173
182
  }
174
183
  set user(user) {
184
+ user.createdAt = new Date(user.createdAt);
175
185
  this._user = user;
176
186
  }
177
187
  number_of_requests = 0;
@@ -179,7 +189,9 @@ export class API {
179
189
  /** Has {@link API.setNewToken} been called and not yet returned anything? */
180
190
  is_setting_token = false;
181
191
  /** If {@link API.setNewToken} has been called, you can wait for it to be done through this promise */
182
- token_promise = new Promise((r) => r);
192
+ token_promise = new Promise((r) => {
193
+ r();
194
+ }); // `{r()}` over `r` prevents Node.js weirdness when awaited
183
195
  /**
184
196
  * This contacts the server in order to get and set a new {@link API.token}!
185
197
  * @remarks The API object requires a {@link API.username} and a {@link API.password} to successfully get any token
@@ -204,9 +216,10 @@ export class API {
204
216
  // Note: `json` currently only has `token` & `user`
205
217
  this.token = json.token;
206
218
  this.user = json.user;
207
- const expiration_date = new Date();
208
- expiration_date.setDate(expiration_date.getDate() + 1); // Assume 24 hours
209
- this.expires = expiration_date;
219
+ // If Umami ever sets expiration dates on tokens, the code to let the API object know should be here
220
+ // const expiration_date = new Date();
221
+ // expiration_date.setDate(expiration_date.getDate() + 1); // Assume 24 hours
222
+ // this.expires = expiration_date;
210
223
  resolve();
211
224
  });
212
225
  })
@@ -226,8 +239,8 @@ export class API {
226
239
  set set_token_on_creation(bool) {
227
240
  this._set_token_on_creation = bool;
228
241
  }
229
- _set_token_on_401 = true;
230
- /** If true, upon failing a request due to a 401, it will call {@link API.setNewToken} (defaults to **true**) */
242
+ _set_token_on_401 = false;
243
+ /** If true, upon failing a request due to a 401, it will call {@link API.setNewToken} (defaults to **false**) */
231
244
  get set_token_on_401() {
232
245
  return this._set_token_on_401;
233
246
  }
@@ -386,7 +399,9 @@ export class API {
386
399
  let error_object;
387
400
  let error_message = "no error message available";
388
401
  if (!is_token_related)
389
- await this.token_promise.catch(() => (this.token_promise = new Promise((r) => r)));
402
+ await this.token_promise.catch(() => (this.token_promise = new Promise((r) => {
403
+ r();
404
+ })));
390
405
  for (const [p, v] of Object.entries(parameters)) {
391
406
  // Convert Dates to ms
392
407
  if (typeof v === "object" && !Array.isArray(v) && v !== null) {
@@ -416,6 +431,10 @@ export class API {
416
431
  })
417
432
  .join("&");
418
433
  }
434
+ const headers = new Headers(this.headers);
435
+ if (!is_token_related) {
436
+ headers.append("Authorization", `${this.token_type} ${this.token}`);
437
+ }
419
438
  const signals = [];
420
439
  if (this.timeout > 0)
421
440
  signals.push(AbortSignal.timeout(this.timeout * 1000));
@@ -423,12 +442,7 @@ export class API {
423
442
  signals.push(this.signal);
424
443
  const response = await fetch(url, {
425
444
  method,
426
- headers: {
427
- Authorization: is_token_related
428
- ? undefined
429
- : `${this.token_type} ${this.token}`,
430
- ...this.headers,
431
- },
445
+ headers,
432
446
  body: method !== "get" ? JSON.stringify(parameters) : undefined, // parameters are here if method is NOT GET
433
447
  signal: AbortSignal.any(signals),
434
448
  })
@@ -474,6 +488,9 @@ export class API {
474
488
  if (to_retry === true && info.number_try <= this.retry_maximum_amount) {
475
489
  this.log(true, `Will request again in ${this.retry_delay} seconds...`, `(retry #${info.number_try}/${this.retry_maximum_amount})`, request_id);
476
490
  await new Promise((res) => setTimeout(res, this.retry_delay * 1000));
491
+ if (response) {
492
+ void response.text(); // Consume the response to avoid connection pool exhaustion
493
+ }
477
494
  return await this.fetch(is_token_related, method, endpoint, parameters, {
478
495
  number_try: info.number_try + 1,
479
496
  has_new_token: info.has_new_token,
@@ -500,9 +517,7 @@ export class API {
500
517
  async request(method, endpoint, parameters = {}) {
501
518
  try {
502
519
  const response = await this.fetch(false, method, endpoint, parameters);
503
- if (response.status === 204)
504
- return undefined; // 204 means the request worked as intended and did not give us anything, so just return nothing
505
- const arrBuff = await response.arrayBuffer();
520
+ const arrBuff = await response.arrayBuffer(); // note: immediately consume the response to prevent connection pool leaks
506
521
  const buff = Buffer.from(arrBuff);
507
522
  try {
508
523
  // Assume the response is in JSON format as it often is, it'll fail into the catch block if it isn't anyway
@@ -559,6 +574,8 @@ export class API {
559
574
  /** @group Links endpoints */
560
575
  getLinks = Links.get;
561
576
  /** @group Links endpoints */
577
+ createLink = Links.post;
578
+ /** @group Links endpoints */
562
579
  getLink = Links.get_LINKID;
563
580
  /** @group Links endpoints */
564
581
  updateLink = Links.post_LINKID;
@@ -572,13 +589,15 @@ export class API {
572
589
  /** @group Me endpoints */
573
590
  getMyWebsites = Me.getWebsites;
574
591
  // PIXELS
575
- /** @group Links endpoints */
592
+ /** @group Pixels endpoints */
576
593
  getPixels = Pixels.get;
577
- /** @group Links endpoints */
594
+ /** @group Pixels endpoints */
595
+ createPixel = Pixels.post;
596
+ /** @group Pixels endpoints */
578
597
  getPixel = Pixels.get_PIXELID;
579
- /** @group Links endpoints */
598
+ /** @group Pixels endpoints */
580
599
  updatePixel = Pixels.post_PIXELID;
581
- /** @group Links endpoints */
600
+ /** @group Pixels endpoints */
582
601
  deletePixel = Pixels.delete_PIXELID;
583
602
  // WEBSITES
584
603
  /** @group Websites endpoints */
@@ -653,6 +672,19 @@ export class API {
653
672
  getWebsiteSessionDataProperties = Sessions.get_WEBSITEID_SessiondataProperties;
654
673
  /** @group Sessions endpoints */
655
674
  getWebsiteSessionDataValues = Sessions.get_WEBSITEID_SessiondataValues;
675
+ // SHARE
676
+ /** @group Share endpoints */
677
+ createShare = Share.post;
678
+ /** @group Share endpoints */
679
+ getShare = Share.get_SHAREID;
680
+ /** @group Share endpoints */
681
+ updateShare = Share.post_SHAREID;
682
+ /** @group Share endpoints */
683
+ deleteShare = Share.delete_SHAREID;
684
+ /** @group Share endpoints */
685
+ getWebsiteShares = Share.get_WEBSITEID_Shares;
686
+ /** @group Share endpoints */
687
+ createWebsiteShare = Share.post_WEBSITEID_Shares;
656
688
  // TEAMS
657
689
  /** @group Teams endpoints */
658
690
  getTeams = Teams.get;
@@ -1,4 +1,4 @@
1
- import { API, DeletionResult, GenericRequestParameters, Users } from "../index.js";
1
+ import { API, DeletionResult, GenericRequestParameters, Teams, Users } from "../index.js";
2
2
  /** Operations around Links management: https://umami.is/docs/api/links */
3
3
  export declare namespace Links {
4
4
  interface Link {
@@ -14,6 +14,17 @@ export declare namespace Links {
14
14
  }
15
15
  /** Returns all user links: https://umami.is/docs/api/links#get-apilinks */
16
16
  function get(this: API, parameters?: GenericRequestParameters): Promise<Link[]>;
17
+ /** Creates a link: https://docs.umami.is/docs/api/links#post-apilinks */
18
+ function post(this: API, parameters: {
19
+ /** The link's name */
20
+ name: Link["name"];
21
+ /** The link's destination URL */
22
+ url: Link["url"];
23
+ /** The link's URL slug, **with a minimum of 8 characters** */
24
+ slug: Link["slug"];
25
+ /** The ID of the team the link will be created under */
26
+ teamId?: Teams.Team["id"];
27
+ }): Promise<Link>;
17
28
  /** Gets a link by ID: https://umami.is/docs/api/links#get-apilinkslinkid */
18
29
  function get_LINKID(this: API, linkId: Link["id"]): Promise<Link>;
19
30
  /** Updates a link: https://umami.is/docs/api/links#post-apilinkslinkid */
@@ -7,6 +7,11 @@ export var Links;
7
7
  return response.data;
8
8
  }
9
9
  Links.get = get;
10
+ /** Creates a link: https://docs.umami.is/docs/api/links#post-apilinks */
11
+ async function post(parameters) {
12
+ return await this.request("post", ["links"], parameters);
13
+ }
14
+ Links.post = post;
10
15
  /** Gets a link by ID: https://umami.is/docs/api/links#get-apilinkslinkid */
11
16
  async function get_LINKID(linkId) {
12
17
  return await this.request("get", ["links", linkId]);
@@ -1,4 +1,4 @@
1
- import { API, DeletionResult, GenericRequestParameters, Users } from "../index.js";
1
+ import { API, DeletionResult, GenericRequestParameters, Teams, Users } from "../index.js";
2
2
  /** Operations around Pixels management: https://umami.is/docs/api/pixels */
3
3
  export declare namespace Pixels {
4
4
  interface Pixel {
@@ -13,6 +13,15 @@ export declare namespace Pixels {
13
13
  }
14
14
  /** Returns all user pixels: https://umami.is/docs/api/pixels#get-apipixels */
15
15
  function get(this: API, parameters?: GenericRequestParameters): Promise<Pixel[]>;
16
+ /** Creates a pixel: https://docs.umami.is/docs/api/pixels#post-apipixels */
17
+ function post(this: API, parameters: {
18
+ /** The pixel's name */
19
+ name: Pixel["name"];
20
+ /** The pixel's URL slug, **with a minimum of 8 characters** */
21
+ slug: Pixel["slug"];
22
+ /** The ID of the team the pixel will be created under */
23
+ teamId?: Teams.Team["id"];
24
+ }): Promise<Pixel>;
16
25
  /** Gets a pixel by ID: https://umami.is/docs/api/pixels#get-apipixelspixelid */
17
26
  function get_PIXELID(this: API, pixelId: Pixel["id"]): Promise<Pixel>;
18
27
  /** Updates a pixel: https://umami.is/docs/api/pixels#post-apipixelspixelid */
@@ -7,6 +7,11 @@ export var Pixels;
7
7
  return response.data;
8
8
  }
9
9
  Pixels.get = get;
10
+ /** Creates a pixel: https://docs.umami.is/docs/api/pixels#post-apipixels */
11
+ async function post(parameters) {
12
+ return await this.request("post", ["pixels"], parameters);
13
+ }
14
+ Pixels.post = post;
10
15
  /** Gets a pixel by ID: https://umami.is/docs/api/pixels#get-apipixelspixelid */
11
16
  async function get_PIXELID(pixelId) {
12
17
  return await this.request("get", ["pixels", pixelId]);
@@ -0,0 +1,70 @@
1
+ import { API, DeletionResult, Websites } from "../index.js";
2
+ /** Operations around Share page management: https://docs.umami.is/docs/api/share */
3
+ export declare namespace Share {
4
+ enum ShareType {
5
+ website = 1,
6
+ link = 2,
7
+ pixel = 3,
8
+ board = 4
9
+ }
10
+ interface Share {
11
+ id: string;
12
+ entityId: string;
13
+ name: string;
14
+ shareType: ShareType;
15
+ slug: string;
16
+ parameters: Parameters;
17
+ createdAt: Date;
18
+ updatedAt: Date;
19
+ }
20
+ interface Parameters {
21
+ overview?: boolean;
22
+ events?: boolean;
23
+ sessions?: boolean;
24
+ realtime?: boolean;
25
+ performance?: boolean;
26
+ compare?: boolean;
27
+ breakdown?: boolean;
28
+ goals?: boolean;
29
+ funnels?: boolean;
30
+ journeys?: boolean;
31
+ retention?: boolean;
32
+ utm?: boolean;
33
+ revenue?: boolean;
34
+ attribution?: boolean;
35
+ }
36
+ /** Creates a share page: https://docs.umami.is/docs/api/share#post-apishare */
37
+ function post(this: API, parameters: {
38
+ /** ID of entity to be added (websiteId, pixelId, linkId, etc.) */
39
+ entityId: Share["entityId"];
40
+ shareType: ShareType;
41
+ /** Name of the share page */
42
+ name: Share["name"];
43
+ /** Slug of the share page */
44
+ slug: Share["slug"];
45
+ /** Parameters for share page */
46
+ parameters: Parameters;
47
+ }): Promise<Share>;
48
+ /** Gets a share page by ID: https://docs.umami.is/docs/api/share#get-apishareidshareid */
49
+ function get_SHAREID(this: API, share_id: Share["id"]): Promise<Share>;
50
+ /** Updates a share page: https://docs.umami.is/docs/api/share#post-apishareidshareid */
51
+ function post_SHAREID(this: API, share_id: Share["id"], parameters: {
52
+ /** Name of the share page */
53
+ name: Share["name"];
54
+ /** Slug of the share page */
55
+ slug: Share["slug"];
56
+ /** Parameters for share page */
57
+ parameters: Parameters;
58
+ }): Promise<Share>;
59
+ /** Deletes a share page: https://docs.umami.is/docs/api/share#delete-apishareidshareid */
60
+ function delete_SHAREID(this: API, share_id: Share["id"]): Promise<DeletionResult>;
61
+ /** Gets all share pages that belong to a website: https://docs.umami.is/docs/api/share#get-apiwebsiteswebsiteidshares */
62
+ function get_WEBSITEID_Shares(this: API, website_id: Websites.Website["id"]): Promise<Share[]>;
63
+ /** Creates a share page belonging to a website: https://docs.umami.is/docs/api/share#post-apiwebsiteswebsiteidshares */
64
+ function post_WEBSITEID_Shares(this: API, website_id: Websites.Website["id"], parameters: {
65
+ /** Name of the share page */
66
+ name: Share["name"];
67
+ /** Parameters for share page */
68
+ parameters: Parameters;
69
+ }): Promise<Share>;
70
+ }
@@ -0,0 +1,46 @@
1
+ /** Operations around Share page management: https://docs.umami.is/docs/api/share */
2
+ export var Share;
3
+ (function (Share) {
4
+ let ShareType;
5
+ (function (ShareType) {
6
+ ShareType[ShareType["website"] = 1] = "website";
7
+ ShareType[ShareType["link"] = 2] = "link";
8
+ ShareType[ShareType["pixel"] = 3] = "pixel";
9
+ ShareType[ShareType["board"] = 4] = "board";
10
+ })(ShareType = Share.ShareType || (Share.ShareType = {}));
11
+ /** Creates a share page: https://docs.umami.is/docs/api/share#post-apishare */
12
+ async function post(parameters) {
13
+ return await this.request("post", ["share"], parameters);
14
+ }
15
+ Share.post = post;
16
+ /** Gets a share page by ID: https://docs.umami.is/docs/api/share#get-apishareidshareid */
17
+ async function get_SHAREID(share_id) {
18
+ return await this.request("get", ["share", "id", share_id]);
19
+ }
20
+ Share.get_SHAREID = get_SHAREID;
21
+ /** Updates a share page: https://docs.umami.is/docs/api/share#post-apishareidshareid */
22
+ async function post_SHAREID(share_id, parameters) {
23
+ return await this.request("post", ["share", "id", share_id], parameters);
24
+ }
25
+ Share.post_SHAREID = post_SHAREID;
26
+ /** Deletes a share page: https://docs.umami.is/docs/api/share#delete-apishareidshareid */
27
+ async function delete_SHAREID(share_id) {
28
+ return await this.request("delete", ["share", "id", share_id]);
29
+ }
30
+ Share.delete_SHAREID = delete_SHAREID;
31
+ /** Gets all share pages that belong to a website: https://docs.umami.is/docs/api/share#get-apiwebsiteswebsiteidshares */
32
+ async function get_WEBSITEID_Shares(website_id) {
33
+ const response = await this.request("get", [
34
+ "websites",
35
+ website_id,
36
+ "shares",
37
+ ]);
38
+ return response.data;
39
+ }
40
+ Share.get_WEBSITEID_Shares = get_WEBSITEID_Shares;
41
+ /** Creates a share page belonging to a website: https://docs.umami.is/docs/api/share#post-apiwebsiteswebsiteidshares */
42
+ async function post_WEBSITEID_Shares(website_id, parameters) {
43
+ return await this.request("post", ["websites", website_id, "shares"], parameters);
44
+ }
45
+ Share.post_WEBSITEID_Shares = post_WEBSITEID_Shares;
46
+ })(Share || (Share = {}));
@@ -1,11 +1,13 @@
1
1
  import { API, DeletionResult, GenericRequestParameters, Users, Websites } from "../index.js";
2
2
  /** Operations around Team management: https://umami.is/docs/api/teams */
3
3
  export declare namespace Teams {
4
- interface Team {
4
+ interface MinimalTeam {
5
5
  id: string;
6
6
  name: string;
7
- accessCode: string;
8
7
  logoUrl: string | null;
8
+ }
9
+ interface Team extends MinimalTeam {
10
+ accessCode: string;
9
11
  createdAt: Date;
10
12
  updatedAt: Date;
11
13
  deletedAt: Date | null;
@@ -9,15 +9,16 @@ export declare namespace Users {
9
9
  interface MinimalUserWithRole extends MinimalUser {
10
10
  role: Role;
11
11
  }
12
- interface MinimalUserWithCreatedAt extends MinimalUserWithRole {
12
+ interface MinimalUserWithRoleCreatedAt extends MinimalUserWithRole {
13
13
  createdAt: Date;
14
14
  }
15
- interface MinimalUserWithRoleCreatedAt extends MinimalUserWithRole, MinimalUserWithCreatedAt {
16
- }
17
15
  interface User extends MinimalUserWithRoleCreatedAt {
18
16
  isAdmin: boolean;
19
17
  }
20
- interface DetailedUser extends MinimalUserWithRole, MinimalUserWithCreatedAt {
18
+ interface UserWithTeams extends User {
19
+ teams: Teams.MinimalTeam[];
20
+ }
21
+ interface DetailedUser extends MinimalUserWithRoleCreatedAt {
21
22
  logoUrl: string | null;
22
23
  displayName: string | null;
23
24
  updatedAt: Date;
@@ -1,11 +1,11 @@
1
- import { API, DeletionResult, GenericRequestParameters, Teams, Users } from "../index.js";
1
+ import { API, DeletionResult, GenericRequestParameters, Share, Teams, Users } from "../index.js";
2
2
  /** Operations around Website management and statistics: https://umami.is/docs/api/websites */
3
3
  export declare namespace Websites {
4
4
  interface Website {
5
5
  id: string;
6
6
  name: string;
7
7
  domain: string;
8
- shareId: string | null;
8
+ shareId: Share.Share["id"] | null;
9
9
  resetAt: Date | null;
10
10
  /** @remarks Is null if the website is under a team (has a `teamId`) */
11
11
  userId: Users.User["id"] | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "umami-api-js",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Package to easily access the Umami api!",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -31,13 +31,13 @@
31
31
  "license": "Unlicense",
32
32
  "devDependencies": {
33
33
  "@types/chai": "^5.2.3",
34
- "@types/node": "^24.9.2",
35
- "ajv": "^8.17.1",
34
+ "@types/node": "^25.6.0",
35
+ "ajv": "^8.20.0",
36
36
  "chai": "^6.2.2",
37
- "dotenv": "^17.2.3",
38
- "prettier": "3.8.1",
39
- "ts-json-schema-generator": "^2.4.0",
40
- "typedoc": "^0.28.16",
41
- "typescript": "^5.9.3"
37
+ "dotenv": "^17.4.2",
38
+ "prettier": "3.8.3",
39
+ "ts-json-schema-generator": "^2.9.0",
40
+ "typedoc": "^0.28.19",
41
+ "typescript": "^6.0.3"
42
42
  }
43
43
  }