Scope - globules-io/OGX.JS GitHub Wiki

Scope

Scope is designed to test and verify a scope against an entity

Eval

 OGX.Scope.eval(_SCOPE_EXPRESSION_, _SCOPE_);

Scope Expression

A Scope Expression is a string that contains the testing part. For instance, if you wish to test an entity scope and check if it has the required scope:

  OGX.Scope.eval('manager', entity.scope);

Consider the entity

  let entity = {scope:'admin'};

You can test if the scope matches admin

  const has_required_scope = OGX.Scope.eval('admin', entity.scope);
  //true

Test if at least one scope matches, admin or manager

  const has_required_scope = OGX.Scope.eval('admin|manager', entity.scope);
  //true

Test if at least the scope matches, support and csuite

  const has_required_scope = OGX.Scope.eval('support+csuite', entity.scope);
  //false

You can also use regular expressions, such as

  const has_required_scope = OGX.Scope.eval('/(cluster|company)_(admin|manager|support)/', entity.scope);
  //false