umami-api-js 1.0.1 → 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/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
  }
@@ -157,8 +158,8 @@ export declare class API {
157
158
  });
158
159
  private _user;
159
160
  /** Information about the account that has been used to log in */
160
- get user(): Users.User;
161
- set user(user: Users.User);
161
+ get user(): Users.UserWithTeams;
162
+ set user(user: Users.UserWithTeams);
162
163
  private number_of_requests;
163
164
  /** Has {@link API.setNewToken} been called and not yet returned anything? */
164
165
  private is_setting_token;
@@ -192,8 +193,8 @@ export declare class API {
192
193
  private updateTokenTimer;
193
194
  private _verbose?;
194
195
  /** Which events should be logged (defaults to **none**) */
195
- get verbose(): "none" | "errors" | "all" | undefined;
196
- set verbose(verbose: "none" | "errors" | "all" | undefined);
196
+ get verbose(): "all" | "none" | "errors" | undefined;
197
+ set verbose(verbose: "all" | "none" | "errors" | undefined);
197
198
  private _timeout;
198
199
  /**
199
200
  * The maximum **amount of seconds** requests should take before returning an answer (defaults to **20**)
@@ -309,6 +310,8 @@ export declare class API {
309
310
  /** @group Links endpoints */
310
311
  readonly getLinks: typeof Links.get;
311
312
  /** @group Links endpoints */
313
+ readonly createLink: typeof Links.post;
314
+ /** @group Links endpoints */
312
315
  readonly getLink: typeof Links.get_LINKID;
313
316
  /** @group Links endpoints */
314
317
  readonly updateLink: typeof Links.post_LINKID;
@@ -320,13 +323,15 @@ export declare class API {
320
323
  readonly getMyTeams: typeof Me.getTeams;
321
324
  /** @group Me endpoints */
322
325
  readonly getMyWebsites: typeof Me.getWebsites;
323
- /** @group Links endpoints */
326
+ /** @group Pixels endpoints */
324
327
  readonly getPixels: typeof Pixels.get;
325
- /** @group Links endpoints */
328
+ /** @group Pixels endpoints */
329
+ readonly createPixel: typeof Pixels.post;
330
+ /** @group Pixels endpoints */
326
331
  readonly getPixel: typeof Pixels.get_PIXELID;
327
- /** @group Links endpoints */
332
+ /** @group Pixels endpoints */
328
333
  readonly updatePixel: typeof Pixels.post_PIXELID;
329
- /** @group Links endpoints */
334
+ /** @group Pixels endpoints */
330
335
  readonly deletePixel: typeof Pixels.delete_PIXELID;
331
336
  /** @group Websites endpoints */
332
337
  readonly getWebsites: typeof Websites.get;
@@ -396,6 +401,18 @@ export declare class API {
396
401
  readonly getWebsiteSessionDataProperties: typeof Sessions.get_WEBSITEID_SessiondataProperties;
397
402
  /** @group Sessions endpoints */
398
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;
399
416
  /** @group Teams endpoints */
400
417
  readonly getTeams: typeof Teams.get;
401
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;
@@ -173,12 +174,14 @@ export class API {
173
174
  role: "view-only",
174
175
  createdAt: new Date(),
175
176
  isAdmin: false,
177
+ teams: [],
176
178
  };
177
179
  /** Information about the account that has been used to log in */
178
180
  get user() {
179
181
  return this._user;
180
182
  }
181
183
  set user(user) {
184
+ user.createdAt = new Date(user.createdAt);
182
185
  this._user = user;
183
186
  }
184
187
  number_of_requests = 0;
@@ -428,6 +431,10 @@ export class API {
428
431
  })
429
432
  .join("&");
430
433
  }
434
+ const headers = new Headers(this.headers);
435
+ if (!is_token_related) {
436
+ headers.append("Authorization", `${this.token_type} ${this.token}`);
437
+ }
431
438
  const signals = [];
432
439
  if (this.timeout > 0)
433
440
  signals.push(AbortSignal.timeout(this.timeout * 1000));
@@ -435,12 +442,7 @@ export class API {
435
442
  signals.push(this.signal);
436
443
  const response = await fetch(url, {
437
444
  method,
438
- headers: {
439
- Authorization: is_token_related
440
- ? undefined
441
- : `${this.token_type} ${this.token}`,
442
- ...this.headers,
443
- },
445
+ headers,
444
446
  body: method !== "get" ? JSON.stringify(parameters) : undefined, // parameters are here if method is NOT GET
445
447
  signal: AbortSignal.any(signals),
446
448
  })
@@ -486,6 +488,9 @@ export class API {
486
488
  if (to_retry === true && info.number_try <= this.retry_maximum_amount) {
487
489
  this.log(true, `Will request again in ${this.retry_delay} seconds...`, `(retry #${info.number_try}/${this.retry_maximum_amount})`, request_id);
488
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
+ }
489
494
  return await this.fetch(is_token_related, method, endpoint, parameters, {
490
495
  number_try: info.number_try + 1,
491
496
  has_new_token: info.has_new_token,
@@ -512,9 +517,7 @@ export class API {
512
517
  async request(method, endpoint, parameters = {}) {
513
518
  try {
514
519
  const response = await this.fetch(false, method, endpoint, parameters);
515
- if (response.status === 204)
516
- return undefined; // 204 means the request worked as intended and did not give us anything, so just return nothing
517
- const arrBuff = await response.arrayBuffer();
520
+ const arrBuff = await response.arrayBuffer(); // note: immediately consume the response to prevent connection pool leaks
518
521
  const buff = Buffer.from(arrBuff);
519
522
  try {
520
523
  // Assume the response is in JSON format as it often is, it'll fail into the catch block if it isn't anyway
@@ -571,6 +574,8 @@ export class API {
571
574
  /** @group Links endpoints */
572
575
  getLinks = Links.get;
573
576
  /** @group Links endpoints */
577
+ createLink = Links.post;
578
+ /** @group Links endpoints */
574
579
  getLink = Links.get_LINKID;
575
580
  /** @group Links endpoints */
576
581
  updateLink = Links.post_LINKID;
@@ -584,13 +589,15 @@ export class API {
584
589
  /** @group Me endpoints */
585
590
  getMyWebsites = Me.getWebsites;
586
591
  // PIXELS
587
- /** @group Links endpoints */
592
+ /** @group Pixels endpoints */
588
593
  getPixels = Pixels.get;
589
- /** @group Links endpoints */
594
+ /** @group Pixels endpoints */
595
+ createPixel = Pixels.post;
596
+ /** @group Pixels endpoints */
590
597
  getPixel = Pixels.get_PIXELID;
591
- /** @group Links endpoints */
598
+ /** @group Pixels endpoints */
592
599
  updatePixel = Pixels.post_PIXELID;
593
- /** @group Links endpoints */
600
+ /** @group Pixels endpoints */
594
601
  deletePixel = Pixels.delete_PIXELID;
595
602
  // WEBSITES
596
603
  /** @group Websites endpoints */
@@ -665,6 +672,19 @@ export class API {
665
672
  getWebsiteSessionDataProperties = Sessions.get_WEBSITEID_SessiondataProperties;
666
673
  /** @group Sessions endpoints */
667
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;
668
688
  // TEAMS
669
689
  /** @group Teams endpoints */
670
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.1",
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.18.0",
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.17",
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
  }