ekyc

Electronic KYC process with uploading ID document using OAuth 2.1 (experimental)
Log | Files | Refs | README | LICENSE

scope.ts (703B)


      1 export class Scope {
      2   static readonly ALL = ["email", "phone-number", "id-document"];
      3 
      4   static of(scope: string | null) {
      5     return new this(
      6       new Set(
      7         scope !== null
      8           ? scope.split(" ")
      9             .map((i) => i.trim())
     10             .filter((i) => Scope.ALL.includes(i))
     11           : Scope.ALL,
     12       ),
     13     );
     14   }
     15 
     16   private constructor(private _values: Set<string>) {
     17   }
     18 
     19   intersect(scopes: Scope) {
     20     return new Scope(new Set(this.values.filter((i) => scopes.contains(i))));
     21   }
     22 
     23   contains(scope: string) {
     24     return this._values.has(scope);
     25   }
     26 
     27   get values() {
     28     return Array.from(this._values.values());
     29   }
     30 
     31   toString() {
     32     return this.values.join(" ");
     33   }
     34 }