@taruvi/sdk 1.1.4 → 1.1.6

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.
@@ -12,7 +12,8 @@ npm install @taruvi-io/sdk
12
12
 
13
13
  Recent updates to the SDK:
14
14
 
15
- - **Policy Service**: New service for checking resource-level permissions with `checkResource()` method. Supports batch resource checking with principals, roles, and attributes.
15
+ - **Analytics Service**: New service for executing analytics queries with `execute()` method. Pass query name and parameters to run predefined analytics.
16
+ - **Policy Service**: New service for checking resource-level permissions with `checkResource()` method. Supports batch resource checking with entity types, tables, and attributes.
16
17
  - **App Service**: New service to retrieve app roles with `roles()` method.
17
18
  - **User Types**: Added `UserList`, `UserApp`, and `UserAppsResponse` types for user listing and app associations.
18
19
  - **Auth Service**: Web UI Flow with `login()`, `signup()`, `logout()` methods that redirect to backend pages. Token refresh with rotation support, `getCurrentUser()` for JWT decoding.
@@ -698,6 +699,86 @@ export default function FunctionExecutor({ taruviClient }) {
698
699
 
699
700
  ---
700
701
 
702
+ ## Analytics Service
703
+
704
+ ### Execute Analytics Query
705
+
706
+ ```typescript
707
+ import { Analytics } from '@taruvi-io/sdk'
708
+
709
+ const analytics = new Analytics(taruviClient)
710
+
711
+ const result = await analytics.execute("monthly-sales-report", {
712
+ params: {
713
+ start_date: "2024-01-01",
714
+ end_date: "2024-12-31"
715
+ }
716
+ })
717
+
718
+ console.log(result.data) // Analytics query result
719
+ ```
720
+
721
+ ### Execute with Typed Response
722
+
723
+ ```typescript
724
+ interface SalesData {
725
+ total_sales: number
726
+ orders_count: number
727
+ average_order_value: number
728
+ }
729
+
730
+ const analytics = new Analytics(taruviClient)
731
+
732
+ const result = await analytics.execute<SalesData>("sales-summary", {
733
+ params: { period: "monthly" }
734
+ })
735
+
736
+ console.log(result.data?.total_sales)
737
+ console.log(result.data?.orders_count)
738
+ ```
739
+
740
+ ### Complete Analytics Dashboard Example
741
+
742
+ ```typescript
743
+ import { useEffect, useState } from 'react'
744
+ import { Analytics } from '@taruvi-io/sdk'
745
+
746
+ export default function AnalyticsDashboard({ taruviClient }) {
747
+ const [metrics, setMetrics] = useState(null)
748
+ const [loading, setLoading] = useState(true)
749
+
750
+ useEffect(() => {
751
+ const fetchMetrics = async () => {
752
+ try {
753
+ const analytics = new Analytics(taruviClient)
754
+ const result = await analytics.execute("dashboard-metrics", {
755
+ params: {
756
+ date_range: "last_30_days"
757
+ }
758
+ })
759
+ setMetrics(result.data)
760
+ } catch (error) {
761
+ console.error("Failed to fetch analytics:", error)
762
+ } finally {
763
+ setLoading(false)
764
+ }
765
+ }
766
+ fetchMetrics()
767
+ }, [])
768
+
769
+ if (loading) return <div>Loading analytics...</div>
770
+
771
+ return (
772
+ <div>
773
+ <h2>Dashboard Metrics</h2>
774
+ <pre>{JSON.stringify(metrics, null, 2)}</pre>
775
+ </div>
776
+ )
777
+ }
778
+ ```
779
+
780
+ ---
781
+
701
782
  ## Settings Service
702
783
 
703
784
  ### Get Site Settings
@@ -764,12 +845,14 @@ const policy = new Policy(taruviClient)
764
845
  // Check permissions for multiple resources
765
846
  const result = await policy.checkResource([
766
847
  {
848
+ entityType: "crm",
767
849
  tableName: "accounts",
768
850
  recordId: "record-123",
769
851
  attributes: { owner_id: "user-456" },
770
852
  actions: ["read", "update"]
771
853
  },
772
854
  {
855
+ entityType: "docs",
773
856
  tableName: "documents",
774
857
  recordId: "doc-789",
775
858
  attributes: {},
@@ -778,33 +861,10 @@ const result = await policy.checkResource([
778
861
  ])
779
862
  ```
780
863
 
781
- ### Check with Principal Override
782
-
783
- ```typescript
784
- const policy = new Policy(taruviClient)
785
-
786
- // Check permissions for a specific principal
787
- const result = await policy.checkResource(
788
- [
789
- {
790
- tableName: "accounts",
791
- recordId: "record-123",
792
- attributes: {},
793
- actions: ["read"]
794
- }
795
- ],
796
- {
797
- id: "user-123",
798
- roles: ["admin", "editor"],
799
- attr: { department: "sales" }
800
- }
801
- )
802
- ```
803
-
804
864
  ### Complete Permission Check Example
805
865
 
806
866
  ```typescript
807
- import { useState } from 'react'
867
+ import { useState, useEffect } from 'react'
808
868
  import { Policy } from '@taruvi-io/sdk'
809
869
 
810
870
  export default function ResourceGuard({ taruviClient, children, resource }) {
@@ -817,6 +877,7 @@ export default function ResourceGuard({ taruviClient, children, resource }) {
817
877
  const policy = new Policy(taruviClient)
818
878
  const result = await policy.checkResource([
819
879
  {
880
+ entityType: resource.entityType,
820
881
  tableName: resource.table,
821
882
  recordId: resource.id,
822
883
  attributes: resource.attributes || {},
@@ -1003,7 +1064,9 @@ import type {
1003
1064
  Principal,
1004
1065
  Resource,
1005
1066
  Resources,
1006
- RoleResponse
1067
+ RoleResponse,
1068
+ AnalyticsRequest,
1069
+ AnalyticsResponse
1007
1070
  } from '@taruvi-io/sdk'
1008
1071
  ```
1009
1072
 
@@ -1062,6 +1125,7 @@ const principal: Principal = {
1062
1125
 
1063
1126
  const resources: Resources = [
1064
1127
  {
1128
+ entityType: "crm",
1065
1129
  tableName: "accounts",
1066
1130
  recordId: "acc-456",
1067
1131
  attributes: { owner_id: "user-123" },
@@ -1128,6 +1192,7 @@ The Storage service supports these specialized filters:
1128
1192
  | `Secrets` | `import { Secrets }` | Sensitive data |
1129
1193
  | `Policy` | `import { Policy }` | Resource permissions |
1130
1194
  | `App` | `import { App }` | App roles & config |
1195
+ | `Analytics` | `import { Analytics }` | Analytics queries |
1131
1196
 
1132
1197
  ---
1133
1198
 
@@ -1171,4 +1236,4 @@ const client = new Client({
1171
1236
 
1172
1237
  ---
1173
1238
 
1174
- **Generated from production code examples • Last updated: 2025-12-22**
1239
+ **Generated from production code examples • Last updated: 2026-01-02**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taruvi/sdk",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Taruvi SDK",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
package/src/index.ts CHANGED
@@ -11,6 +11,7 @@ export { Functions } from "./lib/Function/FunctionsClient.js"
11
11
  export { Secrets } from "./lib/Secrets/SecretsClient.js"
12
12
  export { Policy } from "./lib/Policy/PolicyClient.js"
13
13
  export { App } from "./lib/App/AppClient.js"
14
+ export { Analytics } from "./lib/Analytics/AnalyticsClient.js"
14
15
 
15
16
  // Export types
16
17
  export type { TaruviConfig, StorageFilters, DatabaseFilters } from "./types.js"
@@ -22,4 +23,5 @@ export type { FunctionRequest, FunctionResponse, FunctionInvocation } from "./li
22
23
  export type { DatabaseRequest, DatabaseResponse } from "./lib/Database/types.js"
23
24
  export type { StorageRequest, StorageUpdateRequest, StorageResponse } from "./lib/Storage/types.js"
24
25
  export type { SettingsResponse } from "./lib/Settings/types.js"
25
- export type { SecretRequest, SecretResponse } from "./lib/Secrets/types.js"
26
+ export type { SecretRequest, SecretResponse } from "./lib/Secrets/types.js"
27
+ export type { AnalyticsRequest, AnalyticsResponse } from "./lib/Analytics/types.js"
@@ -0,0 +1,24 @@
1
+ import type { Client } from "../../client.js";
2
+ import type { TaruviConfig } from "../../types.js";
3
+ import type { AnalyticsRequest, AnalyticsResponse } from "./types.js";
4
+ import { AnalyticsRoutes } from "../../lib-internal/routes/AnalyticsRoutes.js";
5
+
6
+ export class Analytics {
7
+ private client: Client
8
+ private config: TaruviConfig
9
+
10
+ constructor(client: Client) {
11
+ this.client = client
12
+ this.config = this.client.getConfig()
13
+ }
14
+
15
+ async execute<T = unknown>(querySlug: string, options: AnalyticsRequest = {}): Promise<AnalyticsResponse<T>> {
16
+ const url = AnalyticsRoutes.baseUrl(this.config.appSlug, querySlug)
17
+
18
+ const body = {
19
+ params: options.params || {}
20
+ }
21
+
22
+ return await this.client.httpClient.post<AnalyticsResponse<T>>(url, body)
23
+ }
24
+ }
@@ -0,0 +1,7 @@
1
+ export interface AnalyticsRequest {
2
+ params?: Record<string, unknown>
3
+ }
4
+
5
+ export interface AnalyticsResponse<T = unknown> {
6
+ data: T | null
7
+ }
@@ -1,7 +1,7 @@
1
1
  import type { Client } from "../../client.js"
2
2
  import { PolicyRoutes } from "../../lib-internal/routes/PolicyRoutes.js"
3
3
  import type { TaruviConfig } from "../../types.js"
4
- import type { Principal, Resource, Resources } from "./types.js"
4
+ import type { Resources } from "./types.js"
5
5
 
6
6
  export class Policy {
7
7
  private client: Client
@@ -11,16 +11,16 @@ export class Policy {
11
11
  this.config = this.client.getConfig()
12
12
  }
13
13
 
14
- async checkResource(resources: Resources, principal?: Principal) {
14
+ async checkResource(resources: Resources) {
15
15
  const url = PolicyRoutes.baseUrl(this.config.appSlug) + PolicyRoutes.checkResource
16
16
  const body = JSON.stringify({
17
- principal,
18
17
  resources: resources.map(r => ({
19
18
  resource: {
20
- kind: `${this.config.appSlug}:${r.tableName}`,
19
+ kind: `${r.entityType}:${r.tableName}`,
21
20
  id: r.recordId,
22
21
  attr: r.attributes || {}
23
- }
22
+ },
23
+ actions: r.actions
24
24
  }))
25
25
  })
26
26
 
@@ -11,6 +11,7 @@ export type Resource = {
11
11
  };
12
12
 
13
13
  export type Resources = {
14
+ entityType: string
14
15
  tableName: string
15
16
  recordId: string
16
17
  attributes: Record<string, unknown>
@@ -0,0 +1,3 @@
1
+ export const AnalyticsRoutes = {
2
+ baseUrl: (appSlug: string, querySlug: string) => `api/apps/${appSlug}/analytics/queries/${querySlug}/execute/`
3
+ }