Company-scoped query state
Toolora’s query state is scoped to the verified active company. Reusable hooks use tenantQueryKey, and AppQueryProvider creates a new QueryClient when activeTenantId changes. This separates client caches across company contexts. Database filters, RLS and API resource policy independently establish which data can be returned.
A cache key describes a read and its ownership in the browser. It does not authenticate a user, grant resource access or guarantee that an external projection is fresh.
Query identity and lifetime
Section titled “Query identity and lifetime”| Mechanism | Inspected behaviour | Limit |
|---|---|---|
tenantQueryKey(tenantId, ...parts) |
Builds ["tenant", tenantId, ...parts] |
Callers must include resource, filter, pagination and actor dimensions relevant to the result |
| Query provider | Recreates the client on active-company change | It does not cancel a business transaction already accepted by the server |
| Verified AuthProvider context | Exposes no prior-token authority while verification is pending | A displayed account or stored preference is not a verified selected company |
| Default query policy | 30-second stale time, no focus refetch, one retry unless a read timeout | Individual queries can define different polling/refetch behaviour |
| Default mutation policy | No automatic mutation retry | Domain-specific replay and recovery still apply |
| Signed-URL helper | Separate bounded cache, cleared on sign-out/company switch | QueryClient replacement is not a universal browser-storage purge |
Hooks enable tenant-bound reads only when the needed context is present. They also constrain the actual query: project/quote lists include company filters and their keys include list options. Customer access-grant keys additionally include the account and customer. A generic entity ID must not erase a result’s company or audience dimension.
Switching and late responses
Section titled “Switching and late responses”An explicit company switch updates the server preference, refreshes the token and waits for verified identity for the new token. An existing token retains its accepted tenant semantics. During verification, the prior token’s membership snapshot is withheld and tenant-bound children are gated.
The AuthProvider distinguishes an operation continuing for the same account from publishing permissions for the exact current token. A refresh can survive ordinary token rotation; an old /me result cannot replace the current token’s authority. QueryClient replacement then separates the new company’s cache.
This does not establish a universal cancellation guarantee for every custom fetch, local state, draft store or signed URL. A mutation accepted under the previous context may finish there. Its completion must not be interpreted as a write to the newly selected company. Mutation boundaries and editor generation/scope checks handle their own lifecycle.
Invalidation, polling and request pacing
Section titled “Invalidation, polling and request pacing”A successful mutation invalidates the owning query families. Cost allocation invalidates queue, context and financial follow-up keys; quote edits invalidate the appropriate quote/list context. Invalidation requests fresh data rather than rewriting the database or declaring a provider synchronized.
Selected worker/review queries poll only while their returned state is pending. readFetch bounds GET/HEAD reads, including body retrieval, to 15 seconds. The installed request governor shares overlapping identical backend GETs and spaces repeated starts by a default second. It keys credentials and excludes writes, other hosts and requests carrying an abort signal. It is request pacing, not a persistent response cache.
Example and evidence scope
Section titled “Example and evidence scope”A synthetic user views Company A’s project list with a search filter, then switches to B. B must receive a different query context and company-filtered read. An A response that finishes later must not be presented as B’s permission snapshot. A portal request for an independently admitted Company C resource still follows its resource-specific identity contract.
The inspected sources establish reset triggers, key construction and representative invalidation. AuthProvider tests specify token/account races. They do not prove that every hook has all required key dimensions or that every provider feed is current. The source review is deliberately narrower than that claim.