@taruvi/sdk 1.5.0 → 1.5.1-beta.4

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.
Files changed (231) hide show
  1. package/README.md +60 -1289
  2. package/dist/client.d.ts +27 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/{src/client.ts → dist/client.js} +30 -48
  5. package/dist/client.js.map +1 -0
  6. package/dist/index.d.ts +28 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +20 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/lib/analytics/AnalyticsClient.d.ts +9 -0
  11. package/dist/lib/analytics/AnalyticsClient.d.ts.map +1 -0
  12. package/dist/lib/analytics/AnalyticsClient.js +17 -0
  13. package/dist/lib/analytics/AnalyticsClient.js.map +1 -0
  14. package/dist/lib/analytics/types.d.ts +6 -0
  15. package/dist/lib/analytics/types.d.ts.map +1 -0
  16. package/dist/lib/analytics/types.js +2 -0
  17. package/dist/lib/analytics/types.js.map +1 -0
  18. package/dist/lib/app/AppClient.d.ts +15 -0
  19. package/dist/lib/app/AppClient.d.ts.map +1 -0
  20. package/dist/lib/app/AppClient.js +41 -0
  21. package/dist/lib/app/AppClient.js.map +1 -0
  22. package/dist/lib/app/types.d.ts +41 -0
  23. package/dist/lib/app/types.d.ts.map +1 -0
  24. package/dist/lib/app/types.js +2 -0
  25. package/dist/lib/app/types.js.map +1 -0
  26. package/dist/lib/auth/AuthClient.d.ts +38 -0
  27. package/dist/lib/auth/AuthClient.d.ts.map +1 -0
  28. package/dist/lib/auth/AuthClient.js +105 -0
  29. package/dist/lib/auth/AuthClient.js.map +1 -0
  30. package/dist/lib/database/DatabaseClient.d.ts +76 -0
  31. package/dist/lib/database/DatabaseClient.d.ts.map +1 -0
  32. package/dist/lib/database/DatabaseClient.js +250 -0
  33. package/dist/lib/database/DatabaseClient.js.map +1 -0
  34. package/dist/lib/database/types.d.ts +66 -0
  35. package/dist/lib/database/types.d.ts.map +1 -0
  36. package/dist/lib/database/types.js +20 -0
  37. package/dist/lib/database/types.js.map +1 -0
  38. package/dist/lib/functions/FunctionsClient.d.ts +9 -0
  39. package/dist/lib/functions/FunctionsClient.d.ts.map +1 -0
  40. package/dist/lib/functions/FunctionsClient.js +20 -0
  41. package/dist/lib/functions/FunctionsClient.js.map +1 -0
  42. package/dist/lib/functions/types.d.ts +25 -0
  43. package/dist/lib/functions/types.d.ts.map +1 -0
  44. package/dist/lib/functions/types.js +2 -0
  45. package/dist/lib/functions/types.js.map +1 -0
  46. package/dist/lib/policy/PolicyClient.d.ts +25 -0
  47. package/dist/lib/policy/PolicyClient.d.ts.map +1 -0
  48. package/{src/lib/policy/PolicyClient.ts → dist/lib/policy/PolicyClient.js} +26 -40
  49. package/dist/lib/policy/PolicyClient.js.map +1 -0
  50. package/dist/lib/policy/types.d.ts +32 -0
  51. package/dist/lib/policy/types.d.ts.map +1 -0
  52. package/dist/lib/policy/types.js +2 -0
  53. package/dist/lib/policy/types.js.map +1 -0
  54. package/dist/lib/secrets/SecretsClient.d.ts +29 -0
  55. package/dist/lib/secrets/SecretsClient.d.ts.map +1 -0
  56. package/dist/lib/secrets/SecretsClient.js +66 -0
  57. package/dist/lib/secrets/SecretsClient.js.map +1 -0
  58. package/dist/lib/secrets/types.d.ts +43 -0
  59. package/dist/lib/secrets/types.d.ts.map +1 -0
  60. package/dist/lib/secrets/types.js +2 -0
  61. package/dist/lib/secrets/types.js.map +1 -0
  62. package/dist/lib/settings/SettingsClient.d.ts +9 -0
  63. package/dist/lib/settings/SettingsClient.d.ts.map +1 -0
  64. package/dist/lib/settings/SettingsClient.js +17 -0
  65. package/dist/lib/settings/SettingsClient.js.map +1 -0
  66. package/dist/lib/settings/types.d.ts +6 -0
  67. package/dist/lib/settings/types.d.ts.map +1 -0
  68. package/dist/lib/settings/types.js +2 -0
  69. package/dist/lib/settings/types.js.map +1 -0
  70. package/dist/lib/storage/StorageClient.d.ts +38 -0
  71. package/dist/lib/storage/StorageClient.d.ts.map +1 -0
  72. package/dist/lib/storage/StorageClient.js +102 -0
  73. package/dist/lib/storage/StorageClient.js.map +1 -0
  74. package/dist/lib/storage/types.d.ts +73 -0
  75. package/dist/lib/storage/types.d.ts.map +1 -0
  76. package/dist/lib/storage/types.js +2 -0
  77. package/dist/lib/storage/types.js.map +1 -0
  78. package/dist/lib/users/UserClient.d.ts +17 -0
  79. package/dist/lib/users/UserClient.d.ts.map +1 -0
  80. package/dist/lib/users/UserClient.js +40 -0
  81. package/dist/lib/users/UserClient.js.map +1 -0
  82. package/dist/lib/users/types.d.ts +108 -0
  83. package/dist/lib/users/types.d.ts.map +1 -0
  84. package/dist/lib/users/types.js +2 -0
  85. package/dist/lib/users/types.js.map +1 -0
  86. package/dist/lib-internal/errors/ErrorClient.d.ts +42 -0
  87. package/dist/lib-internal/errors/ErrorClient.d.ts.map +1 -0
  88. package/dist/lib-internal/errors/ErrorClient.js +102 -0
  89. package/dist/lib-internal/errors/ErrorClient.js.map +1 -0
  90. package/dist/lib-internal/errors/index.d.ts +4 -0
  91. package/dist/lib-internal/errors/index.d.ts.map +1 -0
  92. package/dist/lib-internal/errors/index.js +3 -0
  93. package/dist/lib-internal/errors/index.js.map +1 -0
  94. package/dist/lib-internal/errors/types.d.ts +29 -0
  95. package/dist/lib-internal/errors/types.d.ts.map +1 -0
  96. package/dist/lib-internal/errors/types.js +18 -0
  97. package/dist/lib-internal/errors/types.js.map +1 -0
  98. package/dist/lib-internal/http/HttpClient.d.ts +24 -0
  99. package/dist/lib-internal/http/HttpClient.d.ts.map +1 -0
  100. package/dist/lib-internal/http/HttpClient.js +103 -0
  101. package/dist/lib-internal/http/HttpClient.js.map +1 -0
  102. package/dist/lib-internal/http/types.d.ts +12 -0
  103. package/dist/lib-internal/http/types.d.ts.map +1 -0
  104. package/{src/lib-internal/http/types.ts → dist/lib-internal/http/types.js} +2 -3
  105. package/dist/lib-internal/http/types.js.map +1 -0
  106. package/dist/lib-internal/routes/AnalyticsRoutes.d.ts +4 -0
  107. package/dist/lib-internal/routes/AnalyticsRoutes.d.ts.map +1 -0
  108. package/dist/lib-internal/routes/AnalyticsRoutes.js +4 -0
  109. package/dist/lib-internal/routes/AnalyticsRoutes.js.map +1 -0
  110. package/dist/lib-internal/routes/AppRoutes.d.ts +10 -0
  111. package/dist/lib-internal/routes/AppRoutes.d.ts.map +1 -0
  112. package/dist/lib-internal/routes/AppRoutes.js +6 -0
  113. package/dist/lib-internal/routes/AppRoutes.js.map +1 -0
  114. package/dist/lib-internal/routes/AuthRoutes.d.ts +2 -0
  115. package/dist/lib-internal/routes/AuthRoutes.d.ts.map +1 -0
  116. package/dist/lib-internal/routes/AuthRoutes.js +2 -0
  117. package/dist/lib-internal/routes/AuthRoutes.js.map +1 -0
  118. package/dist/lib-internal/routes/DatabaseRoutes.d.ts +11 -0
  119. package/dist/lib-internal/routes/DatabaseRoutes.d.ts.map +1 -0
  120. package/dist/lib-internal/routes/DatabaseRoutes.js +7 -0
  121. package/dist/lib-internal/routes/DatabaseRoutes.js.map +1 -0
  122. package/dist/lib-internal/routes/FunctionRoutes.d.ts +4 -0
  123. package/dist/lib-internal/routes/FunctionRoutes.d.ts.map +1 -0
  124. package/dist/lib-internal/routes/FunctionRoutes.js +4 -0
  125. package/dist/lib-internal/routes/FunctionRoutes.js.map +1 -0
  126. package/dist/lib-internal/routes/PolicyRoutes.d.ts +5 -0
  127. package/dist/lib-internal/routes/PolicyRoutes.d.ts.map +1 -0
  128. package/dist/lib-internal/routes/PolicyRoutes.js +5 -0
  129. package/dist/lib-internal/routes/PolicyRoutes.js.map +1 -0
  130. package/dist/lib-internal/routes/SecretsRoutes.d.ts +6 -0
  131. package/dist/lib-internal/routes/SecretsRoutes.d.ts.map +1 -0
  132. package/dist/lib-internal/routes/SecretsRoutes.js +6 -0
  133. package/dist/lib-internal/routes/SecretsRoutes.js.map +1 -0
  134. package/dist/lib-internal/routes/SettingsRoutes.d.ts +5 -0
  135. package/dist/lib-internal/routes/SettingsRoutes.d.ts.map +1 -0
  136. package/{src/lib-internal/routes/SettingsRoutes.ts → dist/lib-internal/routes/SettingsRoutes.js} +2 -1
  137. package/dist/lib-internal/routes/SettingsRoutes.js.map +1 -0
  138. package/dist/lib-internal/routes/StorageRoutes.d.ts +11 -0
  139. package/dist/lib-internal/routes/StorageRoutes.d.ts.map +1 -0
  140. package/dist/lib-internal/routes/StorageRoutes.js +8 -0
  141. package/dist/lib-internal/routes/StorageRoutes.js.map +1 -0
  142. package/dist/lib-internal/routes/UserRoutes.d.ts +13 -0
  143. package/dist/lib-internal/routes/UserRoutes.d.ts.map +1 -0
  144. package/dist/lib-internal/routes/UserRoutes.js +13 -0
  145. package/dist/lib-internal/routes/UserRoutes.js.map +1 -0
  146. package/dist/lib-internal/routes/index.d.ts +2 -0
  147. package/dist/lib-internal/routes/index.d.ts.map +1 -0
  148. package/dist/lib-internal/routes/index.js +2 -0
  149. package/dist/lib-internal/routes/index.js.map +1 -0
  150. package/dist/lib-internal/token/TokenClient.d.ts +38 -0
  151. package/dist/lib-internal/token/TokenClient.d.ts.map +1 -0
  152. package/{src/lib-internal/token/TokenClient.ts → dist/lib-internal/token/TokenClient.js} +44 -59
  153. package/dist/lib-internal/token/TokenClient.js.map +1 -0
  154. package/dist/lib-internal/token/types.d.ts +2 -0
  155. package/dist/lib-internal/token/types.d.ts.map +1 -0
  156. package/dist/lib-internal/token/types.js +2 -0
  157. package/dist/lib-internal/token/types.js.map +1 -0
  158. package/dist/types.d.ts +74 -0
  159. package/dist/types.d.ts.map +1 -0
  160. package/dist/types.js +2 -0
  161. package/dist/types.js.map +1 -0
  162. package/dist/utils/enums.d.ts +31 -0
  163. package/dist/utils/enums.d.ts.map +1 -0
  164. package/dist/utils/enums.js +26 -0
  165. package/dist/utils/enums.js.map +1 -0
  166. package/dist/utils/utils.d.ts +6 -0
  167. package/dist/utils/utils.d.ts.map +1 -0
  168. package/dist/utils/utils.js +38 -0
  169. package/dist/utils/utils.js.map +1 -0
  170. package/package.json +11 -2
  171. package/.github/worflows/publish.yml +0 -57
  172. package/.github/workflows/publish.yml +0 -58
  173. package/.kiro/settings/lsp.json +0 -198
  174. package/MODULE_NAMING_CHANGES.md +0 -81
  175. package/PARAMETER_NAMING_CHANGES.md +0 -106
  176. package/USAGE_EXAMPLE.md +0 -86
  177. package/src/index.ts +0 -50
  178. package/src/lib/analytics/AnalyticsClient.ts +0 -24
  179. package/src/lib/analytics/types.ts +0 -8
  180. package/src/lib/app/AppClient.ts +0 -54
  181. package/src/lib/app/types.ts +0 -50
  182. package/src/lib/auth/AuthClient.ts +0 -148
  183. package/src/lib/auth/types.ts +0 -123
  184. package/src/lib/database/DatabaseClient.ts +0 -244
  185. package/src/lib/database/types.ts +0 -90
  186. package/src/lib/functions/FunctionsClient.ts +0 -27
  187. package/src/lib/functions/types.ts +0 -27
  188. package/src/lib/policy/types.ts +0 -39
  189. package/src/lib/secrets/SecretsClient.ts +0 -75
  190. package/src/lib/secrets/types.ts +0 -59
  191. package/src/lib/settings/SettingsClient.ts +0 -22
  192. package/src/lib/settings/types.ts +0 -9
  193. package/src/lib/storage/StorageClient.ts +0 -131
  194. package/src/lib/storage/types.ts +0 -86
  195. package/src/lib/users/UserClient.ts +0 -63
  196. package/src/lib/users/types.ts +0 -123
  197. package/src/lib-internal/errors/ErrorClient.ts +0 -114
  198. package/src/lib-internal/errors/index.ts +0 -3
  199. package/src/lib-internal/errors/types.ts +0 -29
  200. package/src/lib-internal/http/HttpClient.ts +0 -117
  201. package/src/lib-internal/routes/AnalyticsRoutes.ts +0 -3
  202. package/src/lib-internal/routes/AppRoutes.ts +0 -9
  203. package/src/lib-internal/routes/AuthRoutes.ts +0 -3
  204. package/src/lib-internal/routes/DatabaseRoutes.ts +0 -10
  205. package/src/lib-internal/routes/FunctionRoutes.ts +0 -3
  206. package/src/lib-internal/routes/PolicyRoutes.ts +0 -4
  207. package/src/lib-internal/routes/SecretsRoutes.ts +0 -5
  208. package/src/lib-internal/routes/StorageRoutes.ts +0 -15
  209. package/src/lib-internal/routes/UserRoutes.ts +0 -12
  210. package/src/lib-internal/routes/index.ts +0 -0
  211. package/src/lib-internal/token/types.ts +0 -0
  212. package/src/types.ts +0 -98
  213. package/src/utils/enums.ts +0 -24
  214. package/src/utils/utils.ts +0 -37
  215. package/tests/fixtures/mockClient.ts +0 -19
  216. package/tests/mocks/db.json +0 -1
  217. package/tests/unit/analytics/AnalyticsClient.test.ts +0 -84
  218. package/tests/unit/app/AppClient.test.ts +0 -114
  219. package/tests/unit/auth/AuthClient.test.ts +0 -91
  220. package/tests/unit/client/Client.test.ts +0 -87
  221. package/tests/unit/database/DatabaseClient.test.ts +0 -565
  222. package/tests/unit/edge-cases/robustness.test.ts +0 -258
  223. package/tests/unit/errors/errors.test.ts +0 -236
  224. package/tests/unit/functions/FunctionsClient.test.ts +0 -99
  225. package/tests/unit/policy/PolicyClient.test.ts +0 -180
  226. package/tests/unit/secrets/SecretsClient.test.ts +0 -146
  227. package/tests/unit/settings/SettingsClient.test.ts +0 -50
  228. package/tests/unit/storage/StorageClient.test.ts +0 -252
  229. package/tests/unit/users/UserClient.test.ts +0 -150
  230. package/tsconfig.json +0 -44
  231. package/vitest.config.ts +0 -7
@@ -1,29 +0,0 @@
1
- /**
2
- * Error codes matching the backend's ErrorCode enum.
3
- * Maps 1:1 with base.responses.error_codes.ErrorCode in Python.
4
- */
5
- export enum ErrorCode {
6
- BAD_REQUEST = 'BAD_REQUEST',
7
- VALIDATION_ERROR = 'VALIDATION_ERROR',
8
- UNAUTHORIZED = 'UNAUTHORIZED',
9
- FORBIDDEN = 'FORBIDDEN',
10
- NOT_FOUND = 'NOT_FOUND',
11
- CONFLICT = 'CONFLICT',
12
- INTERNAL_ERROR = 'INTERNAL_ERROR',
13
- RATE_LIMITED = 'RATE_LIMITED',
14
- GATEWAY_TIMEOUT = 'GATEWAY_TIMEOUT',
15
- NETWORK_ERROR = 'NETWORK_ERROR'
16
- }
17
-
18
- /**
19
- * Backend error response shape.
20
- * Matches AppException.to_dict() output.
21
- */
22
- export interface ErrorResponseBody {
23
- status: 'error'
24
- code: string
25
- message: string
26
- detail?: string
27
- errors?: Record<string, unknown>
28
- data?: unknown
29
- }
@@ -1,117 +0,0 @@
1
- import type { TaruviConfig } from "../../types.js";
2
- import type { TokenClient } from "../token/TokenClient.js";
3
- import axios, { AxiosError, type AxiosInstance, type InternalAxiosRequestConfig } from "axios";
4
- import { createErrorFromResponse, NetworkError, TaruviError } from "../errors/index.js";
5
- import type { ErrorResponseBody } from "../errors/index.js";
6
-
7
- /**
8
- * HttpClient handles all HTTP requests to the Taruvi API.
9
- * Sends session token via X-Session-Token header.
10
- * Clears tokens on 401 auth failures.
11
- *
12
- * @internal
13
- */
14
- export class HttpClient {
15
- private config: TaruviConfig
16
- private tokenClient: TokenClient
17
- private axiosInstance: AxiosInstance
18
-
19
- constructor(config: TaruviConfig, tokenClient: TokenClient) {
20
- this.config = config
21
- this.tokenClient = tokenClient
22
- this.axiosInstance = axios.create({ baseURL: config.apiUrl, withCredentials: true })
23
- this.setupInterceptors()
24
- }
25
-
26
- private setupInterceptors(): void {
27
- // Request interceptor: attach session token
28
- this.axiosInstance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
29
- const isFormData = config.data instanceof FormData
30
- if (!isFormData) {
31
- config.headers['Content-Type'] = 'application/json'
32
- }
33
- const sessionToken = this.tokenClient.getSessionToken()
34
- if (sessionToken) {
35
- config.headers['X-Session-Token'] = sessionToken
36
- }
37
- return config
38
- })
39
-
40
- // Response interceptor: clear tokens on authentication failure
41
- // Only 401 (Unauthorized) means the session is invalid
42
- // 403 (Forbidden) means authenticated but lacking permission — don't clear tokens
43
- this.axiosInstance.interceptors.response.use(
44
- (response) => response,
45
- (error: AxiosError) => {
46
- const status = error.response?.status
47
- if (status === 401) {
48
- this.tokenClient.clearTokens()
49
- }
50
- return Promise.reject(error)
51
- }
52
- )
53
- }
54
-
55
- private handleError(error: unknown): never {
56
- if (error instanceof TaruviError) {
57
- throw error
58
- }
59
-
60
- if (error instanceof AxiosError) {
61
- if (error.response) {
62
- const body = error.response.data as ErrorResponseBody | undefined
63
- throw createErrorFromResponse(error.response.status, body)
64
- }
65
- throw new NetworkError(error.message)
66
- }
67
-
68
- throw error
69
- }
70
-
71
- async get<T>(endpoint: string, options?: { responseType?: 'json' | 'blob' }): Promise<T> {
72
- try {
73
- const { data } = await this.axiosInstance.get<T>(`/${endpoint}`, {
74
- ...(options?.responseType && { responseType: options.responseType }),
75
- })
76
- return data as T
77
- } catch (error) {
78
- this.handleError(error)
79
- }
80
- }
81
-
82
- async post<T, D = unknown>(endpoint: string, body: D): Promise<T> {
83
- try {
84
- const { data } = await this.axiosInstance.post<T>(`/${endpoint}`, body)
85
- return data
86
- } catch (error) {
87
- this.handleError(error)
88
- }
89
- }
90
-
91
- async put<T, D = unknown>(endpoint: string, body: D): Promise<T> {
92
- try {
93
- const { data } = await this.axiosInstance.put<T>(`/${endpoint}`, body)
94
- return data
95
- } catch (error) {
96
- this.handleError(error)
97
- }
98
- }
99
-
100
- async delete<T, D = unknown>(endpoint: string, body?: D): Promise<T> {
101
- try {
102
- const { data } = await this.axiosInstance.delete<T>(`/${endpoint}`, { data: body })
103
- return data
104
- } catch (error) {
105
- this.handleError(error)
106
- }
107
- }
108
-
109
- async patch<T, D = unknown>(endpoint: string, body: D): Promise<T> {
110
- try {
111
- const { data } = await this.axiosInstance.patch<T>(`/${endpoint}`, body)
112
- return data
113
- } catch (error) {
114
- this.handleError(error)
115
- }
116
- }
117
- }
@@ -1,3 +0,0 @@
1
- export const AnalyticsRoutes = {
2
- baseUrl: (appSlug: string, querySlug: string) => `api/apps/${appSlug}/analytics/queries/${querySlug}/execute/`
3
- }
@@ -1,9 +0,0 @@
1
- export const AppRoutes = {
2
- baseUrl: (appSlug: string) => `api/apps/${appSlug}`,
3
- roles: (): string => `/roles`,
4
- settings: (): string => "/settings/"
5
- }
6
-
7
- type AllRouteKeys = keyof typeof AppRoutes
8
- export type AppRouteKey = Exclude<AllRouteKeys, 'baseUrl'>
9
- export type AppUrlParams = Partial<Record<AppRouteKey, string>>
@@ -1,3 +0,0 @@
1
- export const AuthRoutes = {
2
- session: () => "_allauth/app/v1/auth/session"
3
- } as const
@@ -1,10 +0,0 @@
1
- export const DatabaseRoutes = {
2
- baseUrl: (appSlug: string) => `api/apps/${appSlug}`,
3
- dataTables: (tableName: string): string => `/datatables/${tableName}/data`,
4
- recordId: (recordId: string): string => `/${recordId}`,
5
- upsert: (): string => `/upsert`
6
- }
7
-
8
- type AllRouteKeys = keyof typeof DatabaseRoutes
9
- export type DatabaseRouteKey = Exclude<AllRouteKeys, 'baseUrl'>
10
- export type DatabaseUrlParams = Partial<Record<DatabaseRouteKey, string>>
@@ -1,3 +0,0 @@
1
- export const FunctionRoutes = {
2
- baseUrl: (appSlug: string, functionSlug: string) => `api/apps/${appSlug}/functions/${functionSlug}`
3
- }
@@ -1,4 +0,0 @@
1
- export const PolicyRoutes = {
2
- baseUrl: (appSlug: string) => `api/apps/${appSlug}`,
3
- checkResource: "/check/resources"
4
- }
@@ -1,5 +0,0 @@
1
- export const SecretsRoutes = {
2
- baseUrl: "api/secrets/",
3
- get: (key: string) => `api/secrets/${key}/`,
4
- update: (key: string) => `api/secrets/${key}/`
5
- }
@@ -1,15 +0,0 @@
1
- export const StorageRoutes = {
2
- baseUrl: (appslug: string, bucket: string) => `api/apps/${appslug}/storage/buckets/${bucket}/objects`,
3
- path: (path: string) => "/" + encodeURIComponent(path),
4
- upload: () => "/batch-upload",
5
- delete: () => "/batch-delete"
6
- // bucket: (appslug: string, bucketslug: string) => `${StorageRoutesClone.baseUrl(appslug)}/${bucketslug}`
7
- }
8
-
9
- export type StoragePathKey = 'path'
10
- export type StorageFlagKey = 'upload' | 'delete'
11
- export type StorageRouteKey = StoragePathKey | StorageFlagKey
12
-
13
- export type BucketUrlParams = Partial<
14
- Record<StorageRouteKey, string | true>
15
- >
@@ -1,12 +0,0 @@
1
- export const UserRoutes = {
2
- baseUrl: "api/users/",
3
- getCurrentUser: () => `${UserRoutes.baseUrl}me/`,
4
- preferences: () => `${UserRoutes.baseUrl}me/preferences/`,
5
- getUser: (username: string) => `${UserRoutes.baseUrl}${username}/`,
6
- updateUser: (username: string) => `${UserRoutes.baseUrl}${username}/`,
7
- deleteUser: (username: string) => `${UserRoutes.baseUrl}${username}/`,
8
- listUser: (filter: string) => `${UserRoutes.baseUrl}${filter}`,
9
- getUserApps: (username: string) => `${UserRoutes.baseUrl}${username}/apps/`,
10
- assignRoles: () => `api/assign/roles/`,
11
- revokeRoles: () => `api/revoke/roles/`
12
- } as const
File without changes
File without changes
package/src/types.ts DELETED
@@ -1,98 +0,0 @@
1
- import { MimeTypeCategory, Visibility } from './utils/enums.js'
2
-
3
- export interface TaruviConfig {
4
- apiKey: string // Identifies which site the client belongs to
5
- appSlug: string // Identifies which app the client belongs to
6
- apiUrl: string // Base API URL
7
- deskUrl?: string // URL for the desk/login page
8
- token?: string // Optional: Pre-existing auth token
9
- }
10
-
11
- // Standard response wrapper matching backend AppDataResponse
12
- export interface TaruviResponse<T = unknown> {
13
- status: "success" | "error"
14
- message: string
15
- data: T
16
- total?: number
17
- pagination?: PaginationInfo
18
- }
19
-
20
- export interface PaginationInfo {
21
- offset: number
22
- limit: number
23
- count: number
24
- current_page: number
25
- total_pages: number
26
- has_next: boolean
27
- has_previous: boolean
28
- }
29
-
30
- export interface StorageFilters {
31
- // Pagination (DRF style)
32
- page?: number
33
- page_size?: number
34
-
35
- // Range Filters - Size (in bytes)
36
- size__gte?: number
37
- size__lte?: number
38
- size__gt?: number
39
- size__lt?: number
40
- min_size?: number
41
- max_size?: number
42
-
43
- // Range Filters - Dates (ISO 8601)
44
- created_at__gte?: string
45
- created_at__lte?: string
46
- created_after?: string
47
- created_before?: string
48
- updated_at__gte?: string
49
- updated_at__lte?: string
50
-
51
- // Search Filters
52
- search?: string
53
- filename__icontains?: string
54
- prefix?: string
55
- file?: string
56
- file__icontains?: string
57
- file__startswith?: string
58
- file__istartswith?: string
59
- metadata_search?: string
60
-
61
- // MIME Type Filters
62
- mimetype?: string
63
- mimetype__in?: string
64
- mimetype_category?: MimeTypeCategory
65
-
66
- // Visibility & User Filters
67
- visibility?: Visibility
68
- created_by_me?: boolean
69
- modified_by_me?: boolean
70
- created_by__username?: string
71
- created_by__username__icontains?: string
72
-
73
- // Sorting
74
- ordering?: string
75
- }
76
-
77
- export interface DatabaseFilters {
78
- // Pagination (DRF style)
79
- page?: number
80
- page_size?: number
81
-
82
- // Sorting (DRF style: "-field" for desc, "field" for asc)
83
- ordering?: string
84
-
85
- // Populate relations
86
- populate?: string
87
-
88
- // Search (translates to search_vector__search on backend)
89
- search?: string
90
-
91
- // Aggregates
92
- _aggregate?: string
93
- _group_by?: string
94
- _having?: string
95
-
96
- // Dynamic filters - allows any field with operators
97
- [key: string]: string | number | boolean | undefined
98
- }
@@ -1,24 +0,0 @@
1
- export const MimeTypeCategory = {
2
- IMAGE: 'image',
3
- VIDEO: 'video',
4
- AUDIO: 'audio',
5
- APPLICATION: 'application',
6
- TEXT: 'text'
7
- } as const
8
-
9
- export type MimeTypeCategory = typeof MimeTypeCategory[keyof typeof MimeTypeCategory]
10
-
11
- export const Visibility = {
12
- PUBLIC: 'public',
13
- PRIVATE: 'private'
14
- } as const
15
-
16
- export type Visibility = typeof Visibility[keyof typeof Visibility]
17
-
18
-
19
- export const QueryParams = {
20
- include: "include",
21
- depth: "depth",
22
- format: "format",
23
- graph_type: "graph_type",
24
- }
@@ -1,37 +0,0 @@
1
- const _window = typeof window !== 'undefined' ? window : undefined
2
- const _navigator = typeof navigator !== 'undefined' ? navigator : undefined
3
- const _document = typeof document !== 'undefined' ? document : undefined
4
-
5
- export const isBrowser = (): boolean => {
6
- return _window !== undefined && _document !== undefined
7
- }
8
-
9
- export const isReactNative = (): boolean => {
10
- return _navigator !== undefined &&
11
- // @ts-ignore - navigator.product is deprecated but still used in RN detection
12
- _navigator.product === 'ReactNative'
13
- }
14
-
15
- export const getRuntimeEnvironment = (): string => {
16
- if (isBrowser()) return 'Browser'
17
- if (isReactNative()) return 'ReactNative'
18
- return 'Server'
19
- }
20
-
21
- export function buildQueryString(queryParams: Record<string, unknown> | undefined): string {
22
- if (!queryParams || Object.keys(queryParams).length === 0) {
23
- return ''
24
- }
25
- const params = new URLSearchParams()
26
- Object.entries(queryParams).forEach(([key, value]) => {
27
- if (value !== undefined && value !== null) {
28
- if (Array.isArray(value)) {
29
- value.forEach((v) => params.append(key, String(v)))
30
- } else {
31
- params.append(key, String(value))
32
- }
33
- }
34
- })
35
- const queryString = params.toString()
36
- return queryString ? `?${queryString}` : ''
37
- }
@@ -1,19 +0,0 @@
1
- import { vi } from 'vitest'
2
- import { Client } from '../../src/client.js'
3
-
4
- export const mockHttpClient = {
5
- get: vi.fn(),
6
- post: vi.fn(),
7
- put: vi.fn(),
8
- patch: vi.fn(),
9
- delete: vi.fn()
10
- }
11
-
12
- export const mockClient = {
13
- getConfig: () => ({ apiKey: 'test-key', appSlug: 'test-app', apiUrl: 'https://api.test.com' }),
14
- httpClient: mockHttpClient
15
- } as unknown as Client
16
-
17
- export function resetMocks() {
18
- vi.clearAllMocks()
19
- }
@@ -1 +0,0 @@
1
- {}
@@ -1,84 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest'
2
- import { Analytics } from '../../../src/lib/analytics/AnalyticsClient.js'
3
- import { Client } from '../../../src/client.js'
4
-
5
- const mockHttpClient = {
6
- post: vi.fn()
7
- }
8
-
9
- const mockClient = {
10
- getConfig: () => ({ apiKey: 'test-key', appSlug: 'test-app', apiUrl: 'https://api.test.com' }),
11
- httpClient: mockHttpClient
12
- } as unknown as Client
13
-
14
- describe('Analytics', () => {
15
- beforeEach(() => {
16
- vi.clearAllMocks()
17
- })
18
-
19
- describe('execute()', () => {
20
- it('executes analytics query with default options', async () => {
21
- const response = { data: { total_sales: 1000 } }
22
- mockHttpClient.post.mockResolvedValue(response)
23
-
24
- const analytics = new Analytics(mockClient)
25
- const result = await analytics.execute('sales-report')
26
-
27
- expect(mockHttpClient.post).toHaveBeenCalledWith(
28
- 'api/apps/test-app/analytics/queries/sales-report/execute/',
29
- { params: {} }
30
- )
31
- expect(result).toEqual(response)
32
- })
33
-
34
- it('executes analytics query with params', async () => {
35
- const response = { data: { total_sales: 5000 } }
36
- mockHttpClient.post.mockResolvedValue(response)
37
-
38
- const analytics = new Analytics(mockClient)
39
- await analytics.execute('monthly-report', {
40
- params: {
41
- start_date: '2024-01-01',
42
- end_date: '2024-12-31'
43
- }
44
- })
45
-
46
- expect(mockHttpClient.post).toHaveBeenCalledWith(
47
- 'api/apps/test-app/analytics/queries/monthly-report/execute/',
48
- {
49
- params: {
50
- start_date: '2024-01-01',
51
- end_date: '2024-12-31'
52
- }
53
- }
54
- )
55
- })
56
-
57
- it('supports typed response', async () => {
58
- interface SalesData {
59
- total_sales: number
60
- orders_count: number
61
- }
62
- const response = { data: { total_sales: 10000, orders_count: 50 } }
63
- mockHttpClient.post.mockResolvedValue(response)
64
-
65
- const analytics = new Analytics(mockClient)
66
- const result = await analytics.execute<SalesData>('sales-summary')
67
-
68
- expect(result.data?.total_sales).toBe(10000)
69
- expect(result.data?.orders_count).toBe(50)
70
- })
71
-
72
- it('builds correct URL with app slug and query slug', async () => {
73
- mockHttpClient.post.mockResolvedValue({})
74
-
75
- const analytics = new Analytics(mockClient)
76
- await analytics.execute('dashboard-metrics')
77
-
78
- expect(mockHttpClient.post).toHaveBeenCalledWith(
79
- 'api/apps/test-app/analytics/queries/dashboard-metrics/execute/',
80
- expect.any(Object)
81
- )
82
- })
83
- })
84
- })
@@ -1,114 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest'
2
- import { App } from '../../../src/lib/app/AppClient.js'
3
- import { Client } from '../../../src/client.js'
4
- import type { RolesListResponse, AppSettingsResponse } from '../../../src/lib/app/types.js'
5
-
6
- const mockHttpClient = {
7
- get: vi.fn()
8
- }
9
-
10
- const mockClient = {
11
- getConfig: () => ({ apiKey: 'test-key', appSlug: 'test-app', apiUrl: 'https://api.test.com' }),
12
- httpClient: mockHttpClient
13
- } as unknown as Client
14
-
15
- describe('App', () => {
16
- beforeEach(() => {
17
- vi.clearAllMocks()
18
- })
19
-
20
- describe('roles()', () => {
21
- it('returns App instance for chaining', () => {
22
- const app = new App(mockClient)
23
- const result = app.roles()
24
- expect(result).toBeInstanceOf(App)
25
- })
26
-
27
- it('fetches app roles on execute', async () => {
28
- const rolesData = [
29
- { id: '1', name: 'Admin', permissions: ['read', 'write', 'delete'] },
30
- { id: '2', name: 'Editor', permissions: ['read', 'write'] }
31
- ]
32
- mockHttpClient.get.mockResolvedValue(rolesData)
33
-
34
- const app = new App(mockClient)
35
- const result = await app.roles().execute()
36
-
37
- expect(mockHttpClient.get).toHaveBeenCalledWith('api/apps/test-app/roles')
38
- expect(result).toEqual(rolesData)
39
- })
40
- })
41
-
42
- describe('settings()', () => {
43
- it('returns App instance for chaining', () => {
44
- const app = new App(mockClient)
45
- const result = app.settings()
46
- expect(result).toBeInstanceOf(App)
47
- })
48
-
49
- it('fetches app settings on execute', async () => {
50
- const settingsData = { theme: 'dark', language: 'en' }
51
- mockHttpClient.get.mockResolvedValue(settingsData)
52
-
53
- const app = new App(mockClient)
54
- const result = await app.settings().execute()
55
-
56
- expect(mockHttpClient.get).toHaveBeenCalledWith('api/apps/test-app/settings/')
57
- expect(result).toEqual(settingsData)
58
- })
59
- })
60
-
61
- describe('execute()', () => {
62
- it('calls httpClient.get by default', async () => {
63
- mockHttpClient.get.mockResolvedValue({})
64
-
65
- const app = new App(mockClient)
66
- await app.execute()
67
-
68
- expect(mockHttpClient.get).toHaveBeenCalled()
69
- })
70
-
71
- it('builds correct base URL with app slug', async () => {
72
- mockHttpClient.get.mockResolvedValue({})
73
-
74
- const app = new App(mockClient)
75
- await app.roles().execute()
76
-
77
- expect(mockHttpClient.get).toHaveBeenCalledWith(
78
- expect.stringContaining('api/apps/test-app')
79
- )
80
- })
81
- })
82
-
83
- describe('response handling', () => {
84
- it('returns roles list matching RolesListResponse type', async () => {
85
- const mockResponse: RolesListResponse = {
86
- status: 'success',
87
- message: 'Data retrieved successfully',
88
- data: [
89
- { id: '1', name: 'Admin', slug: 'admin', description: 'Admin role', is_default: false, created_at: '2024-01-01', updated_at: '2024-01-01' },
90
- { id: '2', name: 'Editor', slug: 'editor', description: 'Editor role', is_default: false, created_at: '2024-01-01', updated_at: '2024-01-01' }
91
- ],
92
- total: 2
93
- }
94
- mockHttpClient.get.mockResolvedValue(mockResponse)
95
- const result = await new App(mockClient).roles().execute() as RolesListResponse
96
- expect(result.status).toBe('success')
97
- expect(result.data).toHaveLength(2)
98
- expect(result.data[0].name).toBe('Admin')
99
- expect(result.total).toBe(2)
100
- })
101
-
102
- it('returns settings matching AppSettingsResponse type', async () => {
103
- const mockResponse: AppSettingsResponse = {
104
- status: 'success',
105
- message: 'Settings retrieved successfully',
106
- data: { name: 'My App', slug: 'my-app', description: 'Test app', is_active: true, documentation_url: null, support_email: null, default_frontend_worker_url: null, created_at: '2024-01-01', updated_at: '2024-01-01' }
107
- }
108
- mockHttpClient.get.mockResolvedValue(mockResponse)
109
- const result = await new App(mockClient).settings().execute() as AppSettingsResponse
110
- expect(result.data.name).toBe('My App')
111
- expect(result.data.is_active).toBe(true)
112
- })
113
- })
114
- })