@taruvi/sdk 1.0.8 → 1.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taruvi/sdk",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Taruvi SDK",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -1,24 +1,50 @@
1
- import type { Client } from "../../client.js"
1
+ import type { Client } from "../../client.js";
2
+ import { AppRoutes, type AppRouteKey } from "../../lib-internal/routes/AppRoutes.js";
3
+ import { HttpMethod } from "../../lib-internal/http/types.js";
4
+ import type { TaruviConfig } from "../../types.js";
5
+ import type { UrlParams } from "./types.js";
2
6
 
3
7
  export class App {
4
-
5
8
  private client: Client
6
- private urlParams: {}
9
+ private urlParams: UrlParams
10
+ private config: TaruviConfig
11
+ private operation: HttpMethod | undefined
7
12
 
8
- constructor(client: Client, urlParams: {}, filters?: {}) {
13
+ constructor(client: Client, urlParams: UrlParams = {}, operation?: HttpMethod | undefined) {
9
14
  this.client = client
10
15
  this.urlParams = urlParams
16
+ this.operation = operation
17
+ this.config = this.client.getConfig()
11
18
  }
12
19
 
13
20
  roles() {
14
- return new App(this.client, {...this.urlParams})
21
+ return new App(this.client, { ...this.urlParams, roles: "roles" }, HttpMethod.GET)
15
22
  }
16
23
 
17
- filter(filters: {}) {
18
- return new App(this.client, { ...this.urlParams }, filters)
24
+ private buildRoute(): string {
25
+ return (
26
+ AppRoutes.baseUrl(this.config.appSlug) +
27
+ (Object.keys(this.urlParams) as AppRouteKey[]).reduce((acc, key) => {
28
+ const value = this.urlParams[key]
29
+ const routeBuilder = AppRoutes[key]
30
+
31
+ if (value && routeBuilder) {
32
+ acc += routeBuilder()
33
+ }
34
+
35
+ return acc
36
+ }, "")
37
+ )
19
38
  }
20
39
 
21
- execute() {
22
-
40
+ async execute() {
41
+ const url = this.buildRoute()
42
+ const operation = this.operation || HttpMethod.GET
43
+
44
+ switch (operation) {
45
+ case HttpMethod.GET:
46
+ default:
47
+ return await this.client.httpClient.get(url)
48
+ }
23
49
  }
24
50
  }
@@ -0,0 +1,25 @@
1
+ import type { Client } from "../../client.js"
2
+ import { HttpMethod } from "../../lib-internal/http/types.js"
3
+
4
+ export type AppOperation = HttpMethod
5
+
6
+ // Internal types
7
+ export interface UrlParams {
8
+ appSlug?: string
9
+ roles?: string
10
+ }
11
+
12
+ export interface AppClientInterface {
13
+ client: Client
14
+ urlParams?: UrlParams
15
+ }
16
+
17
+ // Response types
18
+ export interface RoleResponse {
19
+ id?: string | number
20
+ name?: string
21
+ permissions?: string[]
22
+ created_at?: string
23
+ updated_at?: string
24
+ [key: string]: unknown
25
+ }
@@ -1,5 +1,5 @@
1
1
  import type { Client } from "../../client.js";
2
- import type { UserCreateRequest, UserCreateResponse, UserDataResponse, UserList, UserUpdateRequest } from "./types.js";
2
+ import type { UserCreateRequest, UserCreateResponse, UserDataResponse, UserList, UserUpdateRequest, UserAppsResponse } from "./types.js";
3
3
  import { UserRoutes } from "../../lib-internal/routes/UserRoutes.js";
4
4
  import { buildQueryString } from "../../utils/utils.js";
5
5
 
@@ -26,6 +26,10 @@ export class User {
26
26
  return await this.client.httpClient.get(UserRoutes.listUser(queryString))
27
27
  }
28
28
 
29
+ async getUserApps(username: string): Promise<UserAppsResponse> {
30
+ return await this.client.httpClient.get<UserAppsResponse>(UserRoutes.getUserApps(username))
31
+ }
32
+
29
33
  // - createUser
30
34
  async createUser(userData: UserCreateRequest): Promise<UserCreateResponse> {
31
35
  return await this.client.httpClient.post<UserCreateResponse, UserCreateRequest>(
@@ -66,4 +66,14 @@ export interface UserList {
66
66
  ordering: string
67
67
  page: Number
68
68
  page_size: Number
69
- }
69
+ }
70
+
71
+ export interface UserApp {
72
+ name: string
73
+ slug: string
74
+ icon: string
75
+ url: string
76
+ display_name: string
77
+ }
78
+
79
+ export type UserAppsResponse = UserApp[]
@@ -0,0 +1,8 @@
1
+ export const AppRoutes = {
2
+ baseUrl: (appSlug: string) => `api/app/${appSlug}`,
3
+ roles: (): string => `/roles`
4
+ }
5
+
6
+ type AllRouteKeys = keyof typeof AppRoutes
7
+ export type AppRouteKey = Exclude<AllRouteKeys, 'baseUrl'>
8
+ export type AppUrlParams = Partial<Record<AppRouteKey, string>>
@@ -5,5 +5,6 @@ export const UserRoutes = {
5
5
  getCurrentUser: () => `${UserRoutes.baseUrl}me/`,
6
6
  updateUser: (username: string) => `${UserRoutes.baseUrl}${username}/`,
7
7
  deleteUser: (username: string) => `${UserRoutes.baseUrl}${username}/`,
8
- listUser: (filter: string) => `${UserRoutes.baseUrl}${filter}`
8
+ listUser: (filter: string) => `${UserRoutes.baseUrl}${filter}`,
9
+ getUserApps: (username: string) => `${UserRoutes.baseUrl}${username}/apps/`
9
10
  } as const