@nzelajs/adapter-expr-cel
v0.1.0
Published
Nzela GuardRunner adapter evaluating inline cel: transition guards with CEL (@marcbachmann/cel-js), fail-closed, plus a named predicate registry.
Maintainers
Readme
@nzelajs/adapter-expr-cel
English below - Version francaise plus bas.
The CEL GuardRunner for the Nzela engine. It makes inline cel: transition guards REAL: an
expression is evaluated against the instance's data with @marcbachmann/cel-js, sandboxed and
fail-closed. It also carries a named predicate registry for guards referenced by name.
English
Install
npm add @nzelajs/adapter-expr-celWhat it provides
CelGuardRunner(implementsGuardRunner): for each guard ref of a transition,cel:EXPRevaluates EXPR against theExpressionContext(form,case,beneficiary,requester,policy,tenant) using CEL. The result MUST be a strict boolean. Any parse or evaluation error (unknown variable, missing field, type mismatch) and any non-boolean result FAIL CLOSED (the guard fails, never a silent pass). Compiled expressions are cached.ref:nameor a barenamedelegates to an injected predicate registry; an unknown name FAILS CLOSED, and a predicate that throws FAILS CLOSED.checkreturns the firstGuardFailure(or null);assertthrowsGuardFailedErroron the first. Empty or undefined guard list passes.
- The CEL
matchesfunction (unbounded regex) is FORBIDDEN, fail-closed: it compiles to an unboundedRegExpand is a ReDoS vector. Express conditions with==,in,startsWith,contains. validateCelExpression(expr): a pure publish-time compile check (no evaluation). It throws on invalid CEL syntax and on the forbiddenmatches(. Wire it asparseBlueprint'svalidateExpression(directly, or through the studio'svalidateGraph/publishGraph) so a brokencel:guard is rejected when the client publishes instead of failing closed later at runtime - keeping@nzelajs/blueprintvendor-free (it never imports CEL; the app injects this callback).
Inject named predicates via the constructor ({ predicates }) or register(name, predicate). A
predicate reads the same GuardContext and ExpressionContext as the CEL path, so app-specific
logic (a database check) and declarative CEL guards live behind one runner.
Francais
Installation
npm add @nzelajs/adapter-expr-celCe que ca fournit
CelGuardRunner(implementeGuardRunner) : pour chaque ref de garde d'une transition,cel:EXPRevalue EXPR contre l'ExpressionContext(form,case,beneficiary,requester,policy,tenant) avec CEL. Le resultat DOIT etre un booleen strict. Toute erreur de compilation ou d'evaluation (variable inconnue, champ absent, type incompatible) et tout resultat non booleen ECHOUENT FERMES (la garde echoue, jamais de pass silencieux). Les expressions compilees sont mises en cache.ref:nameou un simplenamedelegue a un registre de predicats injecte ; un nom inconnu ECHOUE FERME, et un predicat qui leve une erreur ECHOUE FERME.checkrenvoie la premiereGuardFailure(ou null) ;assertleveGuardFailedErrora la premiere. Liste vide ou absente : pass.
- La fonction CEL
matches(regex non bornee) est INTERDITE, fail-closed : elle compile vers uneRegExpnon bornee, vecteur de ReDoS. Exprimez les conditions avec==,in,startsWith,contains. validateCelExpression(expr): un controle pur a la publication (compilation sans evaluation). Il leve sur une syntaxe CEL invalide et sur lematches(interdit. Branchez-le commevalidateExpressiondeparseBlueprint(directement, ou viavalidateGraph/publishGraphdu studio) pour rejeter une gardecel:cassee des la publication au lieu d'un echec ferme plus tard au runtime - en gardant@nzelajs/blueprintsans vendor (il n'importe jamais CEL ; l'app injecte ce callback).
Injectez des predicats nommes via le constructeur ({ predicates }) ou register(name, predicate).
Un predicat lit le meme GuardContext et ExpressionContext que la voie CEL : la logique propre a
l'app (un controle en base) et les gardes CEL declaratives cohabitent derriere un seul runner.
License
Apache-2.0
