Agent clients, estimates & messages
How /api/agent decides which client or estimate an agent may touch, what each route sends to
Repliers, and what a PATCH does with omitted, empty and null values. Terms are in the
Glossary.
Agent & Admin · Authentication, agents and roles · Data ownership · Events & messaging
The param guards
| Guard | Runs on | Passes when | Effect on ctx.state.user.sub | Source |
|---|---|---|---|---|
router.use(jwt, role([Agent, Admin])) | every route, first | valid token with role Agent or Admin | none | src/routes/agent.ts (router.use) |
clientId | GET and PATCH /client/{clientId}, POST and GET /estimate/{clientId}, POST and GET /messages/{clientId} | no s and the first client returned for { clientId, agentId: sub } has agentId = sub; or s equals the signature | with a valid s, replaced by the client’s own agentId (a number) for the rest of the request | src/routes/agent.ts (router.param("clientId")), src/services/agent.ts (checkSignature, checkClient) |
estimateId | POST /estimate/{estimateId}/send, PATCH and DELETE /estimate/{estimateId} | the estimate exists (404 otherwise), has a clientId (403 otherwise), and s matches the signature of that clientId or the client’s agentId equals sub | as above | src/routes/agent.ts (router.param("estimateId")), src/services/estimate.ts (get, checkOwnership) |
| none | POST and GET /client, GET and POST /boss/people | n/a | none | src/routes/agent.ts |
Everything a handler sends upstream as agentId is sub after the guard, so a signed request
acts as the client’s assigned agent: messages go out under that agent and estimates are read
and written for that agent. The signature is calcSignature(clientId, AUTH_AGENTS_SIGNATURE_SALT)
(signed client links); it is also the ?s= appended to the client links written
into FUB (secureFubAvmLink).
Clients
POST /api/agent/client:agentsCreateClientSchemarequiresemail,agentId(=sub) andstatus(forced totrueafter the body is spread, so a bodystatusis ignored). Optional:fname,lname,phone(any string),tags(array of strings),preferences. When apreferencesobject is sent, omitted members are filled:emailtrue,smstrue,unsubscribefalse. Unknown keys, includingexternalId, are a 400. A detached client-registration event follows (SelectAgentClientRegistrationParams).GET /api/agent/client: filter keysclientId,condition,email,fname,lname,keywords,operator,pageNum(default 1),resultsPerPage(default 100),tags,phone(a number),status,showSavedSearches(default false),showEstimates(default true), forwarded to RepliersGET /clientswithagentId=sub.conditionandoperatoraccept any string. The body is Repliers’ paged list.GET /api/agent/client/{clientId}: the same filter with onlyclientId, the twoshow…flags andagentId; the answer is the list shape with one entry inclients, not a bare client.
PATCH /api/agent/client/{clientId}
The schema is the create schema with every key optional plus a required clientId (path), and
agentId is always set from sub. The service sends PATCH /clients/{id} with every validated
key except clientId, so agentId is always in the forwarded body.
| Body | Result |
|---|---|
| key omitted | not forwarded (no default injected) |
{} | valid; forwarded as { agentId } |
null on any key | 400 |
| empty string | 400 |
tags: [] | valid; forwarded as [] |
preferences: { sms: false } | forwarded as { sms: false, email: true, unsubscribe: false } (defaults fill the omitted members) |
preferences: {} | forwarded as { email: true, sms: true, unsubscribe: false } |
email, status | accepted and forwarded |
| any other key | 400 |
What Repliers does with these values is not established by this checkout.
Estimates
-
POST /api/agent/estimate/{clientId}:estimateAddSchemaplusagentId;boardIdis required,clientIdcomes from the path (it overwrites a body value), andsendEmailNow/sendEmailMonthlyare accepted.AgentService.createEstimatecallsRepliersEstimate.adddirectly, notEstimateService.add. A detached estimate event and note follow. -
GET /api/agent/estimate/{clientId}:RepliersEstimate.get({ clientId, agentId }), returned as is (EstimateService.getByClientId, which adjusts values, is not used). -
POST /api/agent/estimate/{estimateId}/send:PATCH /estimates/{id}with{ sendEmailNow: true }and the response body from Repliers. A second handler then runs without being awaited: it reads the estimate and the client, finds the FUB person byexternalId(else by email), and writes a noteEstimate sent to the client via email. It skips when the estimate has noclientIdor the client has neitherexternalIdnor email; its errors are written withconsole.error. -
PATCH /api/agent/estimate/{estimateId}:estimateBaseSchemakeys plusagentIdandestimateId, withagentIdremoved before the call.boardIdis not accepted;clientIdis, and is forwarded. A nested object that is sent must carry its required members (address: city, street fields,zip;details: bedrooms, bathrooms,propertyType,sqft,style;taxes:annualAmount).Body Result top-level key omitted not forwarded {}valid; forwarded as {}nullon any key400 empty string 400, except details.yearBuilt, which allows""empty array ( condominium.amenities: [])valid; forwarded as [] -
DELETE /api/agent/estimate/{estimateId}:EstimateService.delete, status 200, no body.
Messages
POST /api/agent/messages/{clientId}:contentis an object with at least one key and a requiredmessage; optionallinks,pictures,listings(strings) andsearches(numbers);subjectis not accepted. It sendsPOST /messageswithsender: "agent",agentIdandclientId, awaits it and returns Repliers’ body. Delivery is Repliers’.GET /api/agent/messages/{clientId}: the handler validates onlyclientId,agentIdandestimateId(from the query). Other query keys, including those the schema lists (startTime,endTime,pageNum,resultsPerPage,sender,status), are not read, and no error is raised for them.
Boss people
GET and POST /api/agent/boss/people validate the query (tags optional) plus agentId
and assignedUserId from the token claim external.fub_id; without the claim the error is
You need an account in FollowUpBoss, contact administroator to create one (400). GET returns
FUB’s people response ({} when BOSS_ENABLED=false).
POST (AgentService.syncBossPeople) reads one FUB page. With no people it answers
{ "synced": 0 }. Otherwise it opens a transaction, inserts a sync row and one people_sync
row per person with status PENDING, commits, then publishes each row to
<NATS_WORKER_CONSUMER_STREAM>.people.upsert and answers { "synced": n }. The client writes
happen in the worker (Events & messaging). The rows are
committed before the first publish.
Gotchas
- The guard replaces
subwith a number. Handlers that compare or printsubafter a signed request see the client’sagentId, not the token’s. Source:src/routes/agent.ts(router.param("clientId")). GET /client/{clientId}returns a list. The single-client route callsgetClients. Source:src/routes/agent.ts,src/services/agent.ts(getClients).- A partial
preferencesobject is completed with defaults on client create and PATCH. Source:src/validate/agent.ts(agentsCreateClientSchemaKeys,agentUpdateClientSchema). - The schema lists message filters the route never passes. Source:
src/routes/agent.ts(router.get("/messages/:clientId")),src/validate/agent.ts(agentsGetMessagesSchema). - The estimate note is written after the response. Source:
src/routes/agent.ts(router.post("/estimate/:estimateId/send")). condition,operatorandsenderare declared with.allow(...), which keeps any string valid. Source:src/validate/agent.ts.- The estimate PATCH forwards a body
clientId. Source:src/validate/estimate.ts(estimateBaseSchema),src/routes/agent.ts(router.patch("/estimate/:estimateId")).
Evidence
- The validators were run in isolation with the project’s joi on 2026-10-20 for the
preferencesdefault fill,nulland empty-string cases. test/services/eventsCollection/selectors/selectAgentClientRegistrationParams.test.ts,selectAgentEstimateParams.test.ts.- No route test exists for
/api/agent. - Not established by this checkout: Repliers’ semantics for
GET /clientswith bothclientIdandagentId, and for the PATCH bodies above.
Verified against portal-backend 997ae3e, 2026-10-20.