@dench.com/cli 2.9.6 → 2.9.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.
- package/app-sdk.d.ts +10 -5
- package/crm.ts +9 -2
- package/lib/api-schemas.ts +67 -12
- package/package.json +1 -1
package/app-sdk.d.ts
CHANGED
|
@@ -684,6 +684,8 @@ export interface ApiRequests {
|
|
|
684
684
|
objectName: string;
|
|
685
685
|
/** Field to bucket by. */
|
|
686
686
|
fieldName: string;
|
|
687
|
+
/** Number field to total per bucket (e.g. Amount grouped by Stage). Exact at any table size. */
|
|
688
|
+
sumField?: string;
|
|
687
689
|
};
|
|
688
690
|
/** Search CRM entries. — `dench crm search` — GET /api/v1/crm/search */
|
|
689
691
|
"crm.search": {
|
|
@@ -879,6 +881,7 @@ export interface ApiRequests {
|
|
|
879
881
|
groupByField: string;
|
|
880
882
|
/** Aggregation metric. Defaults to `count`. */
|
|
881
883
|
metric?: "count" | "sum" | "avg" | "min" | "max";
|
|
884
|
+
/** Number field to sum/avg per bucket (e.g. Amount grouped by Stage). Defaults to the group field itself. */
|
|
882
885
|
metricField?: string;
|
|
883
886
|
};
|
|
884
887
|
/** Read an object's analytics dashboard: panels, field roles, the strip's collapsed flag, the named view's own dashboard (if any), and the fields panels may bucket on (synthetic $createdAt / $location last). — `dench crm analytics get` — GET /api/v1/crm/objects/{objectName}/analytics */
|
|
@@ -894,13 +897,13 @@ export interface ApiRequests {
|
|
|
894
897
|
viewName?: string;
|
|
895
898
|
/** Only these stored panels. */
|
|
896
899
|
panelIds?: string[];
|
|
897
|
-
/** Ad-hoc panel definitions to compute instead of the stored dashboard (nothing is persisted). */
|
|
900
|
+
/** Ad-hoc panel definitions to compute instead of the stored dashboard (nothing is persisted). id/title/metric/sortOrder are filled in when omitted. */
|
|
898
901
|
panels?: Array<{
|
|
899
902
|
/** Stable id (template panels use `tpl:<template>:<slug>`). */
|
|
900
|
-
id
|
|
901
|
-
title
|
|
903
|
+
id?: string;
|
|
904
|
+
title?: string;
|
|
902
905
|
type: "stat" | "bar" | "line" | "area" | "donut" | "funnel" | "leaderboard" | "forecast" | "map";
|
|
903
|
-
metric
|
|
906
|
+
metric?: "count" | "sum" | "avg" | "min" | "max";
|
|
904
907
|
/** Numeric field for sum/avg/min/max. Ignored for count. */
|
|
905
908
|
metricField?: string;
|
|
906
909
|
/** Bucketing field (enum/user/relation/boolean/text, or $location). On a time-series panel it splits the series into one line per value. */
|
|
@@ -916,7 +919,7 @@ export interface ApiRequests {
|
|
|
916
919
|
span?: 2 | 3 | 4 | 6;
|
|
917
920
|
/** Hide from the strip above the table; still shown in the full analytics view. */
|
|
918
921
|
hidden?: boolean;
|
|
919
|
-
sortOrder
|
|
922
|
+
sortOrder?: number;
|
|
920
923
|
/** Role-driven derived metric; when set the panel computes from fieldRoles instead of metric/groupBy. */
|
|
921
924
|
derived?: "conversion_rate" | "win_rate" | "won_amount" | "lost_amount" | "open_pipeline" | "pipeline_forecast" | "mrr" | "arr";
|
|
922
925
|
}>;
|
|
@@ -3535,6 +3538,8 @@ export interface ApiResponses {
|
|
|
3535
3538
|
avg?: number;
|
|
3536
3539
|
}[];
|
|
3537
3540
|
totalCount: number;
|
|
3541
|
+
/** True when a bounded row scan (not the exact pre-aggregates) produced the sums. */
|
|
3542
|
+
truncated?: boolean;
|
|
3538
3543
|
};
|
|
3539
3544
|
"crm.analytics.get": {
|
|
3540
3545
|
objectName: string;
|
package/crm.ts
CHANGED
|
@@ -2787,10 +2787,17 @@ async function runAggregateCommand(ctx: CrmCliContext): Promise<void> {
|
|
|
2787
2787
|
const objectName = shift(ctx.args, "object name");
|
|
2788
2788
|
const fieldName = getFlag(ctx.args, "--field");
|
|
2789
2789
|
if (!fieldName) throw new CrmCliError("--field is required");
|
|
2790
|
+
// `--sum Amount` totals that number field per bucket (exact from the
|
|
2791
|
+
// pre-aggregates: "Amount by Stage" at any table size).
|
|
2792
|
+
const sumField = getFlag(ctx.args, "--sum");
|
|
2790
2793
|
assertNoUnknownFlags(ctx.args, "crm aggregate");
|
|
2791
2794
|
out(
|
|
2792
2795
|
ctx,
|
|
2793
|
-
await callQuery(ctx, api.query.aggregate, {
|
|
2796
|
+
await callQuery(ctx, api.query.aggregate, {
|
|
2797
|
+
objectName,
|
|
2798
|
+
fieldName,
|
|
2799
|
+
...(sumField ? { sumField } : {}),
|
|
2800
|
+
}),
|
|
2794
2801
|
);
|
|
2795
2802
|
}
|
|
2796
2803
|
|
|
@@ -4486,7 +4493,7 @@ Query DSL:
|
|
|
4486
4493
|
dench crm query deal --where '{"Close Date":{"$inNext":{"amount":1,"unit":"quarters"}}}'
|
|
4487
4494
|
|
|
4488
4495
|
Aggregates:
|
|
4489
|
-
dench crm aggregate <object> --field Status
|
|
4496
|
+
dench crm aggregate <object> --field Status [--sum Amount]
|
|
4490
4497
|
|
|
4491
4498
|
Full-text search:
|
|
4492
4499
|
dench crm search [--object <name>] [--limit N] <text>
|
package/lib/api-schemas.ts
CHANGED
|
@@ -2020,6 +2020,43 @@ const analyticsPanel = z
|
|
|
2020
2020
|
})
|
|
2021
2021
|
.describe("One analytics panel definition.");
|
|
2022
2022
|
|
|
2023
|
+
/**
|
|
2024
|
+
* An ad-hoc panel as callers actually write it: `id`, `title`, `metric`
|
|
2025
|
+
* and `sortOrder` may be omitted (the CLI's `--panel '{"type":"donut",
|
|
2026
|
+
* "groupBy":"Source"}'` already did this; the App SDK and REST path must
|
|
2027
|
+
* accept the same). `normalizeAdHocPanels` fills the defaults before the
|
|
2028
|
+
* Convex validator sees them — see `convexExtras["crm.analytics.compute"]`.
|
|
2029
|
+
*/
|
|
2030
|
+
const adHocAnalyticsPanel = analyticsPanel
|
|
2031
|
+
.partial({ id: true, title: true, metric: true, sortOrder: true })
|
|
2032
|
+
.describe(
|
|
2033
|
+
"One ad-hoc panel. `id`, `title`, `metric` (default count) and `sortOrder` (default: position) are optional.",
|
|
2034
|
+
);
|
|
2035
|
+
|
|
2036
|
+
/** Fill `id` / `title` / `metric` / `sortOrder` on ad-hoc compute panels. */
|
|
2037
|
+
export function normalizeAdHocPanels(panels: unknown): unknown {
|
|
2038
|
+
if (!Array.isArray(panels)) return panels;
|
|
2039
|
+
return panels.map((raw, index) => {
|
|
2040
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return raw;
|
|
2041
|
+
const panel = raw as Record<string, unknown>;
|
|
2042
|
+
const slug = String(panel.title ?? panel.type ?? "panel")
|
|
2043
|
+
.toLowerCase()
|
|
2044
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
2045
|
+
.replace(/(^-|-$)/g, "");
|
|
2046
|
+
const id =
|
|
2047
|
+
typeof panel.id === "string" && panel.id.trim()
|
|
2048
|
+
? panel.id.trim()
|
|
2049
|
+
: `adhoc:${slug}-${index}`;
|
|
2050
|
+
return {
|
|
2051
|
+
...panel,
|
|
2052
|
+
id,
|
|
2053
|
+
title: typeof panel.title === "string" ? panel.title : id,
|
|
2054
|
+
metric: typeof panel.metric === "string" ? panel.metric : "count",
|
|
2055
|
+
sortOrder: typeof panel.sortOrder === "number" ? panel.sortOrder : index,
|
|
2056
|
+
};
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2023
2060
|
const analyticsPanelPatch = analyticsPanel
|
|
2024
2061
|
.omit({ id: true, size: true })
|
|
2025
2062
|
.partial()
|
|
@@ -2106,12 +2143,10 @@ const analyticsPanelResult = z.object({
|
|
|
2106
2143
|
error: z.string().optional(),
|
|
2107
2144
|
});
|
|
2108
2145
|
|
|
2109
|
-
|
|
2110
2146
|
// ---------------------------------------------------------------------------
|
|
2111
2147
|
// Request schemas keyed by operation id
|
|
2112
2148
|
// ---------------------------------------------------------------------------
|
|
2113
2149
|
|
|
2114
|
-
|
|
2115
2150
|
export const requestSchemas: Record<string, ZodTypeAny> = {
|
|
2116
2151
|
// Meta
|
|
2117
2152
|
"commands.list": noInput,
|
|
@@ -2912,6 +2947,12 @@ export const requestSchemas: Record<string, ZodTypeAny> = {
|
|
|
2912
2947
|
"crm.aggregate": z.object({
|
|
2913
2948
|
objectName: z.string(),
|
|
2914
2949
|
fieldName: z.string().describe("Field to bucket by."),
|
|
2950
|
+
sumField: z
|
|
2951
|
+
.string()
|
|
2952
|
+
.optional()
|
|
2953
|
+
.describe(
|
|
2954
|
+
"Number field to total per bucket (e.g. Amount grouped by Stage). Exact at any table size.",
|
|
2955
|
+
),
|
|
2915
2956
|
}),
|
|
2916
2957
|
"crm.search": z.object({
|
|
2917
2958
|
text: z.string().describe("Full-text query."),
|
|
@@ -3011,7 +3052,12 @@ export const requestSchemas: Record<string, ZodTypeAny> = {
|
|
|
3011
3052
|
type: reportType,
|
|
3012
3053
|
groupByField: z.string(),
|
|
3013
3054
|
metric: reportMetric.optional(),
|
|
3014
|
-
metricField: z
|
|
3055
|
+
metricField: z
|
|
3056
|
+
.string()
|
|
3057
|
+
.optional()
|
|
3058
|
+
.describe(
|
|
3059
|
+
"Number field to sum/avg per bucket (e.g. Amount grouped by Stage). Defaults to the group field itself.",
|
|
3060
|
+
),
|
|
3015
3061
|
}),
|
|
3016
3062
|
"crm.enrich.cell": z.object({
|
|
3017
3063
|
objectName: z.string(),
|
|
@@ -3413,10 +3459,10 @@ export const requestSchemas: Record<string, ZodTypeAny> = {
|
|
|
3413
3459
|
.optional()
|
|
3414
3460
|
.describe("Only these stored panels."),
|
|
3415
3461
|
panels: z
|
|
3416
|
-
.array(
|
|
3462
|
+
.array(adHocAnalyticsPanel)
|
|
3417
3463
|
.optional()
|
|
3418
3464
|
.describe(
|
|
3419
|
-
"Ad-hoc panel definitions to compute instead of the stored dashboard (nothing is persisted).",
|
|
3465
|
+
"Ad-hoc panel definitions to compute instead of the stored dashboard (nothing is persisted). id/title/metric/sortOrder are filled in when omitted.",
|
|
3420
3466
|
),
|
|
3421
3467
|
period: analyticsPeriod.optional(),
|
|
3422
3468
|
extraFilters: z
|
|
@@ -3531,7 +3577,6 @@ export const requestSchemas: Record<string, ZodTypeAny> = {
|
|
|
3531
3577
|
'"own": the view gets its own dashboard (a copy of the object\'s panels); "shared": it shows the object\'s again.',
|
|
3532
3578
|
),
|
|
3533
3579
|
}),
|
|
3534
|
-
|
|
3535
3580
|
};
|
|
3536
3581
|
|
|
3537
3582
|
// ---------------------------------------------------------------------------
|
|
@@ -4136,6 +4181,12 @@ export const responseSchemas: Record<string, ZodTypeAny> = {
|
|
|
4136
4181
|
}),
|
|
4137
4182
|
),
|
|
4138
4183
|
totalCount: z.number(),
|
|
4184
|
+
truncated: z
|
|
4185
|
+
.boolean()
|
|
4186
|
+
.optional()
|
|
4187
|
+
.describe(
|
|
4188
|
+
"True when a bounded row scan (not the exact pre-aggregates) produced the sums.",
|
|
4189
|
+
),
|
|
4139
4190
|
}),
|
|
4140
4191
|
"crm.enrich.cell": z.object({
|
|
4141
4192
|
enqueued: z.boolean(),
|
|
@@ -4488,7 +4539,6 @@ export const responseSchemas: Record<string, ZodTypeAny> = {
|
|
|
4488
4539
|
"crm.analytics.collapse": okResponse,
|
|
4489
4540
|
"crm.analytics.expand": okResponse,
|
|
4490
4541
|
"crm.analytics.scope": z.object({ ok: z.boolean(), changed: z.boolean() }),
|
|
4491
|
-
|
|
4492
4542
|
};
|
|
4493
4543
|
|
|
4494
4544
|
// ---------------------------------------------------------------------------
|
|
@@ -4512,6 +4562,14 @@ export const convexExtras: Record<string, ConvexExtras> = {
|
|
|
4512
4562
|
},
|
|
4513
4563
|
}),
|
|
4514
4564
|
},
|
|
4565
|
+
// Ad-hoc panels arrive without id/title/metric/sortOrder from apps and
|
|
4566
|
+
// curl; the Convex validator requires all four.
|
|
4567
|
+
"crm.analytics.compute": {
|
|
4568
|
+
transformArgs: (input) =>
|
|
4569
|
+
input.panels === undefined
|
|
4570
|
+
? { ...input }
|
|
4571
|
+
: { ...input, panels: normalizeAdHocPanels(input.panels) },
|
|
4572
|
+
},
|
|
4515
4573
|
"cron.enable": { fixedArgs: { enabled: true } },
|
|
4516
4574
|
"cron.disable": { fixedArgs: { enabled: false } },
|
|
4517
4575
|
// Archive/unarchive are one mutation behind two paths, so the flag comes
|
|
@@ -4607,7 +4665,6 @@ export const convexExtras: Record<string, ConvexExtras> = {
|
|
|
4607
4665
|
};
|
|
4608
4666
|
},
|
|
4609
4667
|
},
|
|
4610
|
-
|
|
4611
4668
|
};
|
|
4612
4669
|
|
|
4613
4670
|
// ---------------------------------------------------------------------------
|
|
@@ -4927,7 +4984,6 @@ export const requestExamples: Record<string, unknown> = {
|
|
|
4927
4984
|
},
|
|
4928
4985
|
},
|
|
4929
4986
|
"crm.analytics.scope": { mode: "own" },
|
|
4930
|
-
|
|
4931
4987
|
};
|
|
4932
4988
|
|
|
4933
4989
|
// ---------------------------------------------------------------------------
|
|
@@ -5468,8 +5524,8 @@ export const responseExamples: Record<string, unknown> = {
|
|
|
5468
5524
|
},
|
|
5469
5525
|
],
|
|
5470
5526
|
"crm.aggregate": [
|
|
5471
|
-
{ key: "New", count: 12 },
|
|
5472
|
-
{ key: "Qualified", count: 8,
|
|
5527
|
+
{ key: "Stage:New", count: 12, sum: 48000 },
|
|
5528
|
+
{ key: "Stage:Qualified", count: 8, sum: 64000 },
|
|
5473
5529
|
],
|
|
5474
5530
|
"crm.search": [
|
|
5475
5531
|
{
|
|
@@ -6491,5 +6547,4 @@ export const responseExamples: Record<string, unknown> = {
|
|
|
6491
6547
|
"crm.analytics.collapse": { ok: true },
|
|
6492
6548
|
"crm.analytics.expand": { ok: true },
|
|
6493
6549
|
"crm.analytics.scope": { ok: true, changed: true },
|
|
6494
|
-
|
|
6495
6550
|
};
|