@taruvi/sdk 1.1.4 → 1.1.5

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,89 @@ 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({
712
+ name: "monthly_sales_report",
713
+ params: {
714
+ start_date: "2024-01-01",
715
+ end_date: "2024-12-31"
716
+ }
717
+ })
718
+
719
+ console.log(result.data) // Analytics query result
720
+ ```
721
+
722
+ ### Execute with Typed Response
723
+
724
+ ```typescript
725
+ interface SalesData {
726
+ total_sales: number
727
+ orders_count: number
728
+ average_order_value: number
729
+ }
730
+
731
+ const analytics = new Analytics(taruviClient)
732
+
733
+ const result = await analytics.execute<SalesData>({
734
+ name: "sales_summary",
735
+ params: { period: "monthly" }
736
+ })
737
+
738
+ console.log(result.data?.total_sales)
739
+ console.log(result.data?.orders_count)
740
+ ```
741
+
742
+ ### Complete Analytics Dashboard Example
743
+
744
+ ```typescript
745
+ import { useEffect, useState } from 'react'
746
+ import { Analytics } from '@taruvi-io/sdk'
747
+
748
+ export default function AnalyticsDashboard({ taruviClient }) {
749
+ const [metrics, setMetrics] = useState(null)
750
+ const [loading, setLoading] = useState(true)
751
+
752
+ useEffect(() => {
753
+ const fetchMetrics = async () => {
754
+ try {
755
+ const analytics = new Analytics(taruviClient)
756
+ const result = await analytics.execute({
757
+ name: "dashboard_metrics",
758
+ params: {
759
+ date_range: "last_30_days"
760
+ }
761
+ })
762
+ setMetrics(result.data)
763
+ } catch (error) {
764
+ console.error("Failed to fetch analytics:", error)
765
+ } finally {
766
+ setLoading(false)
767
+ }
768
+ }
769
+ fetchMetrics()
770
+ }, [])
771
+
772
+ if (loading) return <div>Loading analytics...</div>
773
+
774
+ return (
775
+ <div>
776
+ <h2>Dashboard Metrics</h2>
777
+ <pre>{JSON.stringify(metrics, null, 2)}</pre>
778
+ </div>
779
+ )
780
+ }
781
+ ```
782
+
783
+ ---
784
+
701
785
  ## Settings Service
702
786
 
703
787
  ### Get Site Settings
@@ -764,12 +848,14 @@ const policy = new Policy(taruviClient)
764
848
  // Check permissions for multiple resources
765
849
  const result = await policy.checkResource([
766
850
  {
851
+ entityType: "crm",
767
852
  tableName: "accounts",
768
853
  recordId: "record-123",
769
854
  attributes: { owner_id: "user-456" },
770
855
  actions: ["read", "update"]
771
856
  },
772
857
  {
858
+ entityType: "docs",
773
859
  tableName: "documents",
774
860
  recordId: "doc-789",
775
861
  attributes: {},
@@ -778,33 +864,10 @@ const result = await policy.checkResource([
778
864
  ])
779
865
  ```
780
866
 
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
867
  ### Complete Permission Check Example
805
868
 
806
869
  ```typescript
807
- import { useState } from 'react'
870
+ import { useState, useEffect } from 'react'
808
871
  import { Policy } from '@taruvi-io/sdk'
809
872
 
810
873
  export default function ResourceGuard({ taruviClient, children, resource }) {
@@ -817,6 +880,7 @@ export default function ResourceGuard({ taruviClient, children, resource }) {
817
880
  const policy = new Policy(taruviClient)
818
881
  const result = await policy.checkResource([
819
882
  {
883
+ entityType: resource.entityType,
820
884
  tableName: resource.table,
821
885
  recordId: resource.id,
822
886
  attributes: resource.attributes || {},
@@ -1003,7 +1067,9 @@ import type {
1003
1067
  Principal,
1004
1068
  Resource,
1005
1069
  Resources,
1006
- RoleResponse
1070
+ RoleResponse,
1071
+ AnalyticsRequest,
1072
+ AnalyticsResponse
1007
1073
  } from '@taruvi-io/sdk'
1008
1074
  ```
1009
1075
 
@@ -1062,6 +1128,7 @@ const principal: Principal = {
1062
1128
 
1063
1129
  const resources: Resources = [
1064
1130
  {
1131
+ entityType: "crm",
1065
1132
  tableName: "accounts",
1066
1133
  recordId: "acc-456",
1067
1134
  attributes: { owner_id: "user-123" },
@@ -1128,6 +1195,7 @@ The Storage service supports these specialized filters:
1128
1195
  | `Secrets` | `import { Secrets }` | Sensitive data |
1129
1196
  | `Policy` | `import { Policy }` | Resource permissions |
1130
1197
  | `App` | `import { App }` | App roles & config |
1198
+ | `Analytics` | `import { Analytics }` | Analytics queries |
1131
1199
 
1132
1200
  ---
1133
1201
 
@@ -1171,4 +1239,4 @@ const client = new Client({
1171
1239
 
1172
1240
  ---
1173
1241
 
1174
- **Generated from production code examples • Last updated: 2025-12-22**
1242
+ **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.5",
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,25 @@
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>(options: AnalyticsRequest): Promise<AnalyticsResponse<T>> {
16
+ const url = `${AnalyticsRoutes.baseUrl(this.config.appSlug)}${AnalyticsRoutes.execute}`
17
+
18
+ const body = {
19
+ name: options.name,
20
+ params: options.params || {}
21
+ }
22
+
23
+ return await this.client.httpClient.post<AnalyticsResponse<T>>(url, body)
24
+ }
25
+ }
@@ -0,0 +1,8 @@
1
+ export interface AnalyticsRequest {
2
+ name: string
3
+ params?: Record<string, unknown>
4
+ }
5
+
6
+ export interface AnalyticsResponse<T = unknown> {
7
+ data: T | null
8
+ }
@@ -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,4 @@
1
+ export const AnalyticsRoutes = {
2
+ baseUrl: (appSlug: string) => `api/apps/${appSlug}`,
3
+ execute: "/apps_analytics_queries_execute_create"
4
+ }