Skip to main content

@idpass/data-collect-core / validateEventScope

Function: validateEventScope()

validateEventScope(event, scope, lookup): ScopeValidationResult

Defined in: services/ScopeResolver.ts:166

Pure server-side validator for inbound /push events. The caller is responsible for resolving entity references through whatever store it owns (Postgres, IndexedDB, in-memory map). The validator only inspects the event payload and the EntityScopeRef returned by lookup.

Rules (see docs/superpowers/specs/2026-04-28-bounded-sync-scope-design.md §7 and Phase 3 plan):

  • Unbounded scope (areaIds === null && entityTypes === null) → always ok.
  • create-individual / create-group: derive type from event-name suffix, read data.area_id from the payload only.
  • All other event types: defer to lookup(entityGuid). If lookup returns undefined, return unknown_entity — we cannot prove scope membership. update-* events that carry a new data.area_id must check BOTH the stored area and the incoming area: a scoped client must not be able to move an entity in or out of its scope.
  • areaIds set + event resolves to no area_idout_of_scope.
  • entityTypes set + entity is "record" (or any non-listed type) → out_of_scope.

Parameters

event

type

string

entityGuid

string

data

Record<string, unknown>

scope

EffectiveScope

lookup

(guid) => EntityScopeRef | undefined

Returns

ScopeValidationResult