Skip to main content

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

ProcedureTypeAccessDescription
getConfigquerytenantGet a specific config type
getAllConfigsquerytenantGet all config types merged with defaults
updateConfigmutationadminUpdate a config (creates new version)
resetConfigmutationadminReset a config type to defaults

Config Types

There are three config types, each controlling a different scoring dimension:

TypePurposeDefault Source
fitICP match scoring -- dimension weights, field thresholdsDEFAULT_FIT_CONFIG
engagementBehavioral signals -- decay rates, channel weightsDEFAULT_ENGAGEMENT_CONFIG
combinedWeight distribution between fit and engagement scoresDEFAULT_COMBINED_WEIGHTS
Versioned Configs

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

FieldTypeRequiredDescription
type"fit" | "engagement" | "combined"YesConfiguration 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

FieldTypeRequiredDescription
type"fit" | "engagement" | "combined"YesConfig type to update
configRecord<string, unknown>YesNew 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 },
},
});
Audit Trail

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

FieldTypeRequiredDescription
type"fit" | "engagement" | "combined"YesConfig 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" });
warning

Resetting a configuration deactivates all custom versions permanently. The default values will be used until a new custom configuration is saved.