@taruvi/sdk 1.1.5 → 1.1.7
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.
|
@@ -708,8 +708,7 @@ import { Analytics } from '@taruvi-io/sdk'
|
|
|
708
708
|
|
|
709
709
|
const analytics = new Analytics(taruviClient)
|
|
710
710
|
|
|
711
|
-
const result = await analytics.execute({
|
|
712
|
-
name: "monthly_sales_report",
|
|
711
|
+
const result = await analytics.execute("monthly-sales-report", {
|
|
713
712
|
params: {
|
|
714
713
|
start_date: "2024-01-01",
|
|
715
714
|
end_date: "2024-12-31"
|
|
@@ -730,8 +729,7 @@ interface SalesData {
|
|
|
730
729
|
|
|
731
730
|
const analytics = new Analytics(taruviClient)
|
|
732
731
|
|
|
733
|
-
const result = await analytics.execute<SalesData>({
|
|
734
|
-
name: "sales_summary",
|
|
732
|
+
const result = await analytics.execute<SalesData>("sales-summary", {
|
|
735
733
|
params: { period: "monthly" }
|
|
736
734
|
})
|
|
737
735
|
|
|
@@ -753,8 +751,7 @@ export default function AnalyticsDashboard({ taruviClient }) {
|
|
|
753
751
|
const fetchMetrics = async () => {
|
|
754
752
|
try {
|
|
755
753
|
const analytics = new Analytics(taruviClient)
|
|
756
|
-
const result = await analytics.execute({
|
|
757
|
-
name: "dashboard_metrics",
|
|
754
|
+
const result = await analytics.execute("dashboard-metrics", {
|
|
758
755
|
params: {
|
|
759
756
|
date_range: "last_30_days"
|
|
760
757
|
}
|
package/package.json
CHANGED
|
@@ -12,11 +12,10 @@ export class Analytics {
|
|
|
12
12
|
this.config = this.client.getConfig()
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
async execute<T = unknown>(options: AnalyticsRequest): Promise<AnalyticsResponse<T>> {
|
|
16
|
-
const url =
|
|
15
|
+
async execute<T = unknown>(querySlug: string, options: AnalyticsRequest = {}): Promise<AnalyticsResponse<T>> {
|
|
16
|
+
const url = AnalyticsRoutes.baseUrl(this.config.appSlug, querySlug)
|
|
17
17
|
|
|
18
18
|
const body = {
|
|
19
|
-
name: options.name,
|
|
20
19
|
params: options.params || {}
|
|
21
20
|
}
|
|
22
21
|
|
|
@@ -12,15 +12,15 @@ export class Database {
|
|
|
12
12
|
private config: TaruviConfig
|
|
13
13
|
private operation: HttpMethod | undefined
|
|
14
14
|
private body: object | undefined
|
|
15
|
-
private
|
|
15
|
+
private queryParams: DatabaseFilters | undefined
|
|
16
16
|
|
|
17
|
-
constructor(client: Client, urlParams: UrlParams = {}, operation?: HttpMethod | undefined, body?: object | undefined,
|
|
17
|
+
constructor(client: Client, urlParams: UrlParams = {}, operation?: HttpMethod | undefined, body?: object | undefined, queryParams?: DatabaseFilters) {
|
|
18
18
|
this.client = client
|
|
19
19
|
this.urlParams = urlParams
|
|
20
20
|
this.operation = operation
|
|
21
21
|
this.body = body
|
|
22
22
|
this.config = this.client.getConfig()
|
|
23
|
-
this.
|
|
23
|
+
this.queryParams = queryParams
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
from(dataTables: string): Database {
|
|
@@ -28,7 +28,11 @@ export class Database {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
filter(filters: DatabaseFilters): Database {
|
|
31
|
-
return new Database(this.client, { ...this.urlParams }, undefined, undefined, filters)
|
|
31
|
+
return new Database(this.client, { ...this.urlParams }, undefined, undefined, {...this.queryParams, ...filters})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
populate(populate: string[]): Database {
|
|
35
|
+
return new Database(this.client, { ...this.urlParams, }, undefined, undefined, {...this.queryParams, populate: populate.join(',')})
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
get(recordId: string): Database {
|
|
@@ -60,7 +64,7 @@ export class Database {
|
|
|
60
64
|
return acc
|
|
61
65
|
}, "") +
|
|
62
66
|
"/" +
|
|
63
|
-
buildQueryString(this.
|
|
67
|
+
buildQueryString(this.queryParams)
|
|
64
68
|
)
|
|
65
69
|
}
|
|
66
70
|
|
package/src/utils/utils.ts
CHANGED
|
@@ -21,12 +21,12 @@ export const getRuntimeEnvironment = (): string => {
|
|
|
21
21
|
return 'Server'
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function buildQueryString(
|
|
25
|
-
if (!
|
|
24
|
+
export function buildQueryString(queryParams: Record<string, unknown> | undefined): string {
|
|
25
|
+
if (!queryParams || Object.keys(queryParams).length === 0) {
|
|
26
26
|
return ''
|
|
27
27
|
}
|
|
28
28
|
const params = new URLSearchParams()
|
|
29
|
-
Object.entries(
|
|
29
|
+
Object.entries(queryParams).forEach(([key, value]) => {
|
|
30
30
|
if (value !== undefined && value !== null) {
|
|
31
31
|
params.append(key, String(value))
|
|
32
32
|
}
|