Scoring Config API
The scoringConfig router manages per-tenant scoring configuration for fit scores, engagement scores, and combined weight distribution. Configurations are versioned -- every update creates a new version and deactivates the previous one.
Router namespace: scoringConfig
Source: src/server/trpc/routers/scoring-config.ts
Procedures
| Procedure | Type | Access | Description |
|---|---|---|---|
getConfig | query | tenant | Get a specific config type |
getAllConfigs | query | tenant | Get all config types merged with defaults |
updateConfig | mutation | admin | Update a config (creates new version) |
resetConfig | mutation | admin | Reset a config type to defaults |
Config Types
There are three config types, each controlling a different scoring dimension:
| Type | Purpose | Default Source |
|---|---|---|
fit | ICP match scoring -- dimension weights, field thresholds | DEFAULT_FIT_CONFIG |
engagement | Behavioral signals -- decay rates, channel weights | DEFAULT_ENGAGEMENT_CONFIG |
combined | Weight distribution between fit and engagement scores | DEFAULT_COMBINED_WEIGHTS |
Every updateConfig call creates a new version. Previous versions are deactivated but retained in the database. This provides a full audit trail of configuration changes.
getConfig
Retrieves the active configuration for a specific scoring type. Returns the default config if no custom configuration has been saved.
scoringConfig.getConfig.queryOptions(input)
Input
| Field | Type | Required | Description |
|---|---|---|---|
type | "fit" | "engagement" | "combined" | Yes | Configuration type to retrieve |
Response
Returns a JSON object whose shape depends on the config type. Example for combined:
{
"fitWeight": 0.5,
"engagementWeight": 0.5,
"tierThresholds": {
"hot": 80,
"warm": 60,
"cool": 40
}
}
Example
const trpc = useTRPC();
const { data: fitConfig } = useQuery(
trpc.scoringConfig.getConfig.queryOptions({ type: "fit" })
);
getAllConfigs
Retrieves all three config types in a single request, merged with defaults. Custom configs override defaults where they exist.
scoringConfig.getAllConfigs.queryOptions()
Input
None.
Response
{
"fit": {
"dimensions": { "industry": { "weight": 20 }, "employeeCount": { "weight": 15 } }
},
"engagement": {
"decayHalfLifeDays": 30,
"signals": { "emailOpen": { "weight": 5 }, "pageView": { "weight": 3 } }
},
"combined": {
"fitWeight": 0.5,
"engagementWeight": 0.5,
"tierThresholds": { "hot": 80, "warm": 60, "cool": 40 }
}
}
Example
const trpc = useTRPC();
const { data: configs } = useQuery(
trpc.scoringConfig.getAllConfigs.queryOptions()
);
// Access individual configs
const fitConfig = configs?.fit;
const tierThresholds = configs?.combined?.tierThresholds;
updateConfig
Updates a scoring configuration. Creates a new version, deactivates the previous version, and logs the change to the audit trail.
scoringConfig.updateConfig.mutationOptions(options)
Access: Admin only
Input
| Field | Type | Required | Description |
|---|---|---|---|
type | "fit" | "engagement" | "combined" | Yes | Config type to update |
config | Record<string, unknown> | Yes | New configuration object |
Response
{
"success": true,
"version": 3
}
Example
const trpc = useTRPC();
const queryClient = useQueryClient();
const mutation = useMutation(
trpc.scoringConfig.updateConfig.mutationOptions({
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: trpc.scoringConfig.getAllConfigs.queryKey(),
});
},
})
);
mutation.mutate({
type: "combined",
config: {
fitWeight: 0.6,
engagementWeight: 0.4,
tierThresholds: { hot: 85, warm: 65, cool: 45 },
},
});
Every config update is recorded in the audit log with the config type and new version number. Use the Audit API to review the change history.
resetConfig
Resets a configuration type to its built-in defaults by deactivating all custom versions. The next getConfig call will return the default values.
scoringConfig.resetConfig.mutationOptions(options)
Access: Admin only
Input
| Field | Type | Required | Description |
|---|---|---|---|
type | "fit" | "engagement" | "combined" | Yes | Config type to reset |
Response
{
"success": true
}
Example
const trpc = useTRPC();
const queryClient = useQueryClient();
const mutation = useMutation(
trpc.scoringConfig.resetConfig.mutationOptions({
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: trpc.scoringConfig.getAllConfigs.queryKey(),
});
},
})
);
mutation.mutate({ type: "engagement" });
Resetting a configuration deactivates all custom versions permanently. The default values will be used until a new custom configuration is saved.
Related Pages
- Scoring API -- Execute scoring runs and query results
- Audit API -- Review config change history
- tRPC Overview -- Client setup and procedure types