11import { createSecureToken , hash , get , post , put , del , buildUrl , ApiResponse } from 'next-basics' ;
22import * as Umami from './types' ;
33import { log } from 'utils' ;
4+ import { FilterResult } from './types' ;
45
56export const API_KEY_HEADER = 'x-umami-api-key' ;
67
@@ -47,31 +48,31 @@ export class UmamiApiClient {
4748 get ( url : string , params ?: object , headers ?: object ) {
4849 const dest = buildUrl ( `${ this . apiEndpoint } /${ url } ` , params ) ;
4950
50- log ( `GET ${ dest } ` ) ;
51+ log ( `GET ${ dest } ` , params , headers ) ;
5152
5253 return get ( dest , undefined , this . getHeaders ( headers ) ) ;
5354 }
5455
5556 post ( url : string , params ?: object , headers ?: object ) {
5657 const dest = `${ this . apiEndpoint } /${ url } ` ;
5758
58- log ( `POST ${ dest } ` ) ;
59+ log ( `POST ${ dest } ` , params , headers ) ;
5960
6061 return post ( dest , params , this . getHeaders ( headers ) ) ;
6162 }
6263
6364 put ( url : string , params ?: object , headers ?: object ) {
6465 const dest = `${ this . apiEndpoint } /${ url } ` ;
6566
66- log ( `PUT ${ dest } ` ) ;
67+ log ( `PUT ${ dest } ` , params , headers ) ;
6768
6869 return put ( dest , params , this . getHeaders ( headers ) ) ;
6970 }
7071
7172 del ( url : string , params ?: object , headers ?: object ) {
7273 const dest = buildUrl ( `${ this . apiEndpoint } /${ url } ` , params ) ;
7374
74- log ( `DELETE ${ dest } ` ) ;
75+ log ( `DELETE ${ dest } ` , params , headers ) ;
7576
7677 return del ( dest , undefined , this . getHeaders ( headers ) ) ;
7778 }
@@ -84,8 +85,8 @@ export class UmamiApiClient {
8485 return this . get ( `users/${ userId } ` ) ;
8586 }
8687
87- async getUsers ( ) : Promise < ApiResponse < Umami . User [ ] > > {
88- return this . get ( `users` ) ;
88+ async getUsers ( params : Umami . UserSearchFilter ) : Promise < ApiResponse < FilterResult < Umami . User [ ] > > > {
89+ return this . get ( `users` , params ) ;
8990 }
9091
9192 async getUserUsage (
@@ -98,8 +99,11 @@ export class UmamiApiClient {
9899 return this . get ( `users/${ userId } /usage` , params ) ;
99100 }
100101
101- async getUserWebsites ( userId : string ) : Promise < ApiResponse < Umami . User [ ] > > {
102- return this . get ( `users/${ userId } /websites` ) ;
102+ async getUserWebsites (
103+ userId : string ,
104+ params : Umami . WebsiteSearchFilter ,
105+ ) : Promise < ApiResponse < FilterResult < Umami . User [ ] > > > {
106+ return this . get ( `users/${ userId } /websites` , params ) ;
103107 }
104108
105109 async deleteUser ( userId : string ) : Promise < ApiResponse < Umami . Empty > > {
@@ -144,8 +148,10 @@ export class UmamiApiClient {
144148 return this . post ( `websites/${ websiteId } /reset` ) ;
145149 }
146150
147- async getWebsites ( ) : Promise < ApiResponse < Umami . Website [ ] > > {
148- return this . get ( `websites` ) ;
151+ async getWebsites (
152+ params ?: Umami . WebsiteSearchFilter ,
153+ ) : Promise < ApiResponse < FilterResult < Umami . Website [ ] > > > {
154+ return this . get ( `websites` , params ) ;
149155 }
150156
151157 async getWebsiteActive ( websiteId : string ) : Promise < ApiResponse < Umami . WebsiteActive [ ] > > {
@@ -260,24 +266,30 @@ export class UmamiApiClient {
260266 return this . get ( `teams/${ teamId } ` ) ;
261267 }
262268
263- async getTeams ( ) : Promise < ApiResponse < Umami . Team [ ] > > {
264- return this . get ( `teams` ) ;
269+ async getTeams ( params ?: Umami . TeamSearchFilter ) : Promise < ApiResponse < Umami . Team [ ] > > {
270+ return this . get ( `teams` , params ) ;
265271 }
266272
267273 async joinTeam ( data : { accessCode : string } ) : Promise < ApiResponse < Umami . Team > > {
268274 return this . post ( `teams/join` , data ) ;
269275 }
270276
271- async getTeamUsers ( teamId : string ) : Promise < ApiResponse < Umami . User [ ] > > {
272- return this . get ( `teams/${ teamId } /users` ) ;
277+ async getTeamUsers (
278+ teamId : string ,
279+ params ?: Umami . UserSearchFilter ,
280+ ) : Promise < ApiResponse < FilterResult < FilterResult < Umami . User [ ] > > > > {
281+ return this . get ( `teams/${ teamId } /users` , params ) ;
273282 }
274283
275284 async deleteTeamUser ( teamId : string , userId : string ) : Promise < ApiResponse < Umami . Empty > > {
276285 return this . del ( `teams/${ teamId } /users/${ userId } ` ) ;
277286 }
278287
279- async getTeamWebsites ( teamId : string ) : Promise < ApiResponse < Umami . Website [ ] > > {
280- return this . get ( `teams/${ teamId } /websites` ) ;
288+ async getTeamWebsites (
289+ teamId : string ,
290+ params ?: Umami . WebsiteSearchFilter ,
291+ ) : Promise < ApiResponse < FilterResult < FilterResult < Umami . Website [ ] > > > > {
292+ return this . get ( `teams/${ teamId } /websites` , params ) ;
281293 }
282294
283295 async createTeamWebsites (
@@ -318,8 +330,12 @@ export class UmamiApiClient {
318330 return this . get ( 'me' ) ;
319331 }
320332
321- async getMyWebsites ( ) {
322- return this . post ( 'me/websites' ) ;
333+ async getMyWebsites ( params ?: Umami . WebsiteSearchFilter ) {
334+ return this . get ( 'me/websites' , params ) ;
335+ }
336+
337+ async getMyTeams ( params ?: Umami . TeamSearchFilter ) {
338+ return this . get ( 'me/teams' , params ) ;
323339 }
324340
325341 async updateMyPassword ( data : { currentPassword : string ; newPassword : string } ) {
0 commit comments